Visual Studio Code C# Intellisense



C# for Visual Studio Code (powered by OmniSharp)

First written on 2020-09-11.Last updated on 2021-01-02. In this article and several more, I will be discussing developing a very simple C library and application using CMake and Visual Studio Code. I have found the solution thanks to this video on how to Set Up C Development With Visual Studio Code on Windows 10 (VS Code). I launched MinGW Installation Manager and installed all the package from the Basic Setup. I added the path of the gcc compiler to my system´s environment variables: C: MinGW bin, in which is the gcc.exe. C# for Visual Studio Code (powered by OmniSharp) Welcome to the C# extension for Visual Studio Code! This extension provides the following features inside VS Code: Lightweight development tools for.NET Core. Great C# editing support, including Syntax Highlighting, IntelliSense, Go to Definition, Find All References, etc.

The Microsoft C/C for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion. Visual Studio for Mac doesn't support Microsoft C, but does support.NET languages and cross-platform development. For installation instructions, see Install Visual Studio for Mac.

Welcome to the C# extension for Visual Studio Code! This extension provides the following features inside VS Code:

  • Lightweight development tools for .NET Core.
  • Great C# editing support, including Syntax Highlighting, IntelliSense, Go to Definition, Find All References, etc.
  • Debugging support for .NET Core (CoreCLR). NOTE: Mono debugging is not supported. Desktop CLR debugging has limited support.
  • Support for project.json and csproj projects on Windows, macOS and Linux.

The C# extension is powered by OmniSharp.

Get Started Writing C# in VS Code

Note about using .NET Core 3.1.40x SDKs

The .NET 3.1.40x SDKs require version 16.7 of MSBuild.

For MacOS and Linux users who have Mono installed, this means you will need to set omnisharp.useGlobalMono to never until a version of Mono ships with MSBuild 16.7.

Note about using .NET 5 SDKs

The .NET 5 SDK requires version 16.8 of MSBuild.

For Windows users who have Visual Studio installed, this means you will need to be on the latest Visual Studio 16.8 Preview.For MacOS and Linux users who have Mono installed, this means you will need to set omnisharp.useGlobalMono to never until a version of Mono ships with MSBuild 16.8.

