microsoft / pylance-release

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

`extraPaths` starting with `~/` on Linux are considered relative #3730

Closed debonte closed 1 year ago

debonte commented 1 year ago

Code Snippet

VS Code settings:

"python.analysis.extraPaths": [
    "~/.ipython/profile_default/startup"
]

~/.ipython/profile_default/startup/erikd.py:

def addModulePath(path: str):
    pass

Repro Steps

  1. Set extraPaths and create .py file as above.
  2. In a .py file within your workspace, type: from erikd import addModulePath

Expected behavior

Import is resolved

Actual behavior

Import cannot be resolved. ~/.ipython/profile_default/startup is treated as a relative path. Problem is that getRootLength returns 0 for this path.

erictraut commented 1 year ago

This is the intended behavior currently. The ~ character is a shell construct, and pyright doesn't contain logic to interpret shell constructs. We could decide to change that, but it's a slippery slope. Would we support other shell constructs like shell variable expansion? For which shells?

We might want to look at other language servers (e.g. typescript) to see what they do in this case.

debonte commented 1 year ago

✅ mypy Mypy's mypy_path config setting supports ~ and the docs call that out: "User home directory and environment variables will be expanded."

[mypy]
mypy_path = ~/.ipython/profile_default/startup

✅ Pyre Pyre's search_path config setting supports ~.

{
  "site_package_search_strategy": "pep561",
  "source_directories": [
    "."
  ],
  "search_path": [
    "~/.ipython/profile_default/startup"
  ]
}

:x: TypeScript TypeScript's compilerOptions/paths does not support ~.

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
       "foo/*": ["/home/erikd/foo/*"], // works
       "foo/*": ["~/foo/*"]            // does not work
    }
  }
}
rchiodo commented 1 year ago

Related: https://github.com/microsoft/pylance-release/issues/3823

heejaechang commented 1 year ago

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