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

#![allow(clippy:: incorrectly completes with a leading clippy:: #7144

Closed
RDambrosio016 opened this issue Jan 3, 2021 · 8 comments · Fixed by #10562
Closed

#![allow(clippy:: incorrectly completes with a leading clippy:: #7144

RDambrosio016 opened this issue Jan 3, 2021 · 8 comments · Fixed by #10562
Labels
A-completion autocompletion S-actionable Someone could pick this issue up and work on it right now

Comments

@RDambrosio016
Copy link
Contributor

Reproducible code

#![allow(clippy::

Select any of the lints, it will be completed as #![allow(clippy::clippy::or_fun_call)] for example, which is incorrect.

I presume this is because vsc does not consider clippy:: to be a full ident per the rust grammar, therefore it thinks the completion should go after it because the first part isnt part of it

@crumblingstatue
Copy link

crumblingstatue commented Jul 7, 2021

I noticed that what the user typed so far is highlighted in the completion hints
image
However, if :: is typed after clippy, the highlighting stops working.
image
Is the above assessment correct in this being a fault of visual studio code? Should it be fixed there, or can it be fixed in rust-analyzer?

EDIT: Actually, the highlighting behavior is the same for other kinds of completions after double colon. What's different is that the completion hints don't include the part before the ::
image

I did some debug printing inside complete_attribute(acc: &mut Completions, ctx: &CompletionContext), and I noticed that when doing autocomplete after ::, for regular paths, ctx.original_token is [email protected] "::", but for lint attributes, it's [email protected] ":". Looks like for some reason it's not being recognized as COLON2 in lint attributes.

@bjorn3
Copy link
Member

bjorn3 commented Jul 7, 2021

Something similar happens with pub(crate) which turns into pub(pub(crate)).

@crumblingstatue
Copy link

@RDambrosio016
Copy link
Contributor Author

Macro invocations are raw token trees, so no tokens are joined because there is no "semantic meaning"

@crumblingstatue
Copy link

Welp, I give up for now, haha. I have no idea how to debug this.

@RDambrosio016
Copy link
Contributor Author

I think this is just an issue with vsc not thinking the colons form a full ident and therefore putting the completion just after the colons, while RA should be telling it to replace everything in the completion

@Veykril
Copy link
Member

Veykril commented Jul 7, 2021

The problem here is that we do not recognize the clippy:: prefix in the completion building process. So when we insert the completion we insert if after the already existing clippy:: instead of replacing it.

Basically the ctx.source_range() call here is incorrect, instead we need to fetch the ranges of the clippy and :: token as ctx.source_range() returns the range of the current identifier we are completing, which isn't correct in this case. https://github.com/rust-analyzer/rust-analyzer/blob/9f24cc7126f6508dcc9e429a33bd12975873d3e4/crates/ide_completion/src/completions/attribute/lint.rs#L24

@Veykril
Copy link
Member

Veykril commented Jul 7, 2021

Fixing this is rather tricky as we have to basically manually reparse the input we are expecting. It would be great if we could reuse that path completion infra here but inputs to attributes are just random tokens to us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants