vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

[BUG] Using the C# extension pre-release looses semantics colors

Open dibarbet opened this issue 3 years ago • 10 comments

From vscode-dotnettools created by Samuel-Therrien-Beslogic: microsoft/vscode-dotnettools#183

Describe the Issue

Current stable version: image

Pre-release version (needed for C# dev kit): image

Steps To Reproduce

  1. Install C# language support extension, non-prerelease, see colored code
  2. Install C# Dev Kit and C# (prerelease) extensions
  3. Reload window, see colored code for a second
  4. Most of the code looses its semantic colors

Expected Behavior

As before

Environment Information

  • OS: 10.0.22621 Build 22621
  • VSCode: 1.76.1 (user setup)
  • ms-dotnettools.csharp: v2.0.212
  • ms-dotnettools.csdevkit: v0.1.103
  • ms-dotnettools.vscodeintellicode-csharp: v0.1.9
  • ms-dotnettools.vscode-dotnet-runtime: v1.6.0

VSCode settings:

{
  "[csharp]": {
    "editor.defaultFormatter": "ms-dotnettools.csharp"
  },
  "csharp.format.enable": false,
  "csharp.referencesCodeLens.enabled": true,
  "csharp.semanticHighlighting.enabled": true,
  "omnisharp.autoStart": true,
  // Should be disabled for Unity
  "omnisharp.useModernNet": false,
  "omnisharp.enableEditorConfigSupport": true,
  "omnisharp.enableRoslynAnalyzers": true,
  "omnisharp.organizeImportsOnFormat": true,
  "dotnet.implementType.insertionBehavior": "atTheEnd",
  // Must be disabled if using the C# Dev Kit
  "dotnet.server.useOmnisharp": false
}

dibarbet avatar Jun 22 '23 18:06 dibarbet

Moving to "area-roslyn" for the initial investigation.

dibarbet avatar Jun 22 '23 18:06 dibarbet

@Samuel-Therrien-Beslogic a couple of requests

  1. Could you verify that the solution is loaded (the project should show up in the solution explorer pane, and in the bottom left corner of vscode you should see a 'Projects' line with the number of projects) projects

  2. Can you let me know which theme you're using?

  3. Could you run the Inspect Editor Tokens and Scopes command on the GetComponent in your screenshot and send me a screenshot? image

This does look kind of like a unity project which isn't supported by C# devkit. If that is the case, I'm guessing that the project is not loading and therefore the server can't colorize the code correctly.

dibarbet avatar Jun 22 '23 18:06 dibarbet

I am experiencing the same issue. here is my screenshot of a function that looses its highligting and i am unable to go to defenition or implementation. My solution is loaded and i have "Projects: 5" as loaded projects, which is correct.

My solution has .net web api and 4x class libaries. everything using net7.0

image

egillben avatar Jun 22 '23 21:06 egillben

@egillben would you mind filing a separate issue? If you could as well, please set the setting dotnet.server.trace to Trace image

reload the window, run the scenario and include the logs from 'C#' in the output window on the issue? image

That will help us track down what is going on. Based on your description it sounds like devkit is loading the project successfully, but that information isn't flowing into the language server correctly so you end up losing all semantic info. Definitely a bug we need to figure out.

dibarbet avatar Jun 22 '23 21:06 dibarbet

Same issue here. I described it in: #5853

enizvk avatar Jun 28 '23 06:06 enizvk

I've noticed you need to have a .sln file for the highlighting to work.

With the current omnisharp you don't need a .sln, it works fine with just a .csproj.

Could this be related?

tbsuper avatar Jun 29 '23 22:06 tbsuper

For me it seems it is two issues we experience with the same effect.

  1. When, for a reason, the LSP restarts, it places all source files into the 'Miscellaneous' files workspace. It can be easily reproduced, just invoke the 'Restart Language Server' command. Restarting vscode helps to restore original behavior.
  2. Is a different issue and is a little longer to explain: First, the whole thing did not work for me along with getting a warning message saying 'not enough file system watchers to watch changes in this large workspace'. I was pointless, I has only 40 files in the workspace. Nevertheless, I increased the number of watchers (from the default ~8000 to ~25000) and it began to work. Then I looked on what is eating up the watchers and found this:
   WATCHES      PER   
    COUNT     PROCESS   PID USER         COMMAND
------------------------------------------------------------
   17589         2       10940 george      /usr/share/code/code --type=utility --utility-sub-type=node.mojom.NodeService --lang=en-US --service-sandbox-type=none --crashpad-handler-pid=10268 --enable-crash-reporter=a490274b-efaa-4f6f-9006-45938b273e00,no_channel --user-data-dir=...

And it turns out that for my solution which is lost semantic coloring and all intellisense recently, this watcher was missing completely. Even if a source file is 'found in workspace host' (in this case not in the miscellaneous), neither the semantic coloring or Intellisense worked.

Deleting bin and obj, open an another project and then switching back to the problematic one helped to restore the desired state, now the watcher is in place and coloring and intellisense works.

Unfortunately, I could not find for neither case any hint in the logs what is went wrong.

sarosigy avatar Jun 30 '23 08:06 sarosigy

When, for a reason, the LSP restarts, it places all source files into the 'Miscellaneous' files workspace. It can be easily reproduced, just invoke the 'Restart Language Server' command. Restarting vscode helps to restore original behavior.

Yup, I've verified this before in a couple of other related issues. For now I'd recommend using the 'reload window' command instead. I've filed https://github.com/dotnet/vscode-csharp/issues/5882 to track

And it turns out that for my solution which is lost semantic coloring and all intellisense recently, this watcher was missing completely. Even if a source file is 'found in workspace host' (in this case not in the miscellaneous), neither the semantic coloring or Intellisense worked.

Yeah - the missing file watchers is a symptom of the issue - essentially what is happening is that devkit is sometimes failing to send the C# extension all of the project's metadata references (nuget packages, core lib, etc). Without those references we're not creating all the valid file watchers. This is tracked by https://github.com/microsoft/vscode-dotnettools/issues/210

Deleting bin and obj, open an another project and then switching back to the problematic one helped to restore the desired state, now the watcher is in place and coloring and intellisense works.

This is good info, thanks. I'll update the devkit issue.

dibarbet avatar Jun 30 '23 17:06 dibarbet

Closing this issue - the original reported issue seems to be a Unity project which (as a legacy style project) we don't currently load in devkit.

The other intellisense issues with projects that load successfully are tracked in https://github.com/microsoft/vscode-dotnettools/issues/210

dibarbet avatar Jul 05 '23 21:07 dibarbet

For Unity ,I set 'dotnet. server. useOmnisharp' to true,this looks like there are highlights and intelligent prompts

AnthonyJu avatar Aug 03 '23 04:08 AnthonyJu