Repository navigation
Unexpected relative path handling in native server mode #16041
Description
Activity
Do you have any other VS Code settings? For example, any related to
ruff.*.And, can you try setting the log level to debug as stated here and provide all the logs?
By highlighting, do you meant syntax highlighting or that ruff doesn't show any warnings or errors in the editor?
Thanks for the suggestions - having increased the log level I now have an idea what the problem is (see below).
By highlighting, do you meant syntax highlighting or that ruff doesn't show any warnings or errors in the editor?
I mean no warnings or errors ("squiggly underlines").
Do you have any other VS Code settings? For example, any related to ruff.*.
None to affect this, mainly
python.analysisandpython.testing.And, can you try setting the log level to debug
Thanks, I'd found the
ruff.trace.serversetting but not theruff.logLevelsetting - this one had the messages I needed.The problem
I think the difference in behaviour between LSP and native server relates to relative path handling in the
excludesetting. I had a relative directory namedplayconfigured to exclude, and by coincidence (or perhaps because I play a lot 😀) the repo itself lives some levels below a directory also calledplay.Below are some logs, both while running with native server on. Note that the
pyproject.tomlis in the root repo directory calledpolebot(full repo is here).The first is with setting
exclude = ["play"]:8848.627385916s DEBUG ThreadId(106) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Users/[me]/dev/play/bwcc/bwcc-clan/polebot/play 8848.638075750s DEBUG ruff:worker:4 ruff_server::resolve: Ignored path via `exclude`: /Users/[me]/dev/play/bwcc/bwcc-clan/polebot/src/utils/log_tools.pyIf the setting is
exclude = ["./play"]then it behaves as I would expect:8449.275811916s DEBUG ThreadId(94) ruff_server::session::index::ruff_settings: Ignored path via `exclude`: /Users/[me]/dev/play/bwcc/bwcc-clan/polebot/play 8449.285933083s DEBUG ruff:worker:3 ruff_server::resolve: Included path via `include`: /Users/[me]/dev/play/bwcc/bwcc-clan/polebot/src/utils/log_tools.pyIs it a bug?
Note that the first
playdirectory in the path is above thepyproject.tomland therefore, by my understanding of the docs, should be ignored in the context of relative path handling. The secondplaydirectory (in the first log entry in both examples above) is excluded in both cases, as expected because it's below the repo root directory.I would argue that this is a bug, for a few reasons:
-
Any part of a file path that is above the directory containing the config file should be ignored in the context of relative path handling.
-
The current behaviour within the editor is different from the behaviour when running
ruff checkfrom the command line. -
The current behaviour of the native server is different from how it works in the LSP, in this case effectively turning Ruff off for the entire repo.
-
- changed the title
[-]Ruff not highlighting in native server mode[/-][+]Unexpected relative path handling in native server mode[/+]on Feb 8, 2025 Oh nice find. I'm curious, what ruff version are you using?
what ruff version are you using?
0.9.5
Oh, great find. Thank you for debugging. This seems like a bug.
- addedbugAn issue describing something that isn't working, or a PR that fixes a bugAn issue describing something that isn't working, or a PR that fixes a bugserverRelated to the Ruff or ty LSP serverRelated to the Ruff or ty LSP server
on Feb 8, 2025 - linked a pull request that will close this issueRoot exclusions in the server to project root #16043
on Feb 10, 2025 - added a commit that references this issue
on Feb 10, 2025
[Edit - see my comment below for problem description]
I just had a notification that ruff-lsp is deprecated, so I removed my setting
"ruff.nativeServer": "off". Now, I don't get any highlighting in Python documents, however when I runpoetry run ruff checkit lists violations.When native server is enabled, I've checked the logs and can't see any obvious suggestions as to why nothing gets highlighted. In the Ruff output window, it displays
Server: Start requested.and nothing more. In the Ruff Language Server output window it displaysmultiple times.
If I switch back to
"ruff.nativeServer": "off"then the highlighting is restored.The related settings in
settings.jsonare: