Skip to content

Unexpected relative path handling in native server mode #16041

Description

@richtea

[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 run poetry run ruff check it 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 displays

WARN ruff:main ruff_server::server::api: Received notification $/setTrace which does not have a handler.

multiple times.

If I switch back to "ruff.nativeServer": "off" then the highlighting is restored.

The related settings in settings.json are:

  "[python]": {
    "editor.defaultFormatter": "charliermarsh.ruff",
    "editor.codeActionsOnSave": {
      "source.fixAll": "never",
      "source.organizeImports": "never",
      "source.organizeImports.ruff": "always"
    },
    "editor.insertSpaces": true,
    "editor.formatOnSave": false,
    "editor.formatOnPaste": true,
    "editor.formatOnType": false
  },

Activity

  1. dhruvmanila commented on Feb 8, 2025

    @dhruvmanila
    Member

    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?

  2. MichaReiser commented on Feb 8, 2025

    @MichaReiser
    Member

    By highlighting, do you meant syntax highlighting or that ruff doesn't show any warnings or errors in the editor?

  3. richtea commented on Feb 8, 2025

    @richtea
    Author

    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.analysis and python.testing.

    And, can you try setting the log level to debug

    Thanks, I'd found the ruff.trace.server setting but not the ruff.logLevel setting - 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 exclude setting. I had a relative directory named play configured to exclude, and by coincidence (or perhaps because I play a lot 😀) the repo itself lives some levels below a directory also called play.

    Below are some logs, both while running with native server on. Note that the pyproject.toml is in the root repo directory called polebot (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.py
    

    If 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.py
    

    Is it a bug?

    Note that the first play directory in the path is above the pyproject.toml and therefore, by my understanding of the docs, should be ignored in the context of relative path handling. The second play directory (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:

    1. 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.

    2. The current behaviour within the editor is different from the behaviour when running ruff check from the command line.

    3. 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.

  4. changed the title [-]Ruff not highlighting in native server mode[/-] [+]Unexpected relative path handling in native server mode[/+] on Feb 8, 2025
  5. MichaReiser commented on Feb 8, 2025

    @MichaReiser
    Member

    Oh nice find. I'm curious, what ruff version are you using?

  6. richtea commented on Feb 8, 2025

    @richtea
    Author

    what ruff version are you using?

    0.9.5

  7. dhruvmanila commented on Feb 8, 2025

    @dhruvmanila
    Member

    Oh, great find. Thank you for debugging. This seems like a bug.

  8. added
    bugAn issue describing something that isn't working, or a PR that fixes a bug
    serverRelated to the Ruff or ty LSP server
    on Feb 8, 2025
  9. added a commit that references this issue on Feb 10, 2025
    869a954
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn issue describing something that isn't working, or a PR that fixes a bugserverRelated to the Ruff or ty LSP server

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions