-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
ruff server
now supports the source.organizeImports
source action
#10652
Conversation
|
crates/ruff_server/src/server/api/requests/code_action_resolve.rs
Outdated
Show resolved
Hide resolved
mut action: types::CodeAction, | ||
document: &crate::edit::Document, | ||
url: &types::Url, | ||
mut linter_settings: ruff_linter::settings::LinterSettings, |
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.
Hmm, it's unfortunate that this requires making LinterSettings
cloneable but I haven't been able to come up with an alternative solution that not at least requires cloning individual fields. Ideally it would be possible to call check
with the desired rules, but that's a larger refactor and is probably not worth it.
I don't feel strongly but I have a slight preference to pass in a LinterSetting
and move the cloning into resolve_edit_for_organize_imports
.
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.
Could we do something like the following?
- Take a snapshot of existing settings
- Mutate it temporarily
- Restore the settings with the snapshot
I'm not sure how involved this is or if it's better than cloning. That said, I wouldn't recommend doing in this PR but something to think about if we need or want to refactor this in the future.
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.
@MichaReiser @dhruvmanila I'll make a follow-up issue to look into how we could improve this for the future.
Would you mind testing that adding the organizeImports action (ruff or the global one) into the on save action works as expected
(or using the ruff specific actions) |
4d50aa6
to
9145d53
Compare
@MichaReiser I've confirmed that the configuration you've provided works as expected. However, the ruff-specific configuration is not working, but for an unrelated reason, which I'll address in a follow-up issue. |
…ts, and formatting (#10654) ## Summary This builds off of the work in #10652 to implement a command executor, backwards compatible with the commands from the previous LSP (`ruff.applyAutofix`, `ruff.applyFormat` and `ruff.applyOrganizeImports`). This involved a lot of refactoring and tweaks to the code action resolution code - the most notable change is that workspace edits are specified in a slightly different way, using the more general `changes` field instead of the `document_changes` field (which isn't supported on all LSP clients). Additionally, the API for synchronous request handlers has been updated to include access to the `Requester`, which we use to send a `workspace/applyEdit` request to the client. ## Test Plan https://github.com/astral-sh/ruff/assets/19577865/7932e30f-d944-4e35-b828-1d81aa56c087
…astral-sh#10652) ## Summary This builds on top of the work in astral-sh#10597 to support `Ruff: Organize imports` as an available source action. To do this, we have to support `Clone`-ing for linter settings, since we need to modify them in place to select import-related diagnostics specifically (`I001` and `I002`). ## Test Plan https://github.com/astral-sh/ruff/assets/19577865/04282d01-dfda-4ac5-aa8f-6a92d5f85bfd
…ts, and formatting (astral-sh#10654) ## Summary This builds off of the work in astral-sh#10652 to implement a command executor, backwards compatible with the commands from the previous LSP (`ruff.applyAutofix`, `ruff.applyFormat` and `ruff.applyOrganizeImports`). This involved a lot of refactoring and tweaks to the code action resolution code - the most notable change is that workspace edits are specified in a slightly different way, using the more general `changes` field instead of the `document_changes` field (which isn't supported on all LSP clients). Additionally, the API for synchronous request handlers has been updated to include access to the `Requester`, which we use to send a `workspace/applyEdit` request to the client. ## Test Plan https://github.com/astral-sh/ruff/assets/19577865/7932e30f-d944-4e35-b828-1d81aa56c087
Summary
This builds on top of the work in #10597 to support
Ruff: Organize imports
as an available source action.To do this, we have to support
Clone
-ing for linter settings, since we need to modify them in place to select import-related diagnostics specifically (I001
andI002
).Test Plan
organizeImports.Test.Plan.mp4