What's new in 1.23.11

  • Move the global Mono check to the correct place (#4489, PR: #4492)

What's new in 1.23.10

  • Support solution filters (*.slnf) (PR: #4481)
  • Prompt user to install Blazor WASM companion extension if needed (PR: #4392)
  • Add path to dotnet so child processes can use the CLI (PR: #4459)
  • Give more information when Mono is missing or invalid. (#4428, PR: #4431)
  • Revert incremental change forwarding (PR: #4477)
  • Fixes to asset generation (PR: #4402)
  • Add properties to blazorwasm debug configuration. (dotnet/aspnetcore#30977, PR: i#4445)
  • Avoid white status bar items to ensure contrast (#4384, PR: #4385)
  • Update OmniSharp to 1.37.8
    • Update Roslyn version to 3.10.0-1.21125.6 (PR: omnisharp-roslyn#2105)
    • Update included build tools to closely match NET 6 Preview 1 SDK (PR: omnisharp-roslyn#2103)
    • Improve custom error messages for MSB3644 (PR: omnisharp-roslyn#2097)
    • Do not call FindReferencesAsync for null symbol (omnisharp-roslyn#2054, PR: omnisharp-roslyn#2089)
    • use an OmniSharp specific message for MSB3644 (omnisharp-roslyn#2029, PR: omnisharp-roslyn#2069)
    • changed the default RunFixAllRequest timeout to 10 seconds (PR: omnisharp-roslyn#2066)
    • Support Solution filter (.slnf) (PR: omnisharp-roslyn#2121)
    • updated to IL Spy 7.0.0.6372 (PR: omnisharp-roslyn#2113)
    • Add sentinel file to MSBuild to enable workload resolver (#4417, PR: omnisharp-roslyn#2111)
    • fixed CS8605 'Unboxing possibly null value' (PR: omnisharp-roslyn#2108)
  • Updated Razor support (PR: #4470)
    • Bug fixes

What's new in 1.23.9

  • Add option to organize imports during document formatting. (PR: #4302)
  • Update to use zero based indexes (PR: #4300)
  • Improve request queues to improve code completion performance (PR: #4310)
  • Add setting to control whether to show the OmniSharp log on error (#4102, #4330, PR: #4333)
  • Support building launch assets for NET6-NET9 projects (#4346, PR: #4349)
  • Add debugger support for Concord extensions. See the ConcordExtensibilitySamples wiki for more information.
  • Update OmniSharp version to 1.37.6
    • Handle records in syntax highlighting (#2048, PR: #2049)
    • Remove formatting on new line (PR: #2053)
    • Validate highlighting ranges in semantic highlighting requests (PR: #2055)
    • Delay project system init to avoid solution update race (PR: #2057)
    • Use 'variable' kind for parameter completion (#2060, PR: #2061)
    • Log request when response fails (#2064)

What's new in 1.23.8

  • Updated Debugger support (PR: #4281)
    • Updated the version of .NET that the debugger uses for running its own C# code to .NET 5
    • Updated .NET debugging services loader to address problem with debugging after installing XCode12 (dotnet/runtime/#42311)
    • Fixed integrated terminal on non-Windows (#4203)
  • Updated Razor support (PR: #4278)
    • Bug fixes
  • Update OmniSharp version to 1.37.5 (PR: #4299)
    • Update Roslyn version to 3.9.0-2.20570.24 (PR: omnisharp-roslyn#2022)
    • Editorconfig improvements - do not lose state, trigger re-analysis on change (omnisharp-roslyn#1955, #4165, #4184, PR: omnisharp-roslyn#2028)
    • Add documentation comment creation to the FormatAfterKeystrokeService (PR: omnisharp-roslyn#2023)
    • Raise default GotoDefinitionRequest timeout from 2s to 10s (#4260, PR: omnisharp-roslyn#2032)
    • Workspace create file workaround (PR: omnisharp-roslyn#2019)
    • Added msbuild:UseBundledOnly option to force the usage of bundled MSBuild (PR: omnisharp-roslyn#2038)
  • Support auto doc comment generation (#8, PR: #4261)
  • Add schema support for appsettings.json (#4279, PR: #4280)
  • Add schema support for global.json (PR: #4290)
  • Update remoteProcessPickerScript windows ssh exit (#3482, PR: #4225)
  • Do not start OmniSharp server in Live Share scenarios (#3910, PR: #4038)
  • Suppress codelens for IEnumerable.GetEnumerator (#4245, PR: #4246)
  • Allow arm64 MacOS to debug dotnet projects (#4277, PR: #4288)

Emmet support in Razor files

To enable emmet support, add the following to your settings.json:

Semantic Highlighting

The C# semantic highlighting support is in preview. To enable, set editor.semanticHighlighting.enabled and csharp.semanticHighlighting.enabled to true in your settings. Semantic highlighting is only provided for code files that are part of the active project.

To really see the difference, try the new Visual Studio 2019 Light and Dark themes with semantic colors that closely match Visual Studio 2019.

Supported Operating Systems for Debugging

  • Currently, the C# debugger officially supports the following operating systems:

    • X64 operating systems:
      • Windows 7 SP1 and newer
      • macOS 10.12 (Sierra) and newer
      • Linux: see .NET Core documentation for the list of supported distributions. Note that other Linux distributions will likely work as well as long as they include glibc and OpenSSL.
    • ARM operating systems:
      • Linux is supported as a remote debugging target

Found a Bug?

To file a new issue to include all the related config information directly from vscode by entering the command pallette with Ctrl+Shift+P(Cmd+Shift+P on macOS) and running CSharp: Report an issue command. This will open a browser window with all the necessary information related to the installed extensions, dotnet version, mono version, etc. Enter all the remaining information and hit submit. More information can be found on the wiki.

Alternatively you could visit https://github.com/OmniSharp/omnisharp-vscode/issues and file a new one.

Development

First install:

  • Node.js (8.11.1 or later)
  • Npm (5.6.0 or later)

To run and develop do the following:

  • Run npm i
  • Run npm run compile
  • Open in Visual Studio Code (code .)
  • Optional: run npm run watch, make code changes
  • Press F5 to debug

To test do the following: npm run test or F5 in VS Code with the 'Launch Tests' debug configuration.

License

Copyright © .NET Foundation, and contributors.

The Microsoft C# extension is subject to these license terms.The source code to this extension is available on https://github.com/OmniSharp/omnisharp-vscode and licensed under the MIT license.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenantto clarify expected behavior in our community.For more information see the .NET Foundation Code of Conduct.

Contribution License Agreement

By signing the CLA, the community is free to use your contribution to .NET Foundation projects.

.NET Foundation

This project is supported by the .NET Foundation.

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.

Visual Studio Code Download

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).

Visual Studio Code C# Intellisense

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:

  • 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.

Visual Studio Code Intellisense Not Working

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.

Visual Studio Code C# Autocomplete

3/31/2021