-
Notifications
You must be signed in to change notification settings - Fork 46
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
[Feature] Add endpoints specifically for Organize Imports and Fix All #54
Comments
I believe it can be implemented in your language client using this code from By the way, I use Vim/Neovim and my LSP client plugin was able to handle this. |
Yeah we do have a dedicated "Fix all" action in the VS Code plugin. I'm not sure that this is solvable in general for all clients since it requires some modifications for the client itself. Where are you using the LSP? (Like, what editor, etc.?) (Thanks for the kind words :)) |
I use Neovim with the built-in LSP client. I am aware the client will need custom additions to handle these. Workspace command Thank you, @yaegassy, I can take a look at those to implement it. @charliermarsh this should be adequate to implement a custom handler/command, thank you. I will report back with my addition. |
Ok cool -- does the LSP need a (Separately, I don't think it solves your problem, but note that we do also support |
I think this would be about what would be needed. I made edits to the @LSP_SERVER.command("ruff.organizeImports")
def apply_organize_imports(arguments: tuple[TextDocument]):
uri = arguments[0]["uri"]
text_document = LSP_SERVER.workspace.get_document(uri)
LSP_SERVER.apply_edit(
_create_workspace_edits(text_document, _formatting_helper(text_document, only="I001") or []),
"Ruff: Organize Imports",
) Not following what the source things are. Not seeing them in the code for the LSP inside the server.py, or things that could be them. Thank you! |
Yeah that looks reasonable. Feel free to send a PR. I was referring to the latter two kinds in this code block: @LSP_SERVER.feature(
TEXT_DOCUMENT_CODE_ACTION,
CodeActionOptions(
code_action_kinds=[
CodeActionKind.QuickFix,
CodeActionKind.SourceFixAll,
CodeActionKind.SourceOrganizeImports,
f"{CodeActionKind.SourceFixAll}.ruff",
f"{CodeActionKind.SourceOrganizeImports}.ruff",
],
resolve_provider=True,
),
)
def code_action(params: CodeActionParams) -> list[CodeAction] | None:
"""LSP handler for textDocument/codeAction request."""
... |
Added support for `ruff.organizeImports` as a workspace command. I couldn't properly test because I got very frustrated due to not being able to disable organize imports and fix all code actions. I didn't get to testing that this command would work properly. Wanted to post it though as others may be able to test easier and/or I can come back a little later and try again. Fixes #54 Thanks.
Right now, Organize Imports and Fix All code actions fill the code actions list anywhere in any python code. There are settings to disable these code actions (it seems, I'm new to this LSP). I would like to disable the code actions and make each of these separate commands that could be run.
For example, in typescript-language-server has
workspace/executeCommand
which allows you to run these specific actions. This allows the functionality of these good code actions, but done separately of the code actions list.Thanks for this LSP and the great ruff linter.
The text was updated successfully, but these errors were encountered: