astral-sh/ruff

`implicit-namespace-package` (`INP001`) - error is not reported in the language server when a package is nested inside an implicit namespace package

Opened this issue · 2 comments

the scenario covered by #14236 seems to work in the CLI, but the error is not reported in vscode.

i'm not sure if this is an issue with the vscode extension or the language server, but the language server seems to not be sending any diagnostics so i assume that's where the issue is.

i'm using the same version of ruff in both the CLI and the vscode extension: 0.8.1

project structure

foo/
├── __init__.py
└── bar/
    └── baz/
        └── __init__.py

cli output

> ruff check --no-cache foo
foo\bar\baz\__init__.py:1:1: INP001 File `foo\bar\baz\__init__.py` declares a package, but is nested under an implicit namespace package. Add an `__init__.py` to `foo\bar`.
Found 1 error.

vscode output

Image

2024-12-03 20:47:55.022 [info] [Trace - 8:47:55 PM] Sending request 'textDocument/diagnostic - (175)'.
2024-12-03 20:47:55.022 [info] Params: {
    "identifier": "Ruff",
    "textDocument": {
        "uri": "file:///c%3A/Users/user/project/foo/bar/baz/__init__.py"
    }
}


2024-12-03 20:47:55.028 [info] [Trace - 8:47:55 PM] Received response 'textDocument/diagnostic - (175)' in 6ms.
2024-12-03 20:47:55.028 [info] Result: {
    "items": [],
    "kind": "full"
}

Let me look into it. Can you provide the Ruff config file (if any) and the VS Code extension settings that's being used here?

Yeah, this seems like a bug as we never account for the nested package root when checking from the server side:

detect_package_root(
document_path
.parent()
.expect("a path to a document should have a parent path"),
&linter_settings.namespace_packages,
)
.map(PackageRoot::root)

I'll need to look into the original change to understand where PackageRoot::Nested is being constructed.