Intellisense In Visual Studio Code

broken image


-->

In some cases, you might need to manually configure your C++ project to get IntelliSense working properly. For MSBuild projects (based on .vcxproj files), you can adjust settings in project properties. For non-MSBuild projects, you adjust settings in the CppProperties.json file in the root directory of the project. In some cases, you may need to create a hint file to help IntelliSense understand macro definitions. The Visual Studio IDE helps you identify and fix IntelliSense problems.

IntelliSense for C is available for stand-alone files as well as for files that are part of a C project. In cross-platform projects, some IntelliSense features are available in.cpp and.c files in the shared code project, even when you are in an Android or iOS context. This article provides an overview of C IntelliSense features. IntelliSense features are sometimes called by other names such as 'code completion', 'content assist', and 'code hinting.' IntelliSense for your programming language. Visual Studio Code IntelliSense is provided for JavaScript, TypeScript, JSON, HTML, CSS, SCSS, and Less out of the box.

Single-file IntelliSense

When you open a file that is not included in a project, Visual Studio provides some IntelliSense support but by default no error squiggles are shown. If the Navigation Bar says Miscellaneous Files, then that probably explains why you are not seeing error squiggles under incorrect code, or why a preprocessor macro is not defined.

Check the Error List

If a file is not open in single-file mode, and IntelliSense is not working correctly, the first place to check is the Error List window. To see all the IntelliSense errors for the current source file together with all included header files, choose Build + IntelliSense in the dropdown:

IntelliSense produces a maximum of 1000 errors. If there are over 1000 errors in the header files included by a source file, then the source file shows only a single error squiggle at the very start of the source file.

Ensure #include paths are correct

MSBuild projects

If you run your builds outside of the Visual Studio IDE, and your builds are succeeding but IntelliSense is incorrect, it is possible that your command line is out of sync with the project settings for one or more configurations. Right-click on the project node in Solution Explorer and make sure that all #include paths are correct for the current configuration and platform. If the paths are identical in all configurations and platforms, you can select All configurations and All platforms and then verify that the paths are correct.

To see the current values for build macros such as VC_IncludePath, select the Include Directories line and click the dropdown on the right. Then choose and click on the Macros button.

Makefile projects

For Makefile projects that are based on the NMake project template, choose NMake in the left pane and then choose Include search path under the IntelliSense category:

Open Folder projects

For CMake projects, make sure that #include paths are specified correctly for all configurations in CMakeLists.txt. Other project types might require a CppProperties.json file. For more information, see Configure IntelliSense with CppProperties.json. Make sure that the paths are correct for each configuration that is defined in the file.

If there is a syntax error in the CppProperties.json file, IntelliSense in the affected files will be incorrect. Visual Studio will display the error in the Output Window.

Tag parser issues

The tag parser is a 'fuzzy' C++ parser that is used for browsing and navigation. It is very fast but does not attempt to completely comprehend every code construct.

For example, it doesn't evaluate preprocessor macros, and therefore it may incorrectly parse code that makes heavy use of them. When the Tag Parser encounters an unfamiliar code construct, it may skip that entire region of code.

There are two common ways in which this problem manifests in Visual Studio:

  1. If the Navigation Bar shows an innermost macro, then the current function definition was skipped:

  2. The IDE offers to create a function definition for a function that is already defined:

To fix these kinds of problems, add a file named cpp.hint to the root of your solution directory. For more information, see Hint Files.

Tag parser errors appear in the Error List window.

Validate project settings with diagnostic logging

To check whether IntelliSense compiler is using correct compiler options, including Include Paths and Preprocessor macros, turn on Diagnostic Logging of IntelliSense command lines in Tools > Options > Text Editor > C/C++ > Advanced > Diagnostic Logging. Set Enable Logging to True, Logging Level to 5 (most verbose), and Logging Filter to 8 (IntelliSense logging).

The Output Window will now show the command lines that are passed to the IntelliSense compiler. Here is a sample output:

This information may help you understand why IntelliSense is providing inaccurate information. For example, if your project's Include directory contains $(MyVariable)Include, and the diagnostic log shows /IInclude as an Include path, it means that $(MyVariable) wasn't evaluated, and was removed from the final include path.

About the IntelliSense build

Visual Studio uses a dedicated C++ compiler to create and maintain the database that powers all the IntelliSense features. To keep the IntelliSense database in sync with the code, Visual Studio automatically launches IntelliSense-only builds as background tasks in response to certain changes made in the project settings or source files.

However, in some cases Visual Studio might not update the IntelliSense database in a timely manner. For example, when you run a git pull or git checkout command, Visual Studio might take up to an hour to detect changes in the files. You can force a rescan of all files in a solution by right-clicking on the project node in Solution Explorer and choosing Rescan Solution.

