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

Improve VS code auto-completion support #6686

Open
jcfr opened this issue Nov 21, 2022 · 0 comments · May be fixed by #6687
Open

Improve VS code auto-completion support #6686

jcfr opened this issue Nov 21, 2022 · 0 comments · May be fixed by #6687
Labels
Domain: Autocomplete Type: Enhancement Improvement to functionality
Milestone

Comments

@jcfr
Copy link
Member

jcfr commented Nov 21, 2022

Is your feature request related to a problem? Please describe.

Setting PythonSlicer as the interpreter is expected to enabled auto-complete for python module like slicer.util

PythonSlicer interpreter VS Code Python extension
image image

Despite of having the python interpreter properly setting environment variables like PYTHONPATH, user has been expected to set additional settings 12 like python.autoComplete.extraPaths3 and python.analysis.extraPaths4

This requires tedious configuration and ideally relevant setting files should be directly configured.

Describe the solution you'd like

Configure a workspace file referencing the source and build trees as well as the PythonSlicer interpreter.

{
  "folders": [
    {
      "path": "@Slicer_SOURCE_DIR@"
    },
    {
      "path": "@Slicer_BINARY_DIR@"
    },
  ],
  "settings": {
    "python.defaultInterpreterPath": "@PYTHON_EXECUTABLE@",
  },
}

Manually setting "python.analysis.logLevel": "Trace" and inspecting the Output Panel (by selecting Python Language Server) allows to confirm that the environment is discovered:

Pylance language server Trace
[Info  - 5:58:03 PM] (2700483) Pylance language server 2022.11.30 (pyright 04a10583) starting
[Info  - 5:58:03 PM] (2700483) Server root directory: /home/jcfr/.vscode/extensions/ms-python.vscode-pylance-2022.11.30/dist
[Info  - 5:58:03 PM] (2700483) Starting service instance "Slicer"
[Info  - 5:58:03 PM] (2700483) Starting service instance "Slicer-build"
[Info  - 5:58:03 PM] (2700483) Notebook support: LSP
[Info  - 5:58:03 PM] (2700483) Interactive window support: LSP
[Info  - 5:58:03 PM] (2700483) No configuration file found.
[Info  - 5:58:03 PM] (2700483) No pyproject.toml file found.
[Info  - 5:58:03 PM] (2700483) Setting pythonPath for service "Slicer": "/home/jcfr/Projects/Slicer-Release/python-install/bin/PythonSlicer"
[Warn  - 5:58:03 PM] (2700483) stubPath /home/jcfr/Projects/Slicer/typings is not a valid directory.
[Info  - 5:58:03 PM] (2700483) Assuming Python version 3.9
[Info  - 5:58:03 PM] (2700483) Assuming Python platform Linux
[Info  - 5:58:03 PM] (2700483) Search paths for /home/jcfr/Projects/Slicer
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/.vscode/extensions/ms-python.vscode-pylance-2022.11.30/dist/typeshed-fallback/stdlib
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer/typings
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/.vscode/extensions/ms-python.vscode-pylance-2022.11.30/dist/typeshed-fallback/stubs/...
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/.vscode/extensions/ms-python.vscode-pylance-2022.11.30/dist/bundled/stubs
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build/bin
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build/bin/Python
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build/lib/Slicer-5.1/qt-loadable-modules
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build/lib/Slicer-5.1/qt-loadable-modules/Python
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build/lib/Slicer-5.1/qt-scripted-modules
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9/lib-dynload
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9/site-packages
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/VTK-build/lib/python3.9/site-packages
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/CTK-build/CTK-build/bin/Python
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/CTK-build/CTK-build/bin
[Info  - 5:58:03 PM] (2700483) Adding fs watcher for library directories:
 /home/jcfr/Projects/Slicer-Release/Slicer-build/bin
/home/jcfr/Projects/Slicer-Release/Slicer-build/bin/Python
/home/jcfr/Projects/Slicer-Release/Slicer-build/lib/Slicer-5.1/qt-loadable-modules
/home/jcfr/Projects/Slicer-Release/Slicer-build/lib/Slicer-5.1/qt-loadable-modules/Python
/home/jcfr/Projects/Slicer-Release/Slicer-build/lib/Slicer-5.1/qt-scripted-modules
/home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9
/home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9/lib-dynload
/home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9/site-packages
/home/jcfr/Projects/Slicer-Release/VTK-build/lib/python3.9/site-packages
/home/jcfr/Projects/Slicer-Release/CTK-build/CTK-build/bin/Python
/home/jcfr/Projects/Slicer-Release/CTK-build/CTK-build/bin
[Info  - 5:58:03 PM] (2700483) Adding fs watcher for directories:
 /home/jcfr/Projects/Slicer
