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

Excludes match against parent directories outside of the project when formatting through the language server #16282

Open
kageurufu opened this issue Feb 20, 2025 · 3 comments
Labels
bug Something isn't working server Related to the LSP server

Comments

@kageurufu
Copy link

Description

Non-relative paths in ruff.exclude match against parent directories outside of the project.

My working path is $HOME/src/<project>/ and with tool.ruff.extend-exclude = ['src'] set the ruff language server will not format any python within ~/src/project/.
Calling ruff format on the command line works normally.

  • Version: Ruff 0.9.7
  • Minimal snippet
    mkdir -p ~/src
    uv init ~/src/test-ruff-exclude
    cd ~/src/test-ruff-exclude
    echo 'exclude = ["src"]' >> ruff.toml
    
  • Invoked using the VSCode ruff extension, however any lsp integration could trigger this
  • Keywords searched: "exclude", "directory"

LSP Trace:

[Trace - 10:16:19 AM] Sending request 'textDocument/formatting - (28)'.
Params: {
    "textDocument": {
        "uri": "file:///home/frank/src/ruff-exclude-ex/hello.py"
    },
    "options": {
        "tabSize": 4,
        "insertSpaces": true
    }
}


[Trace - 10:16:19 AM] Received response 'textDocument/formatting - (28)' in 0ms.
No result returned.
@dylwil3 dylwil3 added server Related to the LSP server bug Something isn't working labels Feb 20, 2025
@MichaReiser
Copy link
Member

I'm not sure I follow. Let me explain what I understand:

  • You open the $HOME/src/project directory in VS code
  • The ruff.toml in the src directory contains exclude = ["src"]
  • You run ruff in $HOME/src/project and it formats all files in that directory except the files in `src
  • VS Code doesn't format the files because it incorrectly thinks that the exclude src matches $HOME/src

Is this accurate?

@kageurufu
Copy link
Author

Yes, exactly.

I believe the language server is not detecting the project root

@MichaReiser
Copy link
Member

@dhruvmanila is our LSP expert. I wonder if we incorrectly anchor exclude (or not anchor it at all)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Related to the LSP server
Projects
None yet
Development

No branches or pull requests

3 participants