简体   繁体   English

Visual Studio代码IntelliSense建议不会自动弹出

[英]Visual Studio Code IntelliSense suggestions don't pop up automatically

I followed the install instructions in https://code.visualstudio.com , but when I write C# code, the IntelliSense suggestions don't pop up automatically, so I must trigger it by using shortcut Command+Space , meanwhile, the suggestions are just from the code I wrote. 我按照https://code.visualstudio.com中的安装说明进行操作,但是当我编写C#代码时,IntelliSense建议不会自动弹出,所以我必须使用快捷键Command+Space触发它,同时,建议是只是从我写的代码。

Here is the screen capture below: 以下是屏幕截图:

在此输入图像描述

I checked in https://code.visualstudio.com/Docs/editingevolved , VSCode do support C# IntelliSense. 我检查了https://code.visualstudio.com/Docs/editingevolved,VSCode支持C#IntelliSense。

I don't think it is bug, maybe I did something wrong when installing VSCode. 我认为这不是bug,也许我在安装VSCode时做错了。 How to solve this problem? 如何解决这个问题呢?

To activate IntelliSense on a .NET project: 要在.NET项目上激活IntelliSense:

  1. Open project folder: File->Open folder... 打开项目文件夹:文件 - >打开文件夹...
  2. Click on the flame on your bottom left corner, pick your project 点击左下角的火焰,选择你的项目 点击火焰
  3. IntelliSense activated! IntelliSense已激活! IntelliSense现已激活!

From what I've seen, IntelliSense cannot be activated on a .cs file alone. 从我看到的情况来看,无法单独在.cs文件上激活IntelliSense。 (See @natemcmaster's answer). (见@ natemcmaster的回答)。

OmniSharp doesn't know where your project files are. OmniSharp不知道项目文件的位置。 In your screenshot, the left sidebar says "You have not opened a folder". 在屏幕截图中,左侧边栏显示“您尚未打开文件夹”。 OmniSharp will look in your currently opened folder for project files. OmniSharp将在您当前打开的文件夹中查找项目文件。

  1. Add your folder. 添加您的文件夹。 File > Open Folder... 文件>打开文件夹...
  2. Make sure you have a project file (either project.json or your *.csproj files). 确保您有一个项目文件(project.json或您的* .csproj文件)。

This should be enough for OmniSharp to start providing you Intellisense. 这应该足以让OmniSharp开始为您提供Intellisense。

You just have to pick up the language type from the bar at the bottom (the button with the flame). 您只需从底部的栏中选择语言类型(带火焰的按钮)。

像这样

Try changing the editor.quickSuggestions setting to true in the settings.json file. 尝试在settings.json文件中将editor.quickSuggestions设置更改为true The settings file may be found in: 设置文件可以在以下位置找到:

Windows: %APPDATA%\\Code\\User\\settings.json Windows:%APPDATA%\\ Code \\ User \\ settings.json

Mac: $HOME/Library/Application Support/User/settings.json Mac:$ HOME / Library / Application Support / User / settings.json

Linux: $HOME/.config/Code/User/settings.json Linux:$ HOME / .config / Code / User / settings.json

In my case the problem was that I had 2 versions installed. 在我的情况下,问题是我安装了2个版本。 I was launching from the command prompt and it kept running the older version. 我从命令提示符启动,它继续运行旧版本。 In Programs and Features, I removed the one that didn't have "(user)" at the end of the application name, and when I opened Code again, it started downloading packages, one of which was OmniSharp, and then IntelliSense started working. 在程序和功能中,我删除了应用程序名称末尾没有“(user)”的那个,当我再次打开Code时,它开始下载软件包,其中一个是OmniSharp,然后IntelliSense开始工作。

Note that I was also getting the following warning when opening the older version, and searching for the warning led me to instructions on removing the other version, which in turn fixed the IntelliSense problem: 请注意,在打开旧版本时,我也收到以下警告,并且搜索警告让我获得了删除其他版本的说明,这反过来修复了IntelliSense问题:

You are running the system-wide installation of Code, while having the user-wide distribution installed as well. 您正在运行系统范围的Code安装,同时也安装了用户范围的分发。 Make sure you're running the Code version you expect. 确保您运行的是您期望的Code版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM