Closed debonte closed 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.
✅ 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
}
}
}
This issue has been fixed in prerelease version 2023.1.31, which we've just released. You can find the changelog here: CHANGELOG.md
Code Snippet
VS Code settings:
~/.ipython/profile_default/startup/erikd.py:
Repro Steps
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 thatgetRootLength
returns 0 for this path.