-
Notifications
You must be signed in to change notification settings - Fork 380
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
COMP: add completion of lint attributes #5646
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general looks great!
Could you rebase onto master, please?
src/main/kotlin/org/rust/lang/core/completion/RsLintCompletionProvider.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/org/rust/lang/core/completion/RsLintCompletionProvider.kt
Outdated
Show resolved
Hide resolved
private sealed class Lint(val name: String) { | ||
class RustcSpecific(name: String) : Lint(name) | ||
class RustcGroup(name: String) : Lint(name) | ||
class Clippy(name: String) : Lint("clippy::$name") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, there are clippy groups as well according to its documentation
src/main/kotlin/org/rust/lang/core/completion/RsLintCompletionProvider.kt
Outdated
Show resolved
Hide resolved
) | ||
} | ||
|
||
private fun getIcon(lint: Lint): Icon = when (lint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide to split the current completion provider into two ones, it may be convenient to move this method into Lint
itself
else -> RsIcons.ATTRIBUTE | ||
} | ||
|
||
private fun getPriority(lint: Lint): Double = when (lint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same about moving method into Lint
val name = it.name | ||
if (!name.startsWith(prefix)) return@forEach | ||
|
||
val offered = name.removePrefix(prefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now on the root level it offers all lints (i.e. both unused and clippy::xxx), maybe we can only offer clippy:: at the root level and only after completing that we can start completing clippy lints?
It looks quite hacky. I think it's definitely better to suggest complex lints like clippy::xxx
in two steps.
Probably, it makes sense to split this provider into two: one for rustc
lints and another one for clippy
src/main/kotlin/org/rust/lang/core/completion/RsLintCompletionProvider.kt
Outdated
Show resolved
Hide resolved
@@ -169,12 +176,17 @@ object RsPsiPattern { | |||
.withSuperParent(2, RsOuterAttributeOwner::class.java) | |||
.with("nonStdAttributeCondition") { e -> e.name !in STD_ATTRIBUTES } | |||
|
|||
val lintAttributeMetaItem: PsiElementPattern.Capture<RsMetaItem> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JFYI there is org.rust.lang.core.completion.RsPsiPatternTest
to check that patterns works expected.
We usually don't use unit test and use integration instead but since patterns can be quite complex, these tests can be helpful
Actually, I decided to handle the automatic lint setup in this PR, it would just be a needless change if I messed with the lint data structure afterwards. I created a gradle task that parses Rustc lints from
What should I use? I would prefer option 3), by creating a Python script in the |
@Kobzol at the first glance, option |
Ok. My notebook's disk died and I didn't backup the WIP code that I had (which was using gradle |
84f4b40
to
cecc608
Compare
Rewrote it from scratch. |
src/main/kotlin/org/rust/lang/core/completion/lint/RsLintCompletionProvider.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/org/rust/lang/core/completion/lint/RsRustcLintCompletionProvider.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/org/rust/lang/core/completion/lint/RsLintCompletionProvider.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/org/rust/lang/core/completion/lint/RsLintCompletionProvider.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/org/rust/lang/core/completion/lint/RsLintCompletionProvider.kt
Outdated
Show resolved
Hide resolved
Thanks for the review! It seems that I forgot to remove some things that weren't needed. I put the changes into a separate commit to make additional review easier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thank you! It's great!
Could you do the following things before the merge, please?:
- update gif image in the description since it's a little bit outdated regarding clippy lints
- squash commits
7f799f9
to
cbbd141
Compare
Done and done. Btw, I think that similar completion could be useful for features (both language and compiler ones), what do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+
Yep, it may be handy for some users. We even already have a list of compiler features in the plugin and a way to update them.
|
Good point, it should probably be introduced gradually (by solving some of the substeps first). |
Build succeeded: |
6305: COMP: simplify script for fetching Clippy lints r=Undin a=Kobzol I noticed in the Rust Analyzer [changelog](https://rust-analyzer.github.io/thisweek/2020/10/26/changelog-48.html) that they also added lint completion a few days ago (what a coincidence! :D ). They use a JSON with all Clippy lints that I didn't know of. It's a much simpler solution than cloning the `clippy` repository, which is what I have done in the [original PR](#5646). Theoretically, the Python script could now be moved back into `build.gradle.kts`, but I don't think it's worth it. Co-authored-by: Jakub Beránek <berykubik@gmail.com>
This PR adds completion of lint attributes in
allow
,deny
,warn
andforbid
meta items. The lints are filtered based on their path prefix, i.e. if you writeclippy::
, it will only offer you lints fromclippy
.Right now on the root level it offers all lints (i.e. both
unused
andclippy::xxx
), maybe we can only offerclippy::
at the root level and only after completing that we can start completingclippy
lints?Fixes: #3720