英文:
Pylance goes haywire in VS Code python notebooks
问题 {#heading}
有人知道是什么原因导致 VS Code 突然出现语法高亮错误,自动补全/智能感知停止工作吗?我尝试过重新安装 VS Code,切换到 VS Code 内部版本,禁用未使用的扩展。无论我做什么,打开 VS Code 几分钟后,语法高亮都会变得混乱,Pylance 智能感知就会消失。
例如:
我在语言服务器输出中唯一看到的异常情况是:
2023-08-10 09:35:08.006 [info] Error: Debug Failure. False expression: Chained file path undefined doesn't match cellFilePaths c:\Users\julian.irwin\OneDrive - Thermo Fisher Scientific\Projects\XXXX\python notebooks\xxxxxxxxx\lamp_noise_study.ipynb:pylance-notebook-cell:X15sZmlsZQ==.py
at _0x2f5209 (c:\Users\julian.irwin\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.20\dist\server.bundle.js:1:1017323)
at c:\Users\julian.irwin\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.20\dist\server.bundle.js:1:1024550
at _0x3100be.<computed> (c:\Users\julian.irwin\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.20\dist\server.bundle.js:1:1024582)
at _0x72f7ac._onDidChangeNotebookDocumentAsync (c:\Users\julian.irwin\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.20\dist\server.bundle.js:1:1003431)
许多语言服务器输出中包含了包含敏感信息的路径名,因此我没有发布完整的输出。如果有助于调试,我可以将其清理并发布。
另一个神秘的事实是,在另一个选项卡中打开的 Python 文件 (.py) 可以正常工作。高亮和自动补全功能完全正常。只有在笔记本环境中才会出现问题。
可能与这个 Pylance 问题相关:
https://github.com/microsoft/pylance-release/issues/4685
建议的解决方案是降级到 Pylance v2023.7.40
版本:
- Windows 11
- VSCode 1.81.0
- VSCode 1.82.0-insider (也尝试过这个版本!)
- Python 3.11.1
- Ipykernel 6.19.4
VSCode 扩展:
- Jupyter v2023.7.1002162226
- Python v2023.14.0
- Pylance v2023.8.20
英文:
Does anyone know what could cause VS Code to suddenly have syntax highlighting go haywire, and autocompletion/intellisense stop working? I have tried reinstalling VS Code, switching to the VS Code insiders version, disabling unused extensions. No matter what I do a few minutes after opening VS code highlighting goes nuts and Pylance intellisense drops out.
For example:
The only unusual thing I see in the language server output is:
2023-08-10 09:35:08.006 [info] Error: Debug Failure. False expression: Chained file path undefined doesn't match cellFilePaths c:\Users\julian.irwin\OneDrive - Thermo Fisher Scientific\Projects\XXXX\python notebooks\xxxxxxxxx\lamp_noise_study.ipynb:pylance-notebook-cell:X15sZmlsZQ==.py
at _0x2f5209 (c:\Users\julian.irwin\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.20\dist\server.bundle.js:1:1017323)
at c:\Users\julian.irwin\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.20\dist\server.bundle.js:1:1024550
at _0x3100be.<computed> (c:\Users\julian.irwin\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.20\dist\server.bundle.js:1:1024582)
at _0x72f7ac._onDidChangeNotebookDocumentAsync (c:\Users\julian.irwin\.vscode-insiders\extensions\ms-python.vscode-pylance-2023.8.20\dist\server.bundle.js:1:1003431)
Much of the language server output has path names containing sensitive information so I didn't post the full output. I can scrub and then post them if it would help someone debug this.
Another mysterious fact is that a python file (.py) opened in a different tab works fine. Highlighting and autocompletion are fully function. It is only in the notebook environment that the problem occurs.
Possibly related to this Pylance issue:
https://github.com/microsoft/pylance-release/issues/4685
Suggested solution is to downgrade to Pylance v2023.7.40
Versions:
windows 11
vscode 1.81.0
vscode 1.82.0-insider (also tried with this one!)
python 3.11.1
ipykernel 6.19.4
VSCode Extensions
Jupyter v2023.7.1002162226
Python v2023.14.0
Pylance v2023.8.20
答案1 {#1}
得分: 0
我找到了解决方案。
在我的情况下,某些文件已损坏。找到显示错误的扩展文件夹的位置。
- 卸载所有 Python 扩展
- 关闭 VS Code
- 删除该错误的扩展文件夹
- 打开 VS Code 并安装建议的扩展
我注意到仅卸载扩展并不会删除文件夹,所以我猜想重新安装时它只是从相同的文件中加载。 英文:
I found the solution.
In my case, some file was corrupted. Find the location of the extension folder which is showing an error.
- Uninstall all Python extensions
- Close VS Code
- Delete that error extension folder
- Open VS Code and install the recommendations
I noted that only uninstalling extension did not delete the folder, so I am guessing that when reinstall, it just loads from the same files again.
答案2 {#2}
得分: 0
这个问题在这个 Pylance 问题中得到了解决:
https://github.com/microsoft/pylance-release/issues/4685
解决方法是将 Pyalnce 版本从 v2023.8.xx 降级到 v2023.7.40,可以使用 VS Code 扩展列表中的 "安装" 或 "卸载" 下拉菜单来进行操作。 英文:
The problem is addressed in this Pylance issue:
https://github.com/microsoft/pylance-release/issues/4685
The solution is to downgrade from Pyalnce v2023.8.xx to v2023.7.40, using the "Install" or "Uninstall" pulldown menu in the VS Code extension listing for Pylance.