VSCode 鼠标悬停在 Python 关键字上无效

VSCode mouse-hover on Python Keywords not working

开始教一位朋友如何在 Python 中编写代码时,我观察到他的 VSCode 与我自己的有所不同 - 他可以将鼠标悬停在 Python关键字,例如 importdef,它会显示关键字的 Python 手动定义。我自己的 VSCode 不会这样做。

我已经尝试了所有我能想到的方法来找出为什么这对我不起作用,但我完全不知所措。我将我的安装过程与我朋友的进行了比较,按照我提供给他的完全相同的步骤来设置他的环境,但没有得到相同的结果。我尝试从我的笔记本电脑中完全删除 Python、VSCode 和所有残留的 VSCode 文件,并按照他所做的相同顺序重新安装,仍然无济于事。

我在工作中的另一台笔记本电脑上执行了相同的步骤,我可以让 MouseHover 在那里工作。我能想到的唯一可行的区别是我的工作机器没有使用与我的家庭 PC 和笔记本电脑相同的 Windows 帐户 - 但我没有启用设置同步所以我不明白为什么这应该重要无论如何。

对于我在 VSCode 中让此功能正常工作我自己忽略了什么有什么想法吗?我不是特别需要它,但我想在我教他的时候和我的朋友在同一个环境中。

我们都在 VSCode 1.55.2,Python 3.9.4,使用从 VSCode 的 Powershell 终端创建的虚拟环境,然后重新启动 VSCode 让它检测虚拟环境并将其用作终端的默认值,最后安装 pip 并启用 Pylint 作为 linter。

编辑以添加步骤 - 在完全删除 VisualStudio2019 和 Code 的所有痕迹以及 Python 之后,我刚刚在家用笔记本电脑上再次完成了所有这些操作。注意:这是在 Windows 10 上进行的,应用了所有更新

在 riov8 对原始评论 post 的帮助下,我能够比较对每个环境有效的实验组。

  • 在 VSCode 中,加载 Python 文件后,切换到输出面板(与终端位于同一区域)并将下拉列表更改为 Python。
  • 滚动到此面板的顶部,检查您所属的实验组。
  • 大部分实验组不适用于此问题。
  • 专门查找 pythonJediLSPpythonJediLSPcf 或者如果 你两者都没有。

如果您遇到我描述的问题,那么在同一面板的底部,当您在开始 [=103] 后第一次将鼠标悬停在 python 关键字 上时=],你会得到类似如下的错误:

Error 2021-04-16 15:33:40: stderr jediProxy Error (stderr) %UserProfile%\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\completion.py:598: DeprecationWarning: Providing the line is now done in the functions themselves like `Script(...).complete(line, column)`
  sys_path=sys.path,
%UserProfile%\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\completion.py:598: DeprecationWarning: Providing the column is now done in the functions themselves like `Script(...).complete(line, column)`
  sys_path=sys.path,

Error 2021-04-16 15:33:40: stderr jediProxy Error (stderr) %UserProfile%\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\completion.py:598: DeprecationWarning: Deprecated since version 0.17.0. Use the project API instead, which means Script(project=Project(dir, sys_path=sys_path)) instead.
  sys_path=sys.path,

Error 2021-04-16 15:33:40: stderr jediProxy Error (stderr) %UserProfile%\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\completion.py:626: DeprecationWarning: Deprecated since version 0.16.0. Use Script(...).infer instead.
  script.goto_definitions(), request["id"]

以下情况为我解决了问题:

用户属于实验组pythonJediLSPcf:

  • 文件 > 首选项 > 设置
  • 在搜索设置中,开始输入 python.experiment
  • 在 Python> 实验:选择退出下,单击 Edit in settings.json
  • "python.experiments.optOutFrom" 部分中,添加 "pythonJediLSPcf"(引用)
  • 如果不存在,再添加一段"python.experiments.optInto"
  • 在 OptInto 部分,添加 "pythonJediLSP"(引用)
  • 保存 settings.json,然后重新启动 VSCode。
  • Python 关键字上的鼠标悬停工具提示现在应该可以使用了。

用户不属于 pythonJediLSPcfpythonJediLSP:

  • 文件 > 首选项 > 设置
  • 在搜索设置中,开始输入 python.experiment
  • 在 Python 下 › 实验:选择加入,点击 Edit in settings.json
  • "python.experiments.optInto 部分,添加 "pythonJediLSP"(引用)
  • 保存 settings.json,然后重新启动 VSCode。
  • Python 关键字上的鼠标悬停工具提示现在应该可以使用了。

用户属于 pythonJediLSP:

  • 根据我的经验,这是使该功能正常工作所需的实验。如果您已经启用了此实验,请确保您没有同时启用 pythonJediLSPcf。如果这样做,请按照第一个 sub-heading 中的说明禁用它。如果还是不行,那可能又是我自己没有经历过的冲突。

我正在 post 处理有关此问题的 GitHub 问题,完成后将使用 link 更新此答案。