microsoft / pylance-release

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

Pylance Should Disable Checks for Non-Python Kernels in Jupyter Notebooks #6340

Closed singularitti closed 2 months ago

singularitti commented 2 months ago

I'm encountering an issue when using the VSCode extension "Jupyter" with non-Python kernels, specifically the Wolfram Language kernel. When I open a Jupyter notebook with a non-Python kernel, Pylance begins checking types and syntax as if the notebook were using Python. This leads to errors such as undefined variables or functions (Plot, Sin, x, etc.) that are actually valid in the Wolfram Language.

wgbwrgq24wg

Environment data

Code Snippet

Plot[Sin[x], {x, 0, 1}]

Repro Steps

  1. Install the "Jupyter" and "Pylance" extensions in VSCode.
  2. Open a Jupyter notebook in VSCode.
  3. Switch the kernel to "Wolfram Language 14.1" or another non-Python kernel.
  4. Write and execute valid Wolfram Language code, such as Plot[Sin[x], {x, 0, 10}].

Expected behavior

Pylance should detect that the notebook is using a non-Python kernel and automatically disable Python-specific checks.

Actual behavior

Pylance incorrectly applies Python-specific checks, resulting in false errors and warnings for valid code in other languages.

Please consider implementing a feature where Pylance automatically disables its checks whenever a Jupyter notebook is opened with a non-Python kernel. This would prevent unnecessary distractions and errors, improving the experience for users working with other programming languages in VSCode.

rchiodo commented 2 months ago

I don't think this would be something Pylance would implement. Pylance is the language server here because the language in the notebook cell says 'Python'. If Wolfram Language Kernel isn't python, that cell should be changed to the language Wolfram or something like that. Then VS code would have a Wolfram language server.

I think this would be better as a request on the Jupyter extension. To auto switch the language of each cell when the kernel changes.