pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

`src` seems to be ignored by default

Open Tinche opened this issue 3 years ago • 9 comments

Environment data

  • Language Server version: 2022.9.20 (pyright 95c059fa)
  • OS and version: macOS Monterey
  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.5

Repro Steps

I've recently noticed VS Code isn't indexing my Python files properly - find usages and workspace symbol search aren't working. My code is inside a src directory.

Looking at the logs, I see:

[Info  - 3:50:40 PM] (7229) Pylance language server 2022.9.20 (pyright 95c059fa) starting
[Info  - 3:50:40 PM] (7229) Server root directory: /Users/tintvrtkovic/.vscode/extensions/ms-python.vscode-pylance-2022.9.20/dist
[Info  - 3:50:40 PM] (7229) Starting service instance "user-service"
[Info  - 3:50:40 PM] (7229) Notebook support: Legacy
[Info  - 3:50:40 PM] (7229) Interactive window support: Legacy
[Info  - 3:50:40 PM] (7229) No configuration file found.
[Info  - 3:50:40 PM] (7229) pyproject.toml file found at /Users/tintvrtkovic/hr/user-service.
[Info  - 3:50:40 PM] (7229) Setting pythonPath for service "user-service": "/Users/tintvrtkovic/hr/user-service/.venv/bin/python"
[Info  - 3:50:40 PM] (7229) Loading pyproject.toml file at /Users/tintvrtkovic/hr/user-service/pyproject.toml
[Error - 3:50:40 PM] (7229) Pyproject file "/Users/tintvrtkovic/hr/user-service/pyproject.toml" is missing "[tool.pyright]" section.
[Info  - 3:50:40 PM] (7229) Assuming Python version 3.10
[Info  - 3:50:40 PM] (7229) Assuming Python platform Darwin
[Info  - 3:50:40 PM] (7229) Searching for source files
[Info  - 3:50:40 PM] (7229) No source files found.

If I add the directory manually to python.analysis.include, I see:

[Info  - 4:07:30 PM] (7229) Searching for source files
[Info  - 4:07:30 PM] (7229) Found 85 source files

and "Show references" starts working. This used to work before out of the box, so I'm assuming src isn't being scanned by default any more? The docs seem to imply it should be.

Tinche avatar Sep 16 '22 14:09 Tinche

@Tinche, any chance you have set:

"python.analysis.diagnosticMode": "workspace",

Wondering if you might be seeing #3343.

debonte avatar Sep 16 '22 19:09 debonte

