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

Complete extern crates in extern crate items #13002

Closed
Veykril opened this issue Aug 11, 2022 · 7 comments
Closed

Complete extern crates in extern crate items #13002

Veykril opened this issue Aug 11, 2022 · 7 comments
Assignees
Labels
A-completion autocompletion C-feature Category: feature request E-easy E-has-instructions Issue has some instructions and pointers to code to get started

Comments

@Veykril
Copy link
Member

Veykril commented Aug 11, 2022

extern crate $0 we should complete all crates names from the extern crate prelude for the current crate here

@Veykril Veykril added E-easy A-completion autocompletion C-feature Category: feature request labels Aug 11, 2022
@Spaceface16518
Copy link

I figure this issue is low-priority, so I'm going to try to use it to get into contributing to rust-analyzer.

@rustbot claim

@Veykril
Copy link
Member Author

Veykril commented Jan 30, 2023

This requires adding a corresponding variant here

pub(super) enum NameRefKind {
Path(PathCompletionCtx),
DotAccess(DotAccess),
/// Position where we are only interested in keyword completions
Keyword(ast::Item),
/// The record expression this nameref is a field of and whether a dot precedes the completion identifier.
RecordExpr {
dot_prefix: bool,
expr: ast::RecordExpr,
},
Pattern(PatternContext),
}

constructing it here
let segment = match_ast! {
match parent {
ast::PathSegment(segment) => segment,
ast::FieldExpr(field) => {
let receiver = find_opt_node_in_file(original_file, field.expr());
let receiver_is_ambiguous_float_literal = match &receiver {
Some(ast::Expr::Literal(l)) => matches! {
l.kind(),
ast::LiteralKind::FloatNumber { .. } if l.syntax().last_token().map_or(false, |it| it.text().ends_with('.'))
},
_ => false,
};
let kind = NameRefKind::DotAccess(DotAccess {
receiver_ty: receiver.as_ref().and_then(|it| sema.type_of_expr(it)),
kind: DotAccessKind::Field { receiver_is_ambiguous_float_literal },
receiver
});
return Some(make_res(kind));
},
ast::MethodCallExpr(method) => {
let receiver = find_opt_node_in_file(original_file, method.receiver());
let kind = NameRefKind::DotAccess(DotAccess {
receiver_ty: receiver.as_ref().and_then(|it| sema.type_of_expr(it)),
kind: DotAccessKind::Method { has_parens: method.arg_list().map_or(false, |it| it.l_paren_token().is_some()) },
receiver
});
return Some(make_res(kind));
},
_ => return None,
}
};
and then adding a new completion module that handles it https://github.com/rust-lang/rust-analyzer/tree/f1b257f4eb4fef74b42fd7135d1cf3884e8b51c9/crates/ide-completion/src/completions

@Veykril Veykril added the E-has-instructions Issue has some instructions and pointers to code to get started label Jan 30, 2023
@jmintb
Copy link
Contributor

jmintb commented Mar 20, 2023

Can I have a go at this issue? :)

@Veykril
Copy link
Member Author

Veykril commented Mar 20, 2023

go ahead!

@Spaceface16518
Copy link

Apologies for dropping this. I never managed to get this to work, but feel free to take a look at my fork for any code that may be helpful @jmintb.

master...Spaceface16518:rust-analyzer:master

@jmintb
Copy link
Contributor

jmintb commented Jun 25, 2023

I had to focus on uni for a bit, will get back on this now.

@jmintb
Copy link
Contributor

jmintb commented Aug 2, 2023

@rustbot claim

bors added a commit that referenced this issue Aug 8, 2023
feat: Implement extern crate completion

Hi, this is a draft PR for #13002.

I have basic completion working as well as a filter for existing extern crate imports in the same file. This is based on the tests, I have not actually tried this in an editor. Before going further I think this is a good point to stop and get feedback on the
structure and approach I have taken so far. Let me know what you think :)

I will make sure to add more tests, rebase commits and align with the code style guidelines before submitting a final version.

A few specific questions :
1. Is there a better way to check for matching suggestions? right now I just test if an extern crate name starts with the current
user input.
2. Am I creating the `CompletionItem` correctly? I noticed that `use_.rs` invokes a builder where as I do not.
3. When checking for existing extern crate imports the current implementation only looks at the current source file, is that sufficient?
bors added a commit that referenced this issue Aug 15, 2023
feat: Implement extern crate completion

Hi, this is a draft PR for #13002.

I have basic completion working as well as a filter for existing extern crate imports in the same file. This is based on the tests, I have not actually tried this in an editor. Before going further I think this is a good point to stop and get feedback on the
structure and approach I have taken so far. Let me know what you think :)

I will make sure to add more tests, rebase commits and align with the code style guidelines before submitting a final version.

A few specific questions :
1. Is there a better way to check for matching suggestions? right now I just test if an extern crate name starts with the current
user input.
2. Am I creating the `CompletionItem` correctly? I noticed that `use_.rs` invokes a builder where as I do not.
3. When checking for existing extern crate imports the current implementation only looks at the current source file, is that sufficient?
bors added a commit that referenced this issue Aug 21, 2023
feat: Implement extern crate completion

Hi, this is a draft PR for #13002.

I have basic completion working as well as a filter for existing extern crate imports in the same file. This is based on the tests, I have not actually tried this in an editor. Before going further I think this is a good point to stop and get feedback on the
structure and approach I have taken so far. Let me know what you think :)

I will make sure to add more tests, rebase commits and align with the code style guidelines before submitting a final version.

A few specific questions :
1. Is there a better way to check for matching suggestions? right now I just test if an extern crate name starts with the current
user input.
2. Am I creating the `CompletionItem` correctly? I noticed that `use_.rs` invokes a builder where as I do not.
3. When checking for existing extern crate imports the current implementation only looks at the current source file, is that sufficient?
@lnicola lnicola closed this as completed Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion C-feature Category: feature request E-easy E-has-instructions Issue has some instructions and pointers to code to get started
Projects
None yet
Development

No branches or pull requests

4 participants