microsoft / pylance-release

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

PyLance stops functioning when a (virtual) workspace folder is added with any URI that has a path '\' #2978

Closed Josverl closed 2 years ago

Josverl commented 2 years ago

Environment data

Code Snippet

"""MicroPython blink"""
import time
import machine

print("Hello World")
p2 = machine.Pin(2,machine.Pin.OUT)
while True:
    p2.on()
    time.sleep(0.5)
    p2.off()
    time.sleep(0.5)

Repro Steps

The complete repro steps, logs , and screen recording are located in a repro repo

https://github.com/Josverl/stubs-esp-test/blob/main/repro.md

Expected behavior

one or more of the below:

  1. not to blindly assume that the path section of an URI is available on the local filesystem
  2. not to scan the entire local filesystem starting from the root
  3. avoid to try to scan 'remote workspace' folders that do not use filesystem paths skip 'workspace folders' that use an uri, or only where pylance does not understand the protocol or scheme such as :
    • "uri": "memfs:/"
    • "uri": "serial://com6"

ref: https://github.com/Microsoft/vscode-uri#vscode-uri

sample.code-workspace

{
{
    "folders": [
        {
            "name": "MemFS - Sample",
            "uri": "memfs:/"
        },
        {
            "path": "project_esp8266"
        },
        {
            "path": ".",
            "name": "root folder"
        },
        {
            "name": "serial:/COM6",
            "uri": "serial://com6"
        }
    ],
    "settings": {
        "python.analysis.logLevel": "Trace",
    }
}
}

Actual behavior

As soon as a virtual filesystem is part of the workspace, Pylance will attempt to scan the local rootdrive (C:\ or '/' ) where the path is relative to the rootpath of the virtual filesystem. I assume URI.path is used.

Logs

After that essentially PyLance stops functiong for either the local or the virtual filesystem.

this is shown in the Pylance logs by looking for the tag : Search paths for \

[Info  - 12:39:18] (26416) Pylance language server 2022.6.30 (pyright 212d1465) starting
[Info  - 12:39:19] (26416) Server root directory: c:\Users\josverl\.vscode\extensions\ms-python.vscode-pylance-2022.6.30\dist
Notebook support: Legacy
[Info  - 12:39:20] (26416) Background analysis(1) root directory: c:\Users\josverl\.vscode\extensions\ms-python.vscode-pylance-2022.6.30\dist
[Info  - 12:39:20] (26416) Background analysis(1) started
[Info  - 12:39:20] (26416) Background analysis(3) root directory: c:\Users\josverl\.vscode\extensions\ms-python.vscode-pylance-2022.6.30\dist
[Info  - 12:39:20] (26416) Background analysis(3) started
[Info  - 12:39:21] (26416) Background analysis(2) root directory: c:\Users\josverl\.vscode\extensions\ms-python.vscode-pylance-2022.6.30\dist
[Info  - 12:39:21] (26416) Background analysis(2) started
[Info  - 12:39:21] (26416) Background analysis(4) root directory: c:\Users\josverl\.vscode\extensions\ms-python.vscode-pylance-2022.6.30\dist
[Info  - 12:39:21] (26416) Background analysis(4) started
[Info  - 12:39:21] (26416) No configuration file found.
[Info  - 12:39:22] (26416) No pyproject.toml file found.
[Info  - 12:39:22] (26416) Setting pythonPath for service "MemFS - Sample": "C:\Users\josverl\AppData\Local\Microsoft\WindowsApps\python3.9.exe"
[Warn  - 12:39:23] (26416) stubPath \typings is not a valid directory.
[Info  - 12:39:23] (26416) Assuming Python version 3.9
[Info  - 12:39:23] (26416) Assuming Python platform Windows
[Info  - 12:39:23] (26416) Search paths for \
[Info  - 12:39:24] (26416)   c:\Users\josverl\.vscode\extensions\ms-python.vscode-pylance-2022.6.30\dist\typeshed-fallback\stdlib
[Info  - 12:39:24] (26416)   \
[Info  - 12:39:24] (26416)   \typings
....
[Info  - 12:39:24] (26416) Adding fs watcher for directories:
 \
[Info  - 12:39:24] (26416) Searching for source files
[Info  - 12:39:24] (26416) Auto-excluding \$Recycle.Bin\S-1-12-1-3020494159-1235939459-3438115750-967420959\$REJ16W7.venv
[Info  - 12:39:24] (26416) Auto-excluding \$Recycle.Bin\S-1-12-1-3020494159-1235939459-3438115750-967420959\$RGXEZSB.venv
...
[Warn  - 12:39:24] (26416) Skipping broken link "\$Recycle.Bin\S-1-5-18"
[Warn  - 12:39:24] (26416) Skipping broken link "\PerfLogs"
[Warn  - 12:39:24] (26416) Skipping broken link "\Program Files\WindowsApps"
[Warn  - 12:39:25] (26416) Skipping broken link "\ProgramData\Microsoft\Crypto\PCPKSP\WindowsAIK"
....

[Error - 12:47:03] (29996) Enumeration of workspace source files is taking longer than 10 seconds.
This may be because:
* You have opened your home directory or entire hard drive as a workspace
* Your workspace contains a very large number of directories and files
* Your workspace contains a symlink to a directory with many files
* Your workspace is remote, and file enumeration is slow
To reduce this time, open a workspace directory with fewer files or add a pyrightconfig.json configuration file with an "exclude" section to exclude subdirectories from your workspace. For more details, refer to https://github.com/microsoft/pyright/blob/

Full log: MemFS virtual provider : https://github.com/Josverl/stubs-esp-test/blob/main/Memfs_workspace.log

references

https://github.com/microsoft/pylance-release/discussions/2696

heejaechang commented 2 years ago

we should disable all fs access for virtual workspace. we can't use vscode file provider api or new LSP file system api proposal for now. that require async file access which we currently doesn't support.

heejaechang commented 2 years ago

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

Josverl commented 2 years ago

confirmed resolved in Pylance preview 2022.7.41