Visual Studio Code Intellisense Unity

Troubleshooting IntelliSense build failures

An IntelliSense build does not produce binaries, but it can still fail. One possible cause for failure is custom .props or .targets files. In Visual Studio 2017 version 15.6 and later, IntelliSense-only build errors are logged to the Output window. To see them, set Show output from to Solution:

The error message might instruct you to enable design-time tracing:

If you set the environment variable TRACEDESIGNTIME to true and restart Visual Studio, you will see a log file in the %TEMP% directory, which might help diagnose the build failure.

To learn more about TRACEDESIGNTIME environment variable, see Roslyn and Common Project System. The information in these articles is relevant for C++ projects.

Code

See also

Naturally speaking software. IntelliSense is a general term for various code editing features including: code completion, parameter info, quick info, and member lists. IntelliSense features are sometimes called by other names such as 'code completion', 'content assist', and 'code hinting.'

IntelliSense for your programming language

Visual Studio Code IntelliSense is provided for JavaScript, TypeScript, JSON, HTML, CSS, SCSS, and Less out of the box. VS Code supports word based completions for any programming language but can also be configured to have richer IntelliSense by installing a language extension.

Below are the most popular language extensions in the Marketplace. Click on an extension tile below to read the description and reviews to decide which extension is best for you.

IntelliSense features

VS Code IntelliSense features are powered by a language service. A language service provides intelligent code completions based on language semantics and an analysis of your source code. If a language service knows possible completions, the IntelliSense suggestions will pop up as you type. If you continue typing characters, the list of members (variables, methods, etc.) is filtered to only include members containing your typed characters. Pressing Tab or Enter will insert the selected member.

You can trigger IntelliSense in any editor window by typing ⌃Space (Windows, Linux Ctrl+Space) or by typing a trigger character (such as the dot character (.) in JavaScript).

Tip: The suggestions widget supports CamelCase filtering, meaning you can type the letters which are upper cased in a method name to limit the suggestions. For example, 'cra' will quickly bring up 'createApplication'.

If you prefer, you can turn off IntelliSense while you type. See Customizing IntelliSense below to learn how to disable or customize VS Code's IntelliSense features.

As provided by the language service, you can see quick info for each method by either pressing ⌃Space (Windows, Linux Ctrl+Space) or clicking the info icon. The accompanying documentation for the method will now expand to the side. The expanded documentation will stay so and will update as you navigate the list. You can close this by pressing ⌃Space (Windows, Linux Ctrl+Space) again or by clicking on the close icon.

After choosing a method you are provided with parameter info.

When applicable, a language service will surface the underlying types in the quick info and method signatures. In the image above, you can see several any types. Because JavaScript is dynamic and doesn't need or enforce types, any suggests that the variable can be of any type.

Types of completions

The JavaScript code below illustrates IntelliSense completions. IntelliSense gives both inferred proposals and the global identifiers of the project. The inferred symbols are presented first, followed by the global identifiers (shown by the Word icon).

VS Code IntelliSense offers different types of completions, including language server suggestions, snippets, and simple word based textual completions.

Methods and Functionsmethod, function, constructor
Variablesvariable
Fieldsfield
Type parameterstypeParameter
Constantsconstant
Classesclass
Interfacesinterface
Structuresstruct
Eventsevent
Operatorsoperator
Modulesmodule
Properties and Attributesproperty
Values and Enumerationsvalue, enum
Referencesreference
Keywordskeyword
Filesfile
Foldersfolder
Colorscolor
Unitunit
Snippet prefixessnippet
Wordstext

Customizing IntelliSense

You can customize your IntelliSense experience in settings and key bindings.

Settings

The settings shown below are the default settings. You can change these settings in your settings.json file as described in User and Workspace Settings.

Tab Completion

The editor supports 'tab completion' which inserts the best matching completion when pressing Tab. This works regardless of the suggest widget showing or not. Also, pressing Tab after inserting a suggestions will insert the next best suggestion.

By default, tab completion is disabled. Use the editor.tabCompletion setting to enable it. These values exist:

  • off - (default) Tab completion is disabled.
  • on - Tab completion is enabled for all suggestions and repeated invocations insert the next best suggestion.
  • onlySnippets - Tab completion only inserts static snippets which prefix match the current line prefix.

Locality Bonus

Sorting of suggestions depends on extension information and on how well they match the current word you are typing. In addition, you can ask the editor to boost suggestions that appear closer to the cursor position, using the editor.suggest.localityBonus setting.

In above images you can see that count, context, and colocated are sorted based on the scopes in which they appear (loop, function, file).

