如何在 Visual Studio 代码的注释中禁用 IntelliSense?

How do I disable IntelliSense in comments in Visual Studio Code?

我正在使用 Visual Studio 代码,主要用于 PHP。每次我点击 .,IntelliSense 都会启动并为我提供 PHP 全局变量和函数,从 $_COOKIE 开始。我通常知道我想要什么全局或功能,所以这有点烦人。当我在评论区(/* ... */// ...)时甚至会发生这种情况,这更令人讨厌。我的大部分时间都花在了返回和删除 $_COOKIE.

一个例子(不是PHP,但你明白了):

我试过禁用它as suggested in the docs:

// Controls if quick suggestions should show up while typing
"editor.quickSuggestions": false,

// Controls if suggestions should be accepted with "Enter" - in addition to "Tab". Helps to avoid ambiguity between inserting new lines and accepting suggestions.
"editor.acceptSuggestionOnEnter": true,

// Controls the delay in ms after which quick suggestions will show up.
"editor.quickSuggestionsDelay": 10000,

// Enable word based suggestions
"editor.wordBasedSuggestions": true

...但这绝对没有任何效果。当我击中点时,我仍然得到列表。延迟从 100 增加到 1000,也没有效果。

  1. 如何关闭代码注释中的 IntelliSense?
  2. 如何在点击 . 时禁用 IntelliSense,并在我点击 Ctrl+[ 时让它显示出来? =85=]? (见下文更新 2)
  3. 如何完全禁用 IntelliSense,至少 PHP?

更新: 如前所述,禁用触发字符的快速建议是通过以下方式实现的:

// Controls if suggestions should automatically show up when typing trigger characters
"editor.suggestOnTriggerCharacters": false

但是,上面提到的其他选项仍然没有任何作用。

更新 2: possible to mess with the . binding 添加到 keybindings.json 文件:

{
    "key": ".",
    "command": "x",
}

但是,这会导致屏幕顶部显示一条警告消息 "command 'x' not found"。如果将其留空或尝试将 null 传递给 command,它仍然不起作用,因为它不会覆盖默认的键绑定。根据文档,可以通过在特定操作前加上 - 来禁用它,但这对我不起作用:

"command": "-^acceptSelectedSuggestion"

"command": "-acceptSelectedSuggestion"

在任何一种情况下,acceptSelectedSuggesdtion 并不是我点击 时正在执行的命令。,它可能更像是:

"command": "-editor.action.triggerSuggest"

但这也行不通。

大约从 2017 年 3 月或 4 月开始,此问题已得到修复,并且默认更改为评论中不自动完成。默认为:

"editor.quickSuggestions": {
  "other": true,
  "comments": false,
  "strings": false
},

我的设置中没有明确的,只是用一个新的 PHP 文件做了一个测试,我可以输入 global. 然后 space,然后不要不会自动完成任何事情。 (我尝试了主代码和评论。)我确实看到 $COOKIE 作为第一个建议弹出,但我需要使用 up/down 箭头然后输入将其引入。

啊哈,global. 然后 ENTER 确实给了我 global.$COOKIE(即使在评论中,这有点奇怪)。我可以用以下方法解决这个问题:

"editor.acceptSuggestionOnEnter": "off",

要查看您可能想要触摸的其他设置,请转到设置页面并在搜索框中键入 "suggestion"。每个都有评论。例如。 "editor.suggestOnTriggerCharacters": false, 完全摆脱自动建议。

您也可以只指定一种语言的设置,例如

"[php]":  {
  "editor.suggestOnTriggerCharacters": false,
},

尽管 and the docs, the editor.quickSuggestions settings don't do anything for suggestions that pop up due to trigger characters (see this issue on GitHub)。这些似乎都有自己的规则。即,在字符串中键入触发字符时,无论您在 editor.quickSuggestions 中说什么,您 永远不会 得到建议;当在评论或 "other" 中输入触发字符时,无论您在 editor.quickSuggestions.

中说了什么,您 总是 会得到建议

因此,摆脱我所说的 "trigger-character suggestions"(这是迄今为止最烦人的一种!)的唯一可靠方法是使用专门用于它的设置:

"editor.suggestOnTriggerCharacters": false

如果有人可以就如何发现触发字符 是什么 或更好的是如何指定它们发表评论,我会非常乐意编辑我的答案考虑到这一点。

请注意,由于实际匹配您键入的字符与已知模块、变量、函数等而弹出的建议, 仍然由 editor.quickSuggestions 控制不是 editor.suggestOnTriggerCharacters.