Skip to content
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

Always shown ruff-lsp code actions do nothing #8413

Closed
bluthej opened this issue Sep 27, 2023 · 3 comments · Fixed by #8421
Closed

Always shown ruff-lsp code actions do nothing #8413

bluthej opened this issue Sep 27, 2023 · 3 comments · Fixed by #8421
Labels
A-language-server Area: Language server client C-bug Category: This is a bug

Comments

@bluthej
Copy link

bluthej commented Sep 27, 2023

Summary

There are two code actions provided by ruff-lsp that are always shown:

  • Ruff: Organize Imports
  • Ruff: Fix All

Both of them do nothing when they are selected.

Note that when I select the I rule I have another code action that pops which is Ruff (I001): Organize imports which does work. It's the two code actions that are always shown that do nothing.

Reproduction Steps

  • I am building helix from source on the master branch (updated on the 27th of september 2023).

Note that in my config I have both pylsp and ruff-lsp activated, but I tried running only ruff-lsp and it did not help.

Python lsp config

[language-server.ruff-lsp]
command = "ruff-lsp"
args = []

[[language]]
name = "python"
formatter = { command = "black", args = ["--quiet", "-"] }
auto-format = true
language-servers = ["ruff-lsp", "pylsp"]

  • I open a Python file with some unordered imports
  • I open the code actions menu (<space-a>) and select the organize imports or the fix all code action
  • Nothing happens

I opened an issue on the ruff-lsp repo and I tried the config kindly provided by Charlie Marsch on the latest stable release. On this release, both code actions work, but on the master branch I cannot get them to work.

Helix log