Suggestion selection

By default, VS Code pre-selects the previously used suggestion in the suggestion list. This is very useful as you can quickly insert the same completion multiple times. If you'd like different behavior, for example, always select the top item in the suggestion list, you can use the editor.suggestSelection setting.

The available editor.suggestSelection values are:

Xampp

  • first - Always select the top list item.
  • recentlyUsed - (default) The previously used item is selected unless a prefix (type to select) selects a different item.
  • recentlyUsedByPrefix - Select items based on previous prefixes that have completed those suggestions.

'Type to select' means that the current prefix (roughly the text left of the cursor) is used to filter and sort suggestions. When this happens and when its result differs from the result of recentlyUsed it will be given precedence.

When using the last option, recentlyUsedByPrefix, VS Code remembers which item was selected for a specific prefix (partial text). For example, if you typed co and then selected console, the next time you typed co, the suggestion console would be pre-selected. This lets you quickly map various prefixes to different suggestions, for example co -> console and con -> const.

Snippets in suggestions

By default, VS Code shows snippets and completion proposals in one widget. You can control the behavior with the editor.snippetSuggestions setting. To remove snippets from the suggestions widget, set the value to 'none'. If you'd like to see snippets, you can specify the order relative to suggestions; at the top ('top'), at the bottom ('bottom'), or inline ordered alphabetically ('inline'). The default is 'inline'.

Key bindings

The key bindings shown below are the default key bindings. You can change these in your keybindings.json file as described in Key Bindings.

Note: There are many more key bindings relating to IntelliSense. Open the Default Keyboard Shortcuts (File > Preferences > Keyboard Shortcuts) and search for 'suggest'.

Troubleshooting

If you find IntelliSense has stopped working, the language service may not be running. Try restarting VS Code and this should solve the issue. If you are still missing IntelliSense features after installing a language extension, open an issue in the repository of the language extension.

Tip: For configuring and troubleshooting JavaScript IntelliSense, see the JavaScript documentation.

A particular language extension may not support all the VS Code IntelliSense features. Review the extension's README to find out what is supported. If you think there are issues with a language extension, you can usually find the issue repository for an extension through the VS Code Marketplace. Navigate to the extension's detail page and click the Support link.

Next steps

IntelliSense is just one of VS Code's powerful features. Read on to learn more:

Symbols

See also

Naturally speaking software. IntelliSense is a general term for various code editing features including: code completion, parameter info, quick info, and member lists. IntelliSense features are sometimes called by other names such as 'code completion', 'content assist', and 'code hinting.'

IntelliSense for your programming language

Visual Studio Code IntelliSense is provided for JavaScript, TypeScript, JSON, HTML, CSS, SCSS, and Less out of the box. VS Code supports word based completions for any programming language but can also be configured to have richer IntelliSense by installing a language extension.

Below are the most popular language extensions in the Marketplace. Click on an extension tile below to read the description and reviews to decide which extension is best for you.

IntelliSense features

VS Code IntelliSense features are powered by a language service. A language service provides intelligent code completions based on language semantics and an analysis of your source code. If a language service knows possible completions, the IntelliSense suggestions will pop up as you type. If you continue typing characters, the list of members (variables, methods, etc.) is filtered to only include members containing your typed characters. Pressing Tab or Enter will insert the selected member.

You can trigger IntelliSense in any editor window by typing ⌃Space (Windows, Linux Ctrl+Space) or by typing a trigger character (such as the dot character (.) in JavaScript).

Tip: The suggestions widget supports CamelCase filtering, meaning you can type the letters which are upper cased in a method name to limit the suggestions. For example, 'cra' will quickly bring up 'createApplication'.

If you prefer, you can turn off IntelliSense while you type. See Customizing IntelliSense below to learn how to disable or customize VS Code's IntelliSense features.

As provided by the language service, you can see quick info for each method by either pressing ⌃Space (Windows, Linux Ctrl+Space) or clicking the info icon. The accompanying documentation for the method will now expand to the side. The expanded documentation will stay so and will update as you navigate the list. You can close this by pressing ⌃Space (Windows, Linux Ctrl+Space) again or by clicking on the close icon.

After choosing a method you are provided with parameter info.

When applicable, a language service will surface the underlying types in the quick info and method signatures. In the image above, you can see several any types. Because JavaScript is dynamic and doesn't need or enforce types, any suggests that the variable can be of any type.

Types of completions

The JavaScript code below illustrates IntelliSense completions. IntelliSense gives both inferred proposals and the global identifiers of the project. The inferred symbols are presented first, followed by the global identifiers (shown by the Word icon).

VS Code IntelliSense offers different types of completions, including language server suggestions, snippets, and simple word based textual completions.