[Info  - 5:58:03 PM] (2700483) Searching for source files
[Info  - 5:58:03 PM] (2700483) Found 238 source files
[Info  - 5:58:03 PM] (2700483) Background analysis(1) root directory: /home/jcfr/.vscode/extensions/ms-python.vscode-pylance-2022.11.30/dist
[Info  - 5:58:03 PM] (2700483) Background analysis(1) started
(2700483) Background analysis message: setConfigOptions
(2700483) Background analysis message: setImportResolver
(2700483) Background analysis message: ensurePartialStubPackages
[Info  - 5:58:03 PM] (2700483) Background analysis(2) root directory: /home/jcfr/.vscode/extensions/ms-python.vscode-pylance-2022.11.30/dist
[Info  - 5:58:03 PM] (2700483) Background analysis(2) started
[Info  - 5:58:03 PM] (2700483) No configuration file found.
[Info  - 5:58:03 PM] (2700483) No pyproject.toml file found.
[Info  - 5:58:03 PM] (2700483) Setting pythonPath for service "Slicer-build": "/home/jcfr/Projects/Slicer-Release/python-install/bin/PythonSlicer"
[Warn  - 5:58:03 PM] (2700483) stubPath /home/jcfr/Projects/Slicer-Release/Slicer-build/typings is not a valid directory.
[Info  - 5:58:03 PM] (2700483) Assuming Python version 3.9
[Info  - 5:58:03 PM] (2700483) Assuming Python platform Linux
[Info  - 5:58:03 PM] (2700483) Search paths for /home/jcfr/Projects/Slicer-Release/Slicer-build
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/.vscode/extensions/ms-python.vscode-pylance-2022.11.30/dist/typeshed-fallback/stdlib
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build/typings
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/.vscode/extensions/ms-python.vscode-pylance-2022.11.30/dist/typeshed-fallback/stubs/...
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/.vscode/extensions/ms-python.vscode-pylance-2022.11.30/dist/bundled/stubs
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build/bin
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build/bin/Python
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build/lib/Slicer-5.1/qt-loadable-modules
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build/lib/Slicer-5.1/qt-loadable-modules/Python
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/Slicer-build/lib/Slicer-5.1/qt-scripted-modules
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9/lib-dynload
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9/site-packages
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/VTK-build/lib/python3.9/site-packages
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/CTK-build/CTK-build/bin/Python
[Info  - 5:58:03 PM] (2700483)   /home/jcfr/Projects/Slicer-Release/CTK-build/CTK-build/bin
[Info  - 5:58:03 PM] (2700483) Adding fs watcher for library directories:
 /home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9
/home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9/lib-dynload
/home/jcfr/Projects/Slicer-Release/python-install/lib/python3.9/site-packages
/home/jcfr/Projects/Slicer-Release/VTK-build/lib/python3.9/site-packages
/home/jcfr/Projects/Slicer-Release/CTK-build/CTK-build/bin/Python
/home/jcfr/Projects/Slicer-Release/CTK-build/CTK-build/bin
[Info  - 5:58:03 PM] (2700483) Adding fs watcher for directories:
 /home/jcfr/Projects/Slicer-Release/Slicer-build
[Info  - 5:58:03 PM] (2700483) Searching for source files
[Info  - 5:58:04 PM] (2700483) Found 180 source files
(2700483) Background analysis message: setTrackedFiles
(2700483) Background analysis message: markAllFilesDirty
(2700483) Background analysis message: analyze
(2700483) Background analysis message: setConfigOptions
(2700483) Background analysis message: setImportResolver
(2700483) Background analysis message: ensurePartialStubPackages
(2700483) Background analysis message: setTrackedFiles
(2700483) Background analysis message: markAllFilesDirty
(2700483) Background analysis message: analyze

Describe alternatives you've considered

Require users to explicitly configure their environment.

Additional context

Footnotes

  1. https://discourse.slicer.org/t/developing-slicer-modules-in-visual-studio-visual-studio-code/9496/8

  2. https://discourse.slicer.org/t/developing-slicer-modules-in-visual-studio-visual-studio-code/9496/23

  3. https://code.visualstudio.com/docs/python/settings-reference#_autocomplete-settings

  4. https://code.visualstudio.com/docs/python/settings-reference#_python-language-server-settings

@jcfr jcfr added the Type: Enhancement Improvement to functionality label Nov 21, 2022
@jcfr jcfr linked a pull request Nov 21, 2022 that will close this issue
@jcfr jcfr linked a pull request Nov 21, 2022 that will close this issue
@lassoan lassoan added this to the Backlog milestone Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Autocomplete Type: Enhancement Improvement to functionality
Development

Successfully merging a pull request may close this issue.

2 participants