microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.71k stars 765 forks source link

How to explicitly specify that Pylance only scans specific a few directories in a large multi-root workspace #5794

Open vbem opened 6 months ago

vbem commented 6 months ago

Hi, I have a large multi-root workspace containing many project-directories, but only a few among them are Python related. Every time a start VScode, the Pylance starts scanning every project-directory in my multi-root workspace, it consumes several minutes before I can work in Python related project-directories.

Is it possible I can limit the directories Pylance will scan in a multi-root workspace? Thanks in advance.

image image

StellaHuang95 commented 6 months ago

Hi @vbem, if you don't want certain directories or paths to be included in the analysis, you can do the followings:

  1. Open command palette, search for workspace settings.
  2. Add the following to your settings:
    "settings": {
    "python.analysis.exclude": ["full path of directories or files"]
    }

    Globbing is supported, so please refer to this doc for more details.

Please use full paths for now as I found a bug with using variables like ${workspaceFolder:<workspace folder name>}. I will mark this issue as a bug and give an update once the bug is fixed. Thanks.

vbem commented 6 months ago
"settings": {
  "python.analysis.exclude": ["full path of directories or files"]
}

Thanks a lot for your guidance @StellaHuang95 . I added other non-python directories (full-path) into python.analysis.exclude of my multi-root workspace settings, restarted VScode, but the scanning on every project-directory still shown up:

image

image

image

rchiodo commented 6 months ago

I believe you need to actually use a glob like so:

"python.analysis.exclude: ["/root/_git/foo/bar/**/*.py*"]

The Starting server instance entries will still show up though. We should just skip the indexing and analysis then.

vbem commented 6 months ago

I believe you need to actually use a glob like so:

"python.analysis.exclude: ["/root/_git/foo/bar/**/*.py*"]

The Starting server instance entries will still show up though. We should just skip the indexing and analysis then.

Thanks a lot for your hints.

But is it possible to disable/enable pylance scanning instances for certain project-directories? Because in a large multi-root workspace with only 1 python related project-directory, user still need to wait all scanning instance done before working on the python directory, which consumes a lot of unnecessary time and resources.

rchiodo commented 6 months ago

But is it possible to disable/enable pylance scanning instances for certain project-directories? Because in a large multi-root workspace with only 1 python related project-directory, user still need to wait all scanning instance done before working on the python directory, which consumes a lot of unnecessary time and resources.

Sorry there's no way to completely ignore a workspace folder. The ignore logic is actually independent of the folder handling.

Internally there should be no scanning. We will create data structures to track those other folders, but then any documents in that folder will be marked as skipped. The only work that should happen is that it finds no source or files in those folders.

heejaechang commented 6 months ago

But is it possible to disable/enable pylance scanning instances for certain project-directories?

you can have folder specific setting for multi workspaces in vscode using this - https://code.visualstudio.com/docs/editor/workspaces#_multiroot-workspace-settings

for your specific issue, create .vscode/settings.json in the root that you want to ignore python files completely.

and add

{
    "python.analysis.exclude": ["**/*.py", "**/*.pyi"]
}

any setting in code-workspace will apply to all workspaces so, that place is not right place if you want settings that apply for only some of roots.

djettah commented 3 months ago

add

{
    "python.analysis.exclude": ["**/*.py", "**/*.pyi"]
}

I've tried this but unfortunately it doesn't prevent pylance instances from starting and consequently using a big slice of RAM (around 2 GB for 30 roots) in a devcontainer. Are there any other workarounds?

heejaechang commented 3 months ago

@djettah can you take a look at https://github.com/microsoft/pylance-release/wiki/Opening-Large-Workspaces-in-VS-Code ?

that should have more detail instructions on how to set up large workspace.