-
-
Notifications
You must be signed in to change notification settings - Fork 476
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
feat(analyzer): assists #3399
feat(analyzer): assists #3399
Conversation
Parser conformance results onjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
CodSpeed Performance ReportMerging #3399 will not alter performanceComparing Summary
|
dd25de0
to
c325f4a
Compare
f4412ca
to
2a7938d
Compare
466c21d
to
6b7bc6e
Compare
assert!(result.is_ok(), "run_cli returned {result:?}"); | ||
|
||
assert_file_contents( | ||
&fs, | ||
file, | ||
r#"{ "foo": "bar" ,"lorem": "ipsum","zod": true }"#, | ||
); |
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.
I wonder why we use this kind of assertion when we have snapshots?
The configuration and the used concepts seem very close to the linter. It will certainly be impacted by #689. In this case, I wonder if we should decide on #689 before shipping assits to users? Personally, I could remove the Because it is close to the linter configuration, we get the same questions: how handle multi-languages? For instance {
"json": {
"assists": {
"rules": {
"source": {
"useSortedKeys": "on"
}
}
}
},
"javascript": {
"assists": {
"rules": {
"source": {
"useSortedClasses": "on"
}
}
}
},
}
I am a bit worried about tightening up a group (
Could you give us some examples for each group?
However, can we expect users to request options for some of them? Also, you choose Do we agree that an assist rule should be available on a command palette in an editor even if it is turned off in the configuration? I wonder if we should rename
Do you think we could move |
I'd prefer to ship now, and change later. We haven't decided how the configuration is going to change, and how. It could take a lot of time. I would feel demoralised if I can't ship a feature only because we haven't take a decision 😞
What do you think about removing
I think it's a good thing that rules work across languages. Our documentation will be refactored so it can show which languages a rule is for. That's why I added the
But that's the meaning of
I already did: refactor, inline, extract. Those groups will be mapped from
That's possible, but options feel more like something for lint rules.
That, and because we already use
Yes, but only for assists that aren't
I think so, yes! Good suggestion
I think it's a separate discussion. Also, since when there's an ambiguity? |
I am ok with that also :)
I am still skeptical about this. Hopefully we will reach some consensus by Biome 2.0.
Good point!
It is not really an ambiguity, but rather an inconsistency. |
I see some possible usage: for instance I want to sort quickly the keys of a JavaScript object without requiring me to sort the keys of every object in the file. |
I believe I miss some context here, because I don't know what you're talking about 😅
I can see the use case. IDEs should be able to provide code actions based on text ranges. I will tackle that part in a later PR |
fc712cd
to
815becf
Compare
Co-authored-by: Carson McManus <dyc3@users.noreply.github.com>
815becf
to
7a76baa
Compare
Summary
Part of #3178
This PR implements the CLI part of the assists. The assists are considered another tool of Biome, so they deserve a particular spot inside Biome. That's how first assist will look like:
Important
The rule
organizeImports
is an assist, but we consider it a special one because it has its own configuration, which means it is excluded from the other rules.As for rule groups, we follow the same distinction that the LSP uses:
source
: actions to apply to the whole document/file, they will be part offixAll
actionrefactor
,inline
,extract
, etc.) won't be applied by thefixAll
actionThe assists rules aren't meant to have any kind of options, so they just have a
"on"
or"off"
flag to enabled them or disable them.Here's the list of technical changes that this PR does:
generate_configuration
andgenerate_analyzer
to generate the new configuration for assists, which differs from the linter rules.assists
andoverrides.assists
.ci
andcheck
to accept--assists-enabled
flag.assists
process_file/assists.rs
file, responsible to pull the fixes ofRuleCategories::Action
and apply them. If--write
mode, it updates the file, otherwise it emits a diagnostic. It uses the existing CLI infrastructure, so there's nothing new added.pull_actions
method to acceptskip
andonly
, which will be relevant in the future.range
is now aOption<TextRange>
.fix_file
method to accept aRuleCategories
, which will become relevant in the future..gitattributes
to include graphql crates, and make it more maintainable.xtask/rules_check
, where the GraphQL files weren't checked. They are now checked, and I fixed a case where an example wasn't emitting a diagnostic.file_handlers/mod.rs
. There was still a LOT of repeated code. So now we have a type calledAnalyzerVisitorBuilder
that builds the visitors, and the rest is done inside a function calledfinish()
. When we add a new language, we just need to update this method, and the compiler will do the rest, forcing the developer to apply the traits for the new language. TheActionVisitor
is already read to acceptskip
andonly
, but they aren't used yet. They will become useful in the future in case we want to provide functionality to apply single assists.declare_refactor_rule
is renamed todeclare_source_rule
, which is inline with the semantics ofsource
Test Plan
I added new tests for the new
useSortedKeys
rule.What's missing
I plan to follow up with new PRs to address the following
flipBinaryExpression
, to show how non-source rules will work inside the LSP.