-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Magic Completion for impl Trait for Associated Items
#3108
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
Magic Completion for impl Trait for Associated Items
#3108
Conversation
…ir names must be unique.
impl Trait forimpl Trait for Associated Items
|
This an amazing addition, thanks so much for working on it! |
|
This looks good to me! I think the test fail primaraly due to I think there's a bunch of things we can further tweak here, but it's also good to land as is. |
Ah, there was formatting issues. I was sure I had the
I'm happy to further refine this if you had thoughts. I can also refine it in a separate PR if your intention was to accept this as is. |
|
Whoops, spoke too soon, test still failed. Let me try removing the doc comments as it seems to be bringing up |
|
Oh, @matklad, maybe the CI is complaining about needing module level documentation? That would make sense 🤔 Edit: Yup that was it 🤦♂ |
|
I'd lean towards checking this in this specific completion, and not in the
general completion context. But it doesn't matter that much, moving between
the two should be easy.
…On Tue, 11 Feb 2020 at 17:15, Kevin DeLorey ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In crates/ra_ide/src/completion/complete_trait_impl.rs
<#3108 (comment)>
:
> +/// ```ignore
+/// trait SomeTrait {
+/// const SOME_CONST: u16;
+/// }
+///
+/// impl SomeTrait for () {
+/// const <|>
+/// }
+/// ```
+pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) {
+
+ // it is possible to have a parent `fn` and `impl` block. Ignore completion
+ // attempts from within a `fn` block.
+ if ctx.function_syntax.is_some() {
+ return;
+ }
Ah, makes sense. Would there any need for the CompletionContext to
provide the impl_block as this behavior seems pretty specific to this
completion type?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3108>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANB3M7GX6LTCFMMTEJ4SUTRCLFILANCNFSM4KTAQCCA>
.
|
|
I agree, when I get home from my day job I'll work on that change. Thanks for taking a look. |
|
@matklad one thing I've discovered while working on the suggested change was the impl SomeTrait for () {
fn<|>
}will produce something like the following syntax tree: ITEM_LIST@[85; 95)
L_CURLY@[85; 86) "{"
WHITESPACE@[86; 91) "\n "
FN_DEF@[91; 93) <-- incomplete `fn` syntrax makes `FN_DEF`
FN_KW@[91; 93) "fn"
WHITESPACE@[93; 94) "\n"
R_CURLY@[94; 95) "}"But with a impl SomeTrait for () {
const<|>
}will produce something like the following It won't generate a Edit: I pushed my WIP changes so you can see how I started going about your suggestion. |
That's semi-intentional, in that |
|
bors r+ Thanks! |
3108: Magic Completion for `impl Trait for` Associated Items r=matklad a=kdelorey # Summary This PR adds a set of magic completions to auto complete associated trait items (functions/consts/types).  ## Notes Since the assist and completion share the same logic when figuring out the associated items that are missing, a shared utility was created in the `ra_assists::utils` module. Resolves #1046 As this is my first PR to the rust-analyzer project, I'm new to the codebase, feedback welcomed! Co-authored-by: Kevin DeLorey <2295721+kdelorey@users.noreply.github.com>
Build succeeded
|
|
Opened a sequel in #3183 |
|
@matklad, thanks for working with me on this. It was pretty rewarding to open reddit this morning and see a gif of my contribution 🎉 |
Allow trait autocompletions for unimplemented associated fn's, types, and consts without using explicit keywords before hand (fn, type, const). The sequel to rust-lang#3108.
Allow trait autocompletions for unimplemented associated fn's, types, and consts without using explicit keywords before hand (fn, type, const). The sequel to rust-lang#3108.
Summary
This PR adds a set of magic completions to auto complete associated trait items (functions/consts/types).
Notes
Since the assist and completion share the same logic when figuring out the associated items that are missing, a shared utility was created in the
ra_assists::utilsmodule.Resolves #1046
As this is my first PR to the rust-analyzer project, I'm new to the codebase, feedback welcomed!