Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide intention to fill trait members #5944

Open
mkaput opened this issue Jul 2, 2024 · 3 comments · May be fixed by #6690
Open

Provide intention to fill trait members #5944

mkaput opened this issue Jul 2, 2024 · 3 comments · May be fixed by #6690
Assignees
Labels
help wanted Extra attention is needed ide This issue refers to CairoLS or editor extensions

Comments

@mkaput
Copy link
Member

mkaput commented Jul 2, 2024

Implement the following intention in CairoLS:

Image

@mkaput mkaput added this to CairoLS Jul 2, 2024
@mkaput mkaput converted this from a draft issue Jul 2, 2024
@mkaput mkaput added help wanted Extra attention is needed ide This issue refers to CairoLS or editor extensions labels Jul 2, 2024
@LamsyA
Copy link

LamsyA commented Jul 18, 2024

hello @mkaput Kindly provide the link to this in the codebase.

@mkaput
Copy link
Member Author

mkaput commented Jul 19, 2024

Hey! Same store as in #5945

Here's the starting point:

/// Generate code actions for a given diagnostic.
///
/// # Arguments
///
/// * `db` - A reference to the Salsa database.
/// * `node` - The syntax node where the diagnostic is located.
/// * `diagnostic` - The diagnostic for which to generate code actions.
/// * `params` - The parameters for the code action request.
///
/// # Returns
///
/// A vector of [`CodeAction`] objects that can be applied to resolve the diagnostic.
fn get_code_actions_for_diagnostic(
db: &AnalysisDatabase,
node: &SyntaxNode,
diagnostic: &Diagnostic,
params: &CodeActionParams,
) -> Vec<CodeAction> {
let code = match &diagnostic.code {
Some(NumberOrString::String(code)) => code,
Some(NumberOrString::Number(code)) => {
debug!("diagnostic code is not a string: `{code}`");
return vec![];
}
None => {
debug!("diagnostic code is missing");
return vec![];
}
};
match code.as_str() {
"E0001" => {
vec![rename_unused_variable::rename_unused_variable(
db,
node,
diagnostic.clone(),
params.text_document.uri.clone(),
)]
}
code => {
debug!("no code actions for diagnostic code: {code}");
vec![]
}
}
}

You can follow the implementation of unused variable intention as the hooking point. First, you need to assign an error code to this particular diagnostic; you can grep for it by error message.

You will need to get information about trait items. This is provided in the SemanticGroup (this trait-Salsa group is implemented by AnalysisDatabase) by these queries:

/// Returns the names of all the non default implemented items of a trait.
#[salsa::invoke(items::trt::trait_required_item_names)]
fn trait_required_item_names(&self, trait_id: TraitId) -> Maybe<OrderedHashSet<SmolStr>>;
/// Returns the item of the trait, by the given `name`, if exists.
#[salsa::invoke(items::trt::trait_item_by_name)]
fn trait_item_by_name(&self, trait_id: TraitId, name: SmolStr) -> Maybe<Option<TraitItemId>>;
/// Returns the functions of a trait.
#[salsa::invoke(items::trt::trait_functions)]
fn trait_functions(&self, trait_id: TraitId)
-> Maybe<OrderedHashMap<SmolStr, TraitFunctionId>>;
/// Returns the function with the given name of the given trait, if exists.
#[salsa::invoke(items::trt::trait_function_by_name)]
fn trait_function_by_name(
&self,
trait_id: TraitId,
name: SmolStr,
) -> Maybe<Option<TraitFunctionId>>;
/// Returns the types of a trait.
#[salsa::invoke(items::trt::trait_types)]
fn trait_types(&self, trait_id: TraitId) -> Maybe<OrderedHashMap<SmolStr, TraitTypeId>>;
/// Returns the item type with the given name of the given trait, if exists.
#[salsa::invoke(items::trt::trait_type_by_name)]
fn trait_type_by_name(&self, trait_id: TraitId, name: SmolStr) -> Maybe<Option<TraitTypeId>>;
/// Returns the constants of a trait.
#[salsa::invoke(items::trt::trait_constants)]
fn trait_constants(&self, trait_id: TraitId)
-> Maybe<OrderedHashMap<SmolStr, TraitConstantId>>;
/// Returns the item constants with the given name of the given trait, if exists.
#[salsa::invoke(items::trt::trait_constant_by_name)]
fn trait_constant_by_name(
&self,
trait_id: TraitId,
name: SmolStr,
) -> Maybe<Option<TraitConstantId>>;

@mkaput mkaput moved this from Backlog to In Progress in CairoLS Jul 19, 2024
@mkaput
Copy link
Member Author

mkaput commented Aug 2, 2024

@LamsyA any progress? how can I help?

@mkaput mkaput moved this from In Progress to Backlog in CairoLS Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed ide This issue refers to CairoLS or editor extensions
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

3 participants