vscode-ruff icon indicating copy to clipboard operation
vscode-ruff copied to clipboard

Sometimes can't find Ruff settings for files outiside of workspace when using native server. Works ok with Python-based server.

Open DareDevilDenis opened this issue 4 months ago • 1 comments

Firstly, thanks for providing the VSCode Ruff extension. It's great!

My issue:

Ruff version: 2025.26.0 VS Code version: 1.104.0

If I have a workspace open in VSCode and then open a file outside of the workspace, often that file fails to find the Ruff settings, giving error:

2025-09-17 15:12:58.584689000 WARN No settings available for file:///c%3A/Users/vincluff/Documents/_DOCS/my_script_outside_of_workspace.py - falling back to default settings

My file structure:

C:\.ruff.toml
C:\repos\my_app\.ruff.toml
C:\repos\my_app\Source\my_module_in_workspace.py
C:\Users\vincluff\Documents\_DOCS\my_script_outside_of_workspace.py

Both .ruff.toml files contain:

extend-select = ["A", "ANN", "ARG", "B", "C", "D", "D401", "D404", "E", "FURB", "G", "INT", "LOG", "N", "PERF", "PL", "PTH", "RET", "RUF", "SIM", "TID", "Q", "W"]
line-length = 120

[lint.pydocstyle]
convention = "google"

my_module_in_workspace.py and my_script_outside_of_workspace.py contain: print("hello")

In VSCode I open workspace C:\repos\my_app\Source and then open my_script_outside_of_workspace.py. No linting is performed on the file (I should get a yellow squiggly for D100) and I get the error: 2025-09-17 15:12:58.584689000 WARN No settings available for file:///c%3A/Users/vincluff/Documents/_DOCS/my_script_outside_of_workspace.py - falling back to default settings

If I set "ruff.nativeServer": "off" it works fine.

Interestingly, if I copy my_script_outside_of_workspace.py to C:\temp I don't get error "WARN No settings available..." but it still doesn't perform any linting.

This sounds quite similar to https://github.com/astral-sh/ruff-vscode/issues/713 I'm happy to provide further information and to help debug if needed.

Ruff language server output:

2025-09-17 15:17:46.434795800  WARN The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `c:\repos\my_app\.ruff.toml`:
  - 'extend-select' -> 'lint.extend-select' log.target="ruff_workspace::configuration" log.module_path="ruff_workspace::configuration" log.file="crates\\ruff_workspace\\src\\configuration.rs" log.line=1604
2025-09-17 15:17:46.442972500  INFO Registering workspace: c:\repos\my_app\Source
2025-09-17 15:17:46.444314100  INFO Configuration file watcher successfully registered
2025-09-17 15:18:04.103688500  WARN No settings available for file:///c%3A/Users/vincluff/Documents/_DOCS/my_script_outside_of_workspace.py - falling back to default settings
2025-09-17 15:18:04.107856100  WARN No settings available for file:///c%3A/Users/vincluff/Documents/_DOCS/my_script_outside_of_workspace.py - falling back to default settings

My settings.json:

{
    "git.openRepositoryInParentFolders": "never",
    "security.workspace.trust.untrustedFiles": "open",
    "security.workspace.trust.enabled": false,

    // RUNNING VIA DEBUGGER
    "launch": {
        "configurations": [
            {
                "name": "Python: Current File",
                "type": "debugpy",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "justMyCode": false,
                "cwd": "${fileDirname}",  // https://stackoverflow.com/questions/38623138/how-to-set-the-working-directory-for-debugging-a-python-program-in-vs-code
                "env": {"PYTHONPATH": "${workspaceFolder}${pathSeparator}${env:PYTHONPATH}"},  // Set this if you want to use a workspace
            }
        ],
        "compounds": []
    },

    // RUNNING TERMINAL
    "terminal.integrated.env.windows": {"PYTHONPATH": "${workspaceFolder}${pathSeparator}${env:PYTHONPATH}"},

    "workbench.startupEditor": "none",
    "[python]": {
        "editor.defaultFormatter": "charliermarsh.ruff"
    },
    "editor.detectIndentation": false,
    "editor.minimap.enabled": false,
    "python.languageServer": "Pylance",
    "debug.terminal.clearBeforeReusing": true,
    "python.analysis.typeCheckingMode": "basic",
    "workbench.editor.showTabs": "none",
    "window.restoreWindows": "none",
    "window.confirmSaveUntitledWorkspace": false,
    "workbench.editor.empty.hint": "hidden",
    "python.defaultInterpreterPath": "C:\\Program Files\\Python313\\python.exe",
    "explorer.openEditors.sortOrder": "alphabetical",
    "ruff.format.preview": false,
    "ruff.nativeServer": "on",
}

DareDevilDenis avatar Sep 17 '25 14:09 DareDevilDenis

Thanks for the report! @dhruvmanila or @MichaReiser might have a better idea of the root cause than I do, but I was able to reproduce this. I created a project in a temporary directory in /tmp:

tree .
.
└── myproject
    ├── README.md
    ├── main.py
    └── pyproject.toml

main.py

match 42:
    case x:
        ...

pyproject.toml

[project]
name = "myproject"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = []

[tool.ruff]
target-version = "py310"

I chose a syntax error (match before 3.10) just for convenience.

If I open the myproject directory in VS Code, I don't get any diagnostics, as expected.

Separately, I created a script and ruff.toml in ~/tmp/elsewhere:

script.py

match 42:
    case x: ...

ruff.toml

target-version = "py39"

Checking this in that directory results in a diagnostic, as expected:

> ruff check . --output-format concise
script.py:1:1: invalid-syntax: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)
Found 1 error.

VS Code also shows an error when I run code . in that directory.


However, in line with the reported issue, if I first open myproject and only then open script.py, I don't see any diagnostics. At first I thought this meant the workspace configuration was still being used, but if I add another syntax error to both main.py and script.py:

v[*x]  # starred subscripts aren't allowed on 3.10 either

I only see an error in myproject/main.py, which means script.py is falling back to the default latest Python version rather than the workspace setting.

ntBre avatar Sep 19 '25 16:09 ntBre