astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.5k stars 1.08k forks source link

Error on Neovim after upgrading to 0.6.3 #13238

Closed Zeioth closed 1 month ago

Zeioth commented 2 months ago

Description

Ruff displays errors on neovim (installed using)

Screenshot

screenshot_2024-09-04_09-17-36_480641034

screenshot_2024-09-04_09-18-48_932678326

LSP Log

[START][2024-09-04 09:14:29] LSP logging initiated
[ERROR][2024-09-04 09:14:29] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"    'Cancel notification for unknown message id "2"\n'
[START][2024-09-04 09:14:36] LSP logging initiated
[ERROR][2024-09-04 09:14:36] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"    'Cancel notification for unknown message id "2"\n'
[ERROR][2024-09-04 09:15:27] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"    'Cancel notification for unknown message id "3"\n'
[ERROR][2024-09-04 09:15:28] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"    'Cancel notification for unknown message id "4"\n'
Zeioth commented 2 months ago

also, my ruff-lsp version

screenshot_2024-09-04_09-21-14_744180110

MichaReiser commented 2 months ago

Closing as duplicate of https://github.com/astral-sh/ruff-lsp/issues/486

dhruvmanila commented 2 months ago

Let's keep this open as the notification is coming from the native server.

Can you try removing ruff_lsp and only running the native server? It's not recommended to use both at the same time.

dhruvmanila commented 2 months ago

Can you also check the logs via :LspLog and check if there's any error message present there? I think you'll need to turn on the server tracing like so:

require('lspconfig').ruff.setup({
  trace = 'messages',
  init_options = {
    settings = {
      logLevel = 'debug',
    },
  },
})
dhruvmanila commented 2 months ago

Sorry, I didn't notice the logs that you've provided. That doesn't contain anything relevant, you'll need to turn on server tracing via the config that I've provided in my previous comment.

Zeioth commented 1 month ago

The issue is on ruff itself, so the workaround on my end has been using ruff-lsp + pywright.

MichaReiser commented 1 month ago

@Zeioth please stop opening and closing this issue unnecessarily because it triggers a notification for everyone observing the repository.

To get this resolved, please provide us with the log that @dhruvmanila asked you for. It's very difficult to help you without it.

Zeioth commented 1 month ago

@MichaReiser @dhruvmanila Here is the log generated by

Process followed to generate the log file

log file (when opening a python file and pass the cursor over lines)

[START][2024-09-21 12:42:58] LSP logging initiated
[ERROR][2024-09-21 12:42:58] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff" "stderr"    "   0.000011050s  WARN main ruff_server::server: No workspace(s) were provided during initialization. Using the current working directory as a default workspace...\n"
[ERROR][2024-09-21 12:42:59] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff" "stderr"    "   0.012430178s  WARN ruff:main ruff_server::server: LSP client does not support dynamic capability registration - automatic configuration reloading will not be available.\n"
[ERROR][2024-09-21 12:43:01] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"    'Cancel notification for unknown message id "2"\n'
[ERROR][2024-09-21 12:43:01] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"    'Cancel notification for unknown message id "3"\n'
[ERROR][2024-09-21 12:43:57] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"    'Cancel notification for unknown message id "27"\n'

log file (when lsp autocomplete is triggered)

[ERROR][2024-09-21 12:53:47] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff" "stderr"    " 424.907668433s DEBUG  ruff:worker:5 ruff_server::resolve: Included path via `include`: /home/zeioth/raven-app/src/utils/controller.py\n"
[ERROR][2024-09-21 12:53:47] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"    'Cancel notification for unknown message id "103"\n'
[ERROR][2024-09-21 12:53:47] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff" "stderr"    " 425.022634237s ERROR  ruff:worker:8 ruff_server::server::api: An error occurred with result ID 73: failed to deserialize diagnostic data: invalid length 0, expected struct AssociatedDiagnosticData with 4 elements\n"
[ERROR][2024-09-21 12:53:47] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"    "Exception occurred for message \"104\": AttributeError: 'NoneType' object has no attribute 'get'\nTraceback (most recent call last):\n  File \"/home/zeioth/.local/share/nvim/mason/packages/ruff-lsp/venv/lib/python3.12/site-packages/pygls/protocol/json_rpc.py\", line 194, in _execute_request_callback\n    self._send_response(msg_id, result=future.result())\n                                       ^^^^^^^^^^^^^^^\n  File \"/home/zeioth/.local/share/nvim/mason/packages/ruff-lsp/venv/lib/python3.12/site-packages/ruff_lsp/server.py\", line 992, in code_action\n    fix = cast(DiagnosticData, diagnostic.data).get(\"fix\")\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nAttributeError: 'NoneType' object has no attribute 'get'\n"
[ERROR][2024-09-21 12:53:47] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff" "stderr"    " 425.084355442s DEBUG  ruff:worker:4 ruff_server::resolve: Included path via `include`: /home/zeioth/raven-app/src/utils/controller.py\n"
[ERROR][2024-09-21 12:53:47] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff" "stderr"    " 425.092566072s DEBUG  ruff:worker:9 ruff_server::resolve: Included path via `include`: /home/zeioth/raven-app/src/utils/controller.py\n"
[ERROR][2024-09-21 12:53:47] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff" "stderr"    " 425.277145226s DEBUG ruff:worker:10 ruff_server::resolve: Included path via `include`: /home/zeioth/raven-app/src/utils/controller.py\n"
[ERROR][2024-09-21 12:53:47] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff" "stderr"    " 425.707603056s DEBUG ruff:worker:11 ruff_server::resolve: Included path via `include`: /home/zeioth/raven-app/src/utils/controller.py\n"
[ERROR][2024-09-21 12:53:50] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"    'Cancel notification for unknown message id "105"\n'
[ERROR][2024-09-21 12:53:52] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"    'Cancel notification for unknown message id "106"\n'

More info

Might be a problem in the package itself?

MichaReiser commented 1 month ago

Thanks for sharing the logs. From the logs, it seems you're running both ruff-lsp and ruff (server) at the same time. This is not a supported setup and shouldn't be needed. Can you try to remove ruff-lsp and only use ruff server?

[ERROR][2024-09-21 12:53:47] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff" "stderr"    " 425.022634237s ERROR  ruff:worker:8 ruff_server::server::api: An error occurred with result ID 73: failed to deserialize diagnostic data: invalid length 0, expected struct AssociatedDiagnosticData with 4 elements\n"
[ERROR][2024-09-21 12:53:47] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff-lsp" "stderr"
Zeioth commented 1 month ago

@MichaReiser I've tried with ruff alone. Now I only get this error when I trigger lsp autocomplete (which doesn't work). Linting work as expected.

[ERROR][2024-09-22 15:19:50] .../vim/lsp/rpc.lua:770    "rpc"   "/home/zeioth/.local/share/nvim/mason/bin/ruff" "stderr"    "  59.355577387s DEBUG ruff:worker:16 ruff_server::resolve: Included path via `include`: /home/zeioth/raven-app/src/main.py\n"

Because you say using both ruffs at the same time is not supported, I understand ruff-lsp is already included inside ruff, and lsp autocompletion should be working fine?

MichaReiser commented 1 month ago

What you're seeing there isn't an error. It's only a debug message. I think you can turn it of again by removing the logInfo setting

ruff, and lsp autocompletion should be working fine

Ruff's LSP doesn't provide any auto completion. It only provides formatting and linting capabilities.

Zeioth commented 1 month ago

Got it. Thank you. I think we can close this for now then.