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

随声附和 提交于 2020-08-21 14:24:32

问题


I'm using Visual Studio Code, mostly to work with PHP. Everytime I hit ., IntelliSense kicks in and offers me PHP globals and functions, starting with $_COOKIE. I usually know what global or function I want, so it's a bit annoying. This even happens when I'm within a comment block (/* ... */ or // ...), which is far more annoying. Most of my time is spent going back and deleting $_COOKIE.

An example (not PHP, but you get the idea):

I've tried disabling it 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

... but this has absolutely no effect whatsoever. I still get the list when I hit the dot. The delay increase from 100 to 1000, too, has no effect.

  1. How do I turn off IntelliSense inside code comments?
  2. How do I disable IntelliSense on hitting . and just have it show up when I hit Ctrl+Space? (See update 2 below)
  3. How do I disable IntelliSense completely, at least for PHP?

Update: As mentioned here, disabling quick suggestions on trigger characters is achieved via:

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

However, the other options mentioned above still don't do anything.

Update 2: It is possible to mess with the . binding by adding this to the keybindings.json file:

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

However,this results in a warning message at the top of the screen that says "command 'x' not found". If you leave it empty or try to pass null to command, it still doesn't work, as it doesn't overwrite the default key binding. According to the documentation, it's possible to disable a certain action by prefixing it with a -, but this doesn't work for me:

"command": "-^acceptSelectedSuggestion"

or

"command": "-acceptSelectedSuggestion"

In either case, acceptSelectedSuggesdtion isn't really the command that's being executed when I hit ., it's probably more like:

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

But this doesn't work either.


回答1:


Since about March or April 2017, this has been fixed, and also the default has changed to be no auto-complete in comments. The default is:

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

I don't have that explicitly in my settings, and just did a test with a fresh PHP file, and I can type global. then space, and don't get anything auto-completed. (I tried both main code and in comments.) I do see $COOKIE pop up as the first suggestion, but I need to use up/down arrows and then enter to bring it in.

Aha, global. then ENTER does give me global.$COOKIE (even in comments, which is a bit weird). I can fix that with:

"editor.acceptSuggestionOnEnter": "off",

To see other settings you might want to touch, go to the settings page and type "suggestion" in the search box. Each is commented. E.g. "editor.suggestOnTriggerCharacters": false, gets rid of the auto-suggestions completely.

You can also specify the settings for just one language, e.g.

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



回答2:


Despite Darren Cook's answer 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). These seem to be subject to their own rules. Namely, when typing a trigger character in a string, you never get the suggestions, no matter what you said in editor.quickSuggestions; and when typing a trigger character in a comment or "other", you always get the suggestions, no matter what you said in editor.quickSuggestions.

Thus the only reliable way to get rid of what I'm calling "trigger-character suggestions" (which are by far the most annoying kind!) is to use the setting specifically devoted to it:

"editor.suggestOnTriggerCharacters": false

If someone can leave a comment on how to discover what the trigger characters are, or better yet, how to specify them, I would be all too happy to edit my answer to take this into account.

Note that the suggestions which pop up due to actually matching the characters you type with known modules, variables, functions, etc., are still controlled by editor.quickSuggestions and not by editor.suggestOnTriggerCharacters.



来源:https://stackoverflow.com/questions/41136308/how-do-i-disable-intellisense-in-comments-in-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!