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

python.analysis.extraPaths not work in workspace settings.json but it's alright in user settings.json #588

Closed
screamff opened this issue Nov 10, 2020 · 6 comments
Labels
waiting for user response Requires more information from user

Comments

@screamff
Copy link

platform: win10
pylance version: v2020.11.0

I used absolute path. The path includes my own module. When I add it to workspace settings.json, it can't resolve nor use F12. But it works fine when I add the same setting in Preferences: Open Settings (Json).

@jakebailey
Copy link
Member

jakebailey commented Nov 10, 2020

Can you please provide trace logs from the "Python Language Server" output window for both cases? It should print the paths it's using at startup.

https://github.com/microsoft/pylance-release/blob/master/TROUBLESHOOTING.md#filing-an-issue

@jakebailey jakebailey added the waiting for user response Requires more information from user label Nov 10, 2020
@github-actions github-actions bot removed the triage label Nov 10, 2020
@screamff
Copy link
Author

screamff commented Nov 10, 2020

[Info  - 下午1:44:15] Pylance language server 2020.11.0 (pyright 9d8e431b) starting
[Info  - 下午1:44:15] Server root directory: c:\Users\lenovo\.vscode\extensions\ms-python.vscode-pylance-2020.11.0\dist
[Info  - 下午1:44:15] No configuration file found.
[Info  - 下午1:44:15] Setting pythonPath for service "xxx": "C:\Python37-32\python.exe"
Search paths found for configured python interpreter:
  C:\Python37-32\DLLs
  C:\Python37-32\lib
  C:\Python37-32
  C:\Users\lenovo\AppData\Roaming\Python\Python37\site-packages
  C:\Python37-32\lib\site-packages
  C:\Python37-32\lib\site-packages\win32
  C:\Python37-32\lib\site-packages\win32\lib
  C:\Python37-32\lib\site-packages\Pythonwin
[Error - 下午1:44:15] stubPath e:\developenv\xxx\typings is not a valid directory.
[Info  - 下午1:44:15] Assuming Python version 3.7
[Info  - 下午1:44:15] Assuming Python platform Windows

Are these messages enough? Whether I use workspace settings or user settings, they both return these messages(my paths not included). The difference when I use workspace settings is that it return the messages below when I move mouse uppon those unresolved modules.

Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange

Normally it returns parsing ... binding... messages.

@screamff
Copy link
Author

screamff commented Nov 10, 2020

BTW, when I set python.analysis.logLevel in workspace settings, it does not work.Is it possible that my workspace settings.json just doen't work?

@screamff
Copy link
Author

I solved it.It's because I edited the folder settings which path is .vscode\settings.json. So normally there are three settings in single workspace file.user, workspace, xxx folder.The folder settings make me confused.

@jakebailey
Copy link
Member

Thanks for letting us know. VS Code does take things first from the folder, then workspace, then user settings, whichever is set first. Unfortunately the UI for this hierarchy isn't the best, and it can be annoying to notice misconfigurations. It'd be nice if the UI improved (say, showed that it overrode or something), but that'd have to be done in VS Code itself.

@Tobiaqs
Copy link

Tobiaqs commented Dec 24, 2024

I found out that when using workspace settings (proj.code-workspace file), the paths specified in python.analysis.extraPaths are evaluated relative to each of the folders configured in the workspace. To me this seems completely counter-intuitive.

In my case, I have the following tree:

proj/
    backend/
        apps/
            some_app/
                code.py
        modules/
            some_module/
                code.py
    backend-alt/
    proj.code-workspace

My proj.code-workspace:

{
    "folders": [
        { "path": "backend" },
        { "path": "backend-alt" },
    ],
    "settings": {
        "python.analysis.extraPaths": [
            "apps",
            "modules"
        ],
    }
}

This allows me to auto-import some_app.code (in constrast to apps.some_app.code).

I found a workaround to support customization per folder:

{
    "folders": [
        { "path": "backend" },
        { "path": "backend-alt" },
    ],
    "settings": {
        "python.analysis.extraPaths": [
            "../backend/apps",
            "../backend/modules",
            "../backend-alt/plugins"
        ],
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for user response Requires more information from user
Projects
None yet
Development

No branches or pull requests

3 participants