Negative, my global and workspace settings do not reference that key :(

Tinche avatar Sep 16 '22 19:09 Tinche

Ok, and I'm assuming you don't have python.analysis.autoSearchPaths set to false, since I believe it's the docs for that config setting that you were referring to when you said, "The docs seem to imply it should be."

Is there an __init__.py in your src directory?

If not, could you set "python.analysis.logLevel": "Trace", restart Pylance, and then provide a new "Python Language Server" log?

debonte avatar Sep 16 '22 20:09 debonte

Oh, interesting, my src does not have an __init__.py. We're using namespace packages since some other code is in the same package, but another directory.

Here's the full log with logLevel: Trace:

[Info  - 10:10:16 PM] (10062) Pylance language server 2022.9.20 (pyright 95c059fa) starting
[Info  - 10:10:16 PM] (10062) Server root directory: /Users/tintvrtkovic/.vscode/extensions/ms-python.vscode-pylance-2022.9.20/dist
[Info  - 10:10:16 PM] (10062) Starting service instance "user-service"
[Info  - 10:10:16 PM] (10062) Notebook support: Legacy
[Info  - 10:10:16 PM] (10062) Interactive window support: Legacy
[Info  - 10:10:16 PM] (10062) No configuration file found.
[Info  - 10:10:16 PM] (10062) pyproject.toml file found at /Users/tintvrtkovic/hr/user-service.
[Info  - 10:10:16 PM] (10062) Setting pythonPath for service "user-service": "/Users/tintvrtkovic/hr/user-service/.venv/bin/python"
[Info  - 10:10:16 PM] (10062) Loading pyproject.toml file at /Users/tintvrtkovic/hr/user-service/pyproject.toml
[Error - 10:10:16 PM] (10062) Pyproject file "/Users/tintvrtkovic/hr/user-service/pyproject.toml" is missing "[tool.pyright]" section.
[Info  - 10:10:16 PM] (10062) Assuming Python version 3.10
[Info  - 10:10:16 PM] (10062) Assuming Python platform Darwin
[Info  - 10:10:17 PM] (10062) Search paths for /Users/tintvrtkovic/hr/user-service
[Info  - 10:10:17 PM] (10062)   /Users/tintvrtkovic/.vscode/extensions/ms-python.vscode-pylance-2022.9.20/dist/typeshed-fallback/stdlib
[Info  - 10:10:17 PM] (10062)   /Users/tintvrtkovic/hr/user-service
[Info  - 10:10:17 PM] (10062)   /Users/tintvrtkovic/hr/user-service/src
[Info  - 10:10:17 PM] (10062)   /Users/tintvrtkovic/hr/user-service/typings
[Info  - 10:10:17 PM] (10062)   /Users/tintvrtkovic/.vscode/extensions/ms-python.vscode-pylance-2022.9.20/dist/typeshed-fallback/stubs/...
[Info  - 10:10:17 PM] (10062)   /Users/tintvrtkovic/.vscode/extensions/ms-python.vscode-pylance-2022.9.20/dist/bundled/stubs
[Info  - 10:10:17 PM] (10062)   /Users/tintvrtkovic/.asdf/installs/python/3.10.5/lib/python3.10
[Info  - 10:10:17 PM] (10062)   /Users/tintvrtkovic/.asdf/installs/python/3.10.5/lib/python3.10/lib-dynload
[Info  - 10:10:17 PM] (10062)   /Users/tintvrtkovic/hr/user-service/.venv/lib/python3.10/site-packages
[Info  - 10:10:17 PM] (10062)   /Users/tintvrtkovic/hr/user-service/src
[Info  - 10:10:17 PM] (10062)   /Users/tintvrtkovic/hr/user-service/vendor
[Info  - 10:10:17 PM] (10062) Adding fs watcher for library directories:
 /Users/tintvrtkovic/.asdf/installs/python/3.10.5/lib/python3.10
/Users/tintvrtkovic/.asdf/installs/python/3.10.5/lib/python3.10/lib-dynload
/Users/tintvrtkovic/hr/user-service/.venv/lib/python3.10/site-packages
[Info  - 10:10:17 PM] (10062) Searching for source files
[Info  - 10:10:17 PM] (10062) No source files found.
[Info  - 10:10:17 PM] (10062) Background analysis(1) root directory: /Users/tintvrtkovic/.vscode/extensions/ms-python.vscode-pylance-2022.9.20/dist
[Info  - 10:10:17 PM] (10062) Background analysis(1) started
(10062) Background analysis message: setConfigOptions
(10062) Background analysis message: setImportResolver
(10062) Background analysis message: ensurePartialStubPackages
(10062) Background analysis message: setTrackedFiles
(10062) Background analysis message: markAllFilesDirty
(10062) Background analysis message: analyze

Tinche avatar Sep 16 '22 20:09 Tinche

Apparently, we do not automatically search src if it contains an __init__.py. Anyway, that's why I asked. But you're good there.

Hmmm, the log shows that we are adding src to the search path.

Is this code in a public repo that I can try out on my machine?

debonte avatar Sep 16 '22 20:09 debonte

No, it's a private repo, but I could try paring it down as much as I can while still reproing and then publishing it somewhere.

Tinche avatar Sep 16 '22 20:09 Tinche

I whittled it down to https://github.com/Tinche/vs-code-test.

Still says No source files found. unless I explicitly add src to python.analysis.include, then it says Found 1 source file.

Tinche avatar Sep 16 '22 20:09 Tinche

Excellent, thanks! I can repro the issue.

I don't see it in 2022.9.10 (last week's release), so you could work around the issue by switching to that build.

debonte avatar Sep 16 '22 20:09 debonte

Glad I could help and thanks for looking into this ;)

Tinche avatar Sep 16 '22 20:09 Tinche

This issue has been fixed in prerelease version 2022.9.31, which we've just released. You can find the changelog here: CHANGELOG.md

debonte avatar Sep 22 '22 01:09 debonte

Thanks!

Tinche avatar Sep 22 '22 08:09 Tinche