-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
fix(analyze & lsp): code action and text mutation #2237
Conversation
✅ Deploy Preview for biomejs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
CodSpeed Performance ReportMerging #2237 will improve performances by 7.51%Falling back to comparing Summary
Benchmarks breakdown
|
f53812b
to
c15869d
Compare
f2880ae
to
55d4000
Compare
55d4000
to
40cde73
Compare
!bench_cli |
If I remember correctly, these magic coments were removed when we added automated benchmark using Codspeed. |
f22ffa7
to
770f2a9
Compare
Out of curiosity, how did you compile the binary? We have some settings that we push during the CI |
Isn't it |
If both benchmarks run on the same built artifact, then it should be fine. During the CI we pass some environment variables: https://github.com/biomejs/biome/blob/main/.github%2Fworkflows%2Frelease_cli.yml#L128-L132 |
Oh yes I didn't set the |
Reverse the order of code actions, so actions will be applied from back to front. This will make sure following code actions won't be invalidated by their previous code actions.
Transferring the leading trivia in code actions of some rules can invalidate comment directives. This also helps to get the correct result when applying code actions one by one.
The core logic is in file `crates/biome_rowan/src/ast/batch.rs`. This commit reimplements how we calculate the text range and text edit from batch mutations: - `SyntaxSlot::Empty` now contains an index position of the empty slot. This is to aid the calculation of text edit from commit changes. - `TextEdit` has a new public method `with_unicode_words_diff`. This is to aid the calculation of text edit from commit changes. - The `key` of `CommitChange` that will affect its order in a sorted list is changed. This is to ensure changes will be addressed from back to front. - Add an `is_from_action` field to `CommitChange`. This is to distinguish whether a commit change is from the action or is propagated from the children. This is to aid the calculation of text edit from commit changes. - Rename `as_text_edits` to `as_text_range_and_edit` for clarification. - The core logic of `commit` is moved into `commit_with_text_range_and_edit`. That's because when calculating the text range and text edit, we need to commit the changes. So they should be addressed together. - When the new tree, text range and text edit are all required, we should use `commit_with_text_range_and_edit` instead of `commit` and `as_text_range_and_edit` separately to avoid unncessary clone. That's because when calculating the text range and text edit, we also need to commit the changes. This should be done in one pass.
Most of the updates are the result of the reimplementation of how we calculate the text edits. Previously, the text edit is acquired from a naive text diff of the code before and after commit. We now populate the text edit struct manually when applying changes. Some of the updates are the reuslt of discarding leading trivia when removing a node.
This is to keep them consistent with the existing code.
@ematipico Do you have other suggestions or can I merge this? |
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 changes look good to me; I left only a few nits. That was some hard work you poured into this PR @Sec-ant, fantastic! 💪
770f2a9
to
b4679d3
Compare
Should be good to go. I'm gonna merge this now! |
Summary
This PR fixes the unexpected code deletion and repetition when
quickfix.biome
is enabled and someimport
-related rules are applied.This PR includes 3 fixes:
noUnusedImports
andnoRedundantUseStrict
, remove the trivia of theimport
statements or"use strict"
directives instead of transferring them to their siblings.TextEdit
s fromCommitChange
s directly, instead of.commit().to_string()
and diffing the entire code string.To make this PR code review experience friendly, I grouped the changes into several commits:
fix(code_actions): reverse order: 0bf3f09
Reverse the order of code actions, so actions will be applied from back to front.
This will make sure following code actions won't be invalidated by their previous code actions.
fix(rules): remove leading trivia instead of transferring them: 4f1e9cd
This helps to get the correct result when applying code actions one by one.
This can also avoid potential problems where comment directives like
@ts-expect-error
being transferred to an unexpected place.fix(text_range_and_text_edit): refactor and reimplementation: 22780e8
The core logic is in file
crates/biome_rowan/src/ast/batch.rs
. This commit reimplements how we calculate the text range and text edit from batch mutations:SyntaxSlot::Empty
now contains an index position of the empty slot. This is to aid the calculation of text edit from commit changes.TextEdit
has a new public methodwith_unicode_words_diff
. This is to aid the calculation of text edit from commit changes.key
ofCommitChange
that will affect its order in a sorted list is changed. This is to ensure changes will be addressed from back to front.is_from_action
field toCommitChange
. This is to distinguish whether a commit change is from the action or is propagated from the children. This is to aid the calculation of text edit from commit changes.as_text_edits
toas_text_range_and_edit
for clarification.commit
is moved intocommit_with_text_range_and_edit
. That's because when calculating the text range and text edit, we need to commit the changes. So they should be addressed together.commit_with_text_range_and_edit
instead ofcommit
andas_text_range_and_edit
separately to avoid unncessary clone. That's because when calculating the text range and text edit, we also need to commit the changes. This should be done in one pass.chore: update test snapshots: 41bc14c
Most of the updates are the result of the reimplementation of how we calculate the text edits.
Previously, the text edit is acquired from a naive text diff of the code before and after commit.
We now populate the text edit struct manually when applying changes.
Some of the updates are the reuslt of discarding leading trivia when removing a node.
chore: regenerate web docs:
40cde73
Regenerate the web docs to reflect the changes.
chore: update changelog: 434627f
Update the changelog to reflect the fix.
chore: update changelog: db8b4cf
Unlink some issues in the changelog.
Test Plan
CI should pass. There'll be many snapshot updates (see above for the reasons). But the final result should be correct.
Code actions are tested locally with VSCode:
noUnusedImports
Video Demos
no-unused-imports-before.mp4
no-unused-imports-after.mp4
no-unused-imports-before.mp4
no-unused-imports-after.mp4
useImportType
Video Demos
use-import-type-before.mp4
use-import-type-after.mp4
I cannot reproduce others from the linked issues. Please provide the code and settings (include biome and vscode) if someone has a stable minimal reproduction.