Methods and Functionsmethod, function, constructor
Variablesvariable
Fieldsfield
Type parameterstypeParameter
Constantsconstant
Classesclass
Interfacesinterface
Structuresstruct
Eventsevent
Operatorsoperator
Modulesmodule
Properties and Attributesproperty
Values and Enumerationsvalue, enum
Referencesreference
Keywordskeyword
Filesfile
Foldersfolder
Colorscolor
Unitunit
Snippet prefixessnippet
Wordstext

Customizing IntelliSense

You can customize your IntelliSense experience in settings and key bindings.

Settings

The settings shown below are the default settings. You can change these settings in your settings.json file as described in User and Workspace Settings.

Tab Completion

The editor supports 'tab completion' which inserts the best matching completion when pressing Tab. This works regardless of the suggest widget showing or not. Also, pressing Tab after inserting a suggestions will insert the next best suggestion.

By default, tab completion is disabled. Use the editor.tabCompletion setting to enable it. These values exist:

  • off - (default) Tab completion is disabled.
  • on - Tab completion is enabled for all suggestions and repeated invocations insert the next best suggestion.
  • onlySnippets - Tab completion only inserts static snippets which prefix match the current line prefix.

Locality Bonus

Sorting of suggestions depends on extension information and on how well they match the current word you are typing. In addition, you can ask the editor to boost suggestions that appear closer to the cursor position, using the editor.suggest.localityBonus setting.

In above images you can see that count, context, and colocated are sorted based on the scopes in which they appear (loop, function, file).

Suggestion selection

By default, VS Code pre-selects the previously used suggestion in the suggestion list. This is very useful as you can quickly insert the same completion multiple times. If you'd like different behavior, for example, always select the top item in the suggestion list, you can use the editor.suggestSelection setting.

The available editor.suggestSelection values are:

Xampp

  • first - Always select the top list item.
  • recentlyUsed - (default) The previously used item is selected unless a prefix (type to select) selects a different item.
  • recentlyUsedByPrefix - Select items based on previous prefixes that have completed those suggestions.

'Type to select' means that the current prefix (roughly the text left of the cursor) is used to filter and sort suggestions. When this happens and when its result differs from the result of recentlyUsed it will be given precedence.

When using the last option, recentlyUsedByPrefix, VS Code remembers which item was selected for a specific prefix (partial text). For example, if you typed co and then selected console, the next time you typed co, the suggestion console would be pre-selected. This lets you quickly map various prefixes to different suggestions, for example co -> console and con -> const.

Snippets in suggestions

By default, VS Code shows snippets and completion proposals in one widget. You can control the behavior with the editor.snippetSuggestions setting. To remove snippets from the suggestions widget, set the value to 'none'. If you'd like to see snippets, you can specify the order relative to suggestions; at the top ('top'), at the bottom ('bottom'), or inline ordered alphabetically ('inline'). The default is 'inline'.

Key bindings

The key bindings shown below are the default key bindings. You can change these in your keybindings.json file as described in Key Bindings.

Note: There are many more key bindings relating to IntelliSense. Open the Default Keyboard Shortcuts (File > Preferences > Keyboard Shortcuts) and search for 'suggest'.

Troubleshooting

If you find IntelliSense has stopped working, the language service may not be running. Try restarting VS Code and this should solve the issue. If you are still missing IntelliSense features after installing a language extension, open an issue in the repository of the language extension.

Tip: For configuring and troubleshooting JavaScript IntelliSense, see the JavaScript documentation.

A particular language extension may not support all the VS Code IntelliSense features. Review the extension's README to find out what is supported. If you think there are issues with a language extension, you can usually find the issue repository for an extension through the VS Code Marketplace. Navigate to the extension's detail page and click the Support link.

Next steps

IntelliSense is just one of VS Code's powerful features. Read on to learn more:

  • JavaScript - Get the most out of your JavaScript development, including configuring IntelliSense.
  • Node.js - See an example of IntelliSense in action in the Node.js walkthrough.
  • Debugging - Learn how to set up debugging for your application.
  • Creating Language extensions - Learn how to create extensions that add IntelliSense for new programming languages.

Common questions

Why am I not getting any suggestions?

This can be caused by a variety of reasons. First, try restarting VS Code. If the problem persists, consult the language extension's documentation. For JavaScript specific troubleshooting, please see the JavaScript language topic.

Why am I not seeing method and variable suggestions?

This issue is caused by missing type declaration (typings) files in JavaScript. You can check if a type declaration file package is available for a specific library by using the TypeSearch site. There is more information about this issue in the JavaScript language topic. For other languages, please consult the extension's documentation.

3/31/2021




broken image