~/.cache/helix/helix.log (master branch)
2023-09-27T22:27:59.858 helix_lsp::transport [INFO] ruff-lsp -> {"jsonrpc":"2.0","method":"textDocument/codeAction","params":{"context":{"diagnostics":[{"code":"I001","data":{"fix":{"applicability":"Automatic","edits":[{"content":"import os\nimport sys\n\n\n","end_location":{"column":0,"row":3},"location":{"column":0,"row":1}}],"message":"Organize imports"},"noqa_row":1},"message":"Import block is un-sorted or un-formatted","range":{"end":{"character":0,"line":2},"start":{"character":0,"line":0}},"severity":2,"source":"Ruff"}],"triggerKind":1},"range":{"end":{"character":1,"line":0},"start":{"character":0,"line":0}},"textDocument":{"uri":"file:///tmp/ruff/test.py"}},"id":1}
2023-09-27T22:27:59.872 helix_lsp::transport [INFO] ruff-lsp <- {"id": 1, "jsonrpc": "2.0", "result": [{"title": "Ruff: Organize Imports", "kind": "source.organizeImports", "diagnostics": [], "data": "file:///tmp/ruff/test.py"}, {"title": "Ruff: Fix All", "kind": "source.fixAll", "diagnostics": [], "data": "file:///tmp/ruff/test.py"}, {"title": "Ruff (I001): Organize imports", "kind": "quickfix", "diagnostics": [{"range": {"start": {"line": 0, "character": 0}, "end": {"line": 2, "character": 0}}, "message": "Import block is un-sorted or un-formatted", "severity": 2, "code": "I001", "source": "Ruff", "data": {"fix": {"applicability": "Automatic", "edits": [{"content": "import os\nimport sys\n\n\n", "end_location": {"column": 0, "row": 3}, "location": {"column": 0, "row": 1}}], "message": "Organize imports"}, "noqa_row": 1}}], "edit": {"documentChanges": [{"textDocument": {"uri": "file:///tmp/ruff/test.py", "version": 0}, "edits": [{"range": {"start": {"line": 0, "character": 0}, "end": {"line": 2, "character": 0}}, "newText": "import os\nimport sys\n\n\n"}]}]}, "data": "file:///tmp/ruff/test.py"}, {"title": "Ruff (I001): Disable for this line", "kind": "quickfix", "diagnostics": [{"range": {"start": {"line": 0, "character": 0}, "end": {"line": 2, "character": 0}}, "message": "Import block is un-sorted or un-formatted", "severity": 2, "code": "I001", "source": "Ruff", "data": {"fix": {"applicability": "Automatic", "edits": [{"content": "import os\nimport sys\n\n\n", "end_location": {"column": 0, "row": 3}, "location": {"column": 0, "row": 1}}], "message": "Organize imports"}, "noqa_row": 1}}], "edit": {"documentChanges": [{"textDocument": {"uri": "file:///tmp/ruff/test.py", "version": 0}, "edits": [{"range": {"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 9}}, "newText": "import os  # noqa: I001"}]}]}, "data": "file:///tmp/ruff/test.py"}]}
2023-09-27T22:27:59.872 helix_lsp::transport [INFO] ruff-lsp <- [{"data":"file:///tmp/ruff/test.py","diagnostics":[],"kind":"source.organizeImports","title":"Ruff: Organize Imports"},{"data":"file:///tmp/ruff/test.py","diagnostics":[],"kind":"source.fixAll","title":"Ruff: Fix All"},{"data":"file:///tmp/ruff/test.py","diagnostics":[{"code":"I001","data":{"fix":{"applicability":"Automatic","edits":[{"content":"import os\nimport sys\n\n\n","end_location":{"column":0,"row":3},"location":{"column":0,"row":1}}],"message":"Organize imports"},"noqa_row":1},"message":"Import block is un-sorted or un-formatted","range":{"end":{"character":0,"line":2},"start":{"character":0,"line":0}},"severity":2,"source":"Ruff"}],"edit":{"documentChanges":[{"edits":[{"newText":"import os\nimport sys\n\n\n","range":{"end":{"character":0,"line":2},"start":{"character":0,"line":0}}}],"textDocument":{"uri":"file:///tmp/ruff/test.py","version":0}}]},"kind":"quickfix","title":"Ruff (I001): Organize imports"},{"data":"file:///tmp/ruff/test.py","diagnostics":[{"code":"I001","data":{"fix":{"applicability":"Automatic","edits":[{"content":"import os\nimport sys\n\n\n","end_location":{"column":0,"row":3},"location":{"column":0,"row":1}}],"message":"Organize imports"},"noqa_row":1},"message":"Import block is un-sorted or un-formatted","range":{"end":{"character":0,"line":2},"start":{"character":0,"line":0}},"severity":2,"source":"Ruff"}],"edit":{"documentChanges":[{"edits":[{"newText":"import os  # noqa: I001","range":{"end":{"character":9,"line":0},"start":{"character":0,"line":0}}}],"textDocument":{"uri":"file:///tmp/ruff/test.py","version":0}}]},"kind":"quickfix","title":"Ruff (I001): Disable for this line"}]
~/.cache/helix/helix.log (latest stable release)

2023-09-27T22:25:24.098 helix_term::application [DEBUG] received editor event: LanguageServerMessage((0, Notification(Notification { jsonrpc: Some(V2), method: "window/logMessage", params: Map({"message": String("Running Ruff with: /home/joffrey/.local/pipx/venvs/ruff-lsp/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--format', 'json', '-', '--fix', '--stdin-filename', '/tmp/ruff/test.py']"), "type": Number(4)}) })))
2023-09-27T22:25:24.098 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Log, message: "Running Ruff with: /home/joffrey/.local/pipx/venvs/ruff-lsp/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--format', 'json', '-', '--fix', '--stdin-filename', '/tmp/ruff/test.py']" }
2023-09-27T22:25:24.115 helix_lsp::transport [INFO] <- {"id": 1, "jsonrpc": "2.0", "result": [{"title": "Ruff: Organize Imports", "kind": "source.organizeImports", "diagnostics": [], "edit": {"documentChanges": [{"textDocument": {"uri": "file:///tmp/ruff/test.py", "version": 0}, "edits": [{"range": {"start": {"line": 0, "character": 0}, "end": {"line": 2147483647, "character": 0}}, "newText": "import os\nimport sys\n\n\ndef f():\n    x = 1\n"}]}]}, "data": "file:///tmp/ruff/test.py"}, {"title": "Ruff: Fix All", "kind": "source.fixAll", "diagnostics": [{"range": {"start": {"line": 0, "character": 0}, "end": {"line": 2, "character": 0}}, "message": "Import block is un-sorted or un-formatted", "severity": 2, "code": "I001", "source": "Ruff", "data": {"fix": {"applicability": "Automatic", "edits": [{"content": "import os\nimport sys\n\n\n", "end_location": {"column": 0, "row": 3}, "location": {"column": 0, "row": 1}}], "message": "Organize imports"}, "noqa_row": 1}}], "edit": {"documentChanges": [{"textDocument": {"uri": "file:///tmp/ruff/test.py", "version": 0}, "edits": [{"range": {"start": {"line": 0, "character": 0}, "end": {"line": 2147483647, "character": 0}}, "newText": "def f():\n    pass\n"}]}]}, "data": "file:///tmp/ruff/test.py"}, {"title": "Ruff (I001): Organize imports", "kind": "quickfix", "diagnostics": [{"range": {"start": {"line": 0, "character": 0}, "end": {"line": 2, "character": 0}}, "message": "Import block is un-sorted or un-formatted", "severity": 2, "code": "I001", "source": "Ruff", "data": {"fix": {"applicability": "Automatic", "edits": [{"content": "import os\nimport sys\n\n\n", "end_location": {"column": 0, "row": 3}, "location": {"column": 0, "row": 1}}], "message": "Organize imports"}, "noqa_row": 1}}], "edit": {"documentChanges": [{"textDocument": {"uri": "file:///tmp/ruff/test.py", "version": 0}, "edits": [{"range": {"start": {"line": 0, "character": 0}, "end": {"line": 2, "character": 0}}, "newText": "import os\nimport sys\n\n\n"}]}]}, "data": "file:///tmp/ruff/test.py"}, {"title": "Ruff (I001): Disable for this line", "kind": "quickfix", "diagnostics": [{"range": {"start": {"line": 0, "character": 0}, "end": {"line": 2, "character": 0}}, "message": "Import block is un-sorted or un-formatted", "severity": 2, "code": "I001", "source": "Ruff", "data": {"fix": {"applicability": "Automatic", "edits": [{"content": "import os\nimport sys\n\n\n", "end_location": {"column": 0, "row": 3}, "location": {"column": 0, "row": 1}}], "message": "Organize imports"}, "noqa_row": 1}}], "edit": {"documentChanges": [{"textDocument": {"uri": "file:///tmp/ruff/test.py", "version": 0}, "edits": [{"range": {"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 9}}, "newText": "import os  # noqa: I001"}]}]}, "data": "file:///tmp/ruff/test.py"}]}
2023-09-27T22:25:24.115 helix_lsp::transport [INFO] <- [{"data":"file:///tmp/ruff/test.py","diagnostics":[],"edit":{"documentChanges":[{"edits":[{"newText":"import os\nimport sys\n\n\ndef f():\n    x = 1\n","range":{"end":{"character":0,"line":2147483647},"start":{"character":0,"line":0}}}],"textDocument":{"uri":"file:///tmp/ruff/test.py","version":0}}]},"kind":"source.organizeImports","title":"Ruff: Organize Imports"},{"data":"file:///tmp/ruff/test.py","diagnostics":[{"code":"I001","data":{"fix":{"applicability":"Automatic","edits":[{"content":"import os\nimport sys\n\n\n","end_location":{"column":0,"row":3},"location":{"column":0,"row":1}}],"message":"Organize imports"},"noqa_row":1},"message":"Import block is un-sorted or un-formatted","range":{"end":{"character":0,"line":2},"start":{"character":0,"line":0}},"severity":2,"source":"Ruff"}],"edit":{"documentChanges":[{"edits":[{"newText":"def f():\n    pass\n","range":{"end":{"character":0,"line":2147483647},"start":{"character":0,"line":0}}}],"textDocument":{"uri":"file:///tmp/ruff/test.py","version":0}}]},"kind":"source.fixAll","title":"Ruff: Fix All"},{"data":"file:///tmp/ruff/test.py","diagnostics":[{"code":"I001","data":{"fix":{"applicability":"Automatic","edits":[{"content":"import os\nimport sys\n\n\n","end_location":{"column":0,"row":3},"location":{"column":0,"row":1}}],"message":"Organize imports"},"noqa_row":1},"message":"Import block is un-sorted or un-formatted","range":{"end":{"character":0,"line":2},"start":{"character":0,"line":0}},"severity":2,"source":"Ruff"}],"edit":{"documentChanges":[{"edits":[{"newText":"import os\nimport sys\n\n\n","range":{"end":{"character":0,"line":2},"start":{"character":0,"line":0}}}],"textDocument":{"uri":"file:///tmp/ruff/test.py","version":0}}]},"kind":"quickfix","title":"Ruff (I001): Organize imports"},{"data":"file:///tmp/ruff/test.py","diagnostics":[{"code":"I001","data":{"fix":{"applicability":"Automatic","edits":[{"content":"import os\nimport sys\n\n\n","end_location":{"column":0,"row":3},"location":{"column":0,"row":1}}],"message":"Organize imports"},"noqa_row":1},"message":"Import block is un-sorted or un-formatted","range":{"end":{"character":0,"line":2},"start":{"character":0,"line":0}},"severity":2,"source":"Ruff"}],"edit":{"documentChanges":[{"edits":[{"newText":"import os  # noqa: I001","range":{"end":{"character":9,"line":0},"start":{"character":0,"line":0}}}],"textDocument":{"uri":"file:///tmp/ruff/test.py","version":0}}]},"kind":"quickfix","title":"Ruff (I001): Disable for this line"}]
2023-09-27T22:25:45.863 helix_term::commands::lsp [DEBUG] code action: CodeAction { title: "Ruff: Organize Imports", kind: Some(CodeActionKind("source.organizeImports")), diagnostics: Some([]), edit: Some(WorkspaceEdit { changes: None, document_changes: Some(Edits([TextDocumentEdit { text_document: OptionalVersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/tmp/ruff/test.py", query: None, fragment: None }, version: Some(0) }, edits: [Left(TextEdit { range: Range { start: Position { line: 0, character: 0 }, end: Position { line: 2147483647, character: 0 } }, new_text: "import os\nimport sys\n\n\ndef f():\n    x = 1\n" })] }])), change_annotations: None }), command: None, is_preferred: None, disabled: None, data: Some(String("file:///tmp/ruff/test.py")) }
2023-09-27T22:25:45.863 helix_term::commands::lsp [DEBUG] edit: WorkspaceEdit { changes: None, document_changes: Some(Edits([TextDocumentEdit { text_document: OptionalVersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/tmp/ruff/test.py", query: None, fragment: None }, version: Some(0) }, edits: [Left(TextEdit { range: Range { start: Position { line: 0, character: 0 }, end: Position { line: 2147483647, character: 0 } }, new_text: "import os\nimport sys\n\n\ndef f():\n    x = 1\n" })] }])), change_annotations: None }
2023-09-27T22:25:45.863 helix_lsp::util [WARN] LSP position Position { line: 2147483647, character: 0 } out of range assuming EOF
2023-09-27T22:25:45.863 helix_lsp::transport [INFO] -> {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"contentChanges":[{"range":{"end":{"character":0,"line":2},"start":{"character":0,"line":2}},"text":"\n\n"}],"textDocument":{"uri":"file:///tmp/ruff/test.py","version":1}}}
2023-09-27T22:25:45.869 helix_lsp::transport [INFO] <- {"params": {"type": 4, "message": "Using interpreter executable: /home/joffrey/.local/pipx/venvs/ruff-lsp/bin/ruff"}, "method": "window/logMessage", "jsonrpc": "2.0"}
2023-09-27T22:25:45.869 helix_lsp::transport [INFO] <- {"params": {"type": 4, "message": "Running Ruff with: /home/joffrey/.local/pipx/venvs/ruff-lsp/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--format', 'json', '-', '--stdin-filename', '/tmp/ruff/test.py']"}, "method": "window/logMessage", "jsonrpc": "2.0"}
2023-09-27T22:25:45.869 helix_term::application [DEBUG] received editor event: LanguageServerMessage((0, Notification(Notification { jsonrpc: Some(V2), method: "window/logMessage", params: Map({"message": String("Using interpreter executable: /home/joffrey/.local/pipx/venvs/ruff-lsp/bin/ruff"), "type": Number(4)}) })))
2023-09-27T22:25:45.869 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Log, message: "Using interpreter executable: /home/joffrey/.local/pipx/venvs/ruff-lsp/bin/ruff" }
2023-09-27T22:25:45.870 helix_term::application [DEBUG] received editor event: LanguageServerMessage((0, Notification(Notification { jsonrpc: Some(V2), method: "window/logMessage", params: Map({"message": String("Running Ruff with: /home/joffrey/.local/pipx/venvs/ruff-lsp/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--format', 'json', '-', '--stdin-filename', '/tmp/ruff/test.py']"), "type": Number(4)}) })))
2023-09-27T22:25:45.870 helix_term::application [INFO] window/logMessage: LogMessageParams { typ: Log, message: "Running Ruff with: /home/joffrey/.local/pipx/venvs/ruff-lsp/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--format', 'json', '-', '--stdin-filename', '/tmp/ruff/test.py']" }
2023-09-27T22:25:45.885 helix_lsp::transport [INFO] <- {"params": {"uri": "file:///tmp/ruff/test.py", "diagnostics": [{"range": {"start": {"line": 0, "character": 7}, "end": {"line": 0, "character": 9}}, "message": "`os` imported but unused", "severity": 2, "code": "F401", "codeDescription": {"href": "https://beta.ruff.rs/docs/rules/unused-import"}, "source": "Ruff", "tags": [1], "data": {"fix": {"applicability": "Automatic", "edits": [{"content": "", "end_location": {"column": 0, "row": 2}, "location": {"column": 0, "row": 1}}], "message": "Remove unused import: `os`"}, "noqa_row": 1}}, {"range": {"start": {"line": 1, "character": 7}, "end": {"line"
: 1, "character": 10}}, "message": "`sys` imported but unused", "severity": 2, "code": "F401", "codeDescription": {"href": "https://beta.ruff.rs/docs/rules/unused-import"}, "source": "Ruff", "tags": [1], "data": {"fix": {"applicability": "Automatic", "edits": [{"content": "", "end_location": {"column": 0, "row": 3}, "location": {"column": 0, "row": 2}}], "message": "Remove unused import: `sys`"}, "noqa_row": 2}}, {"range": {"start": {"line": 5, "character": 4}, "end": {"line": 5, "character": 5}}, "message": "Local variable `x` is assigned to but never used", "severity": 2, "code": "F841", "codeDescription": {"href": "https://beta.ruff.rs/docs/rules/unused-variable"}, "source": "Ruff", "tags": [1], "data": {"fix": {"applicability": "Suggested", "edits": [{"content": "pass", "end_location": {"column": 9, "row": 6}, "location": {"column": 4, "row": 6}}], "message": "Remove assignment to unused variable `x`"}, "noqa_row": 6}}]}, "method": "textDocument/publishDiagnostics", "jsonrpc": "2.0"}
2023-09-27T22:25:45.885 helix_term::application [DEBUG] received editor event: LanguageServerMessage((0, Notification(Notification { jsonrpc: Some(V2), method: "textDocument/publishDiagnostics", params: Map({"diagnostics": Array [Object {"code": String("F401"), "codeDescription": Object {"href": String("https://beta.ruff.rs/docs/rules/unused-import")}, "data": Object {"fix": Object {"applicability": String("Automatic"), "edits": Array [Object {"content": String(""), "end_location": Object {"column": Number(0), "row": Number(2)}, "location": Object {"column": Number(0), "row": Number(1)}}], "message": String("Remove unused import: `os`")}, "noqa_row": Number(1)}, "message": String("`os` imported but unused"), "range": Object {"end": Object {"character": Number(9), "line": Number(0)}, "start": Object {"character": Number(7), "line": Number(0)}}, "severity": Number(2), "source": String("Ruff"), "tags": Array [Number(1)]}, Object {"code": String("F401"), "codeDescription": Object {"href": String("https://beta.ruff.rs/docs/rules/unused-import")}, "data": Object {"fix": Object {"applicability": String("Automatic"), "edits": Array [Object {"content": String(""), "end_location": Object {"column": Number(0), "row": Number(3)}, "location": Object {"column": Number(0), "row": Number(2)}}], "message": String("Remove unused import: `sys`")}, "noqa_row": Number(2)}, "message": String("`sys` imported but unused"), "range": Object {"end": Object {"character": Number(10), "line": Number(1)}, "start": Object {"character": Number(7), "line": Number(1)}}, "severity": Number(2), "source": String("Ruff"), "tags": Array [Number(1)]}, Object {"code": String("F841"), "codeDescription": Object {"href": String("https://beta.ruff.rs/docs/rules/unused-variable")}, "data": Object {"fix": Object {"applicability": String("Suggested"), "edits": Array [Object {"content": String("pass"), "end_location": Object {"column": Number(9), "row": Number(6)}, "location": Object {"column": Number(4), "row": Number(6)}}], "message": String("Remove assignment to unused variable `x`")}, "noqa_row": Number(6)}, "message": String("Local variable `x` is assigned to but never used"), "range": Object {"end": Object {"character": Number(5), "line": Number(5)}, "start": Object {"character": Number(4), "line": Number(5)}}, "severity": Number(2), "source": String("Ruff"), "tags": Array [Number(1)]}], "uri": String("file:///tmp/ruff/test.py")}) })))

Platform

Linux

Terminal Emulator

kitty 0.29.2

Helix Version

helix 23.05-450-gba063714

@bluthej bluthej added the C-bug Category: This is a bug label Sep 27, 2023
@kirawi
Copy link
Member

kirawi commented Sep 27, 2023

How are you selecting it? #5118 may have changed the behavior.

@bluthej
Copy link
Author

bluthej commented Sep 27, 2023

I'm using tab to select and then press enter (is that what you meant?)

@hakan-demirli

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants