36

I have installed the C# extension in VS Code. The problem I am having is, after using a code snippet prop, Intellisense no longer suggests variable types. This happens with other things like ctor as well, it will not autocomplete the class name, for example.

I have tried uninstalling/reinstalling the extension. I have Googled without luck as well.

I expect for Intellisense to suggest variable types, for example. Intellisense does not suggest anything.

Hitting Ctrl+. does suggest the correct fix among the list.

Edit: My project does not have a project.json or *.sln file. I created the project using the command line dotnet new webapi. If that is what is required, how do I add it or get Intellisense working?

Mark
  • 143,421
  • 24
  • 428
  • 436
Richie
  • 427
  • 1
  • 5
  • 10

4 Answers4

75

By default, intellisense / quick suggestions will not be triggered inside of a snippet. To enable them set

"editor.suggest.snippetsPreventQuickSuggestions": false

true is the default.

Editor > Suggest: Snippets Prevent Quick Suggestions in the Settings UI.

starball
  • 20,030
  • 7
  • 43
  • 238
Mark
  • 143,421
  • 24
  • 428
  • 436
  • 5
    this can backfire. if Intellisense suggests something and you click `tab` to go to the next snippet place, it will complete the suggestion. E.g. `for` snippet; typing `i` as variable; Intellisense suggestion:`int`; click `tab`; `int` inserted. But to avoid this, click `escape` before `tab` (**only if Intellisense prompted**) – Superior Nov 09 '19 at 09:58
  • 1
    @Superior Why does visual studio not have this problem? Why can't vs code provide the same experience as visual studio? – huang Aug 16 '20 at 10:59
  • @JokeHuang Why is that question directed towards me? I don't know – Superior Aug 16 '20 at 14:29
  • @Superior isn't there a setting to enable tab to trigger the suggestion if the dropdown is displayed and go to the next snippet placeholder otherwise ? – gruvw May 08 '21 at 07:42
  • @Gruvw yes, one posted in this answer. I just said that, to remove the dropdown, you have to click `escape` – Superior May 08 '21 at 09:29
  • @Superior for me, when I click tab, it does not complete the suggestion but it will go to the next snippet placeholder even though the suggestion menu is displayed – gruvw May 08 '21 at 09:34
4

Mark answered the question above. If he is able to come back I'll accept his answer.

File > Preferences > Settings

Search for editor.suggest.snippetsPreventQuickSuggestions.

Make sure the box is unchecked.

Thanks Mark!

Richie
  • 427
  • 1
  • 5
  • 10
1

I got the same error and I solved it with this configuration:

enter image description here

Klian
  • 1,520
  • 5
  • 21
  • 32
0

Visual Studio Code's more advanced editing features (IntelliSense, refactoring tools, etc.) only work in C# files if you have a project.json file or *.sln file that VSCode is aware of.

Open the folder (i.e. open the File menu and click Open Folder...) with the *.sln file or project.json and VSCode will attempt to find all project/solution files in the folder.

If there are multiple projects, you may need to select one from the projects button on the right side of the status bar (bottom of the window).

From the VSCode website:

Selecting a project.json-file is opening a DNX-project and VSCode will load that project plus the referenced projects

Selecting a *.sln-file is opening a MSBuild-project. It will load the referenced *.csproj-projects and sibling or descendant project.json-files but no other project files that are referenced from the solution file.

Selecting a folder will make VSCode scan for *.sln and project.json files and VSCode will attempt to load them all.

Community
  • 1
  • 1
  • I editing the original question. I do not have a project.json or *.sln file. – Richie Apr 15 '19 at 06:08
  • Which IntelliSense extension you are using? If not try to download Visual Studio IntelliCode –  Apr 15 '19 at 06:37