dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.88k stars 676 forks source link

Setting `csharp.semanticHighlighting.enabled` to true breaks syntax highlighting for base classes and attributes #5016

Open Trottero opened 2 years ago

Trottero commented 2 years ago

Issue Description

Setting csharp.semanticHighlighting.enabled to true breaks syntax highlighting for base classes and attributes. This causes it to show up as a class definition, when in many themes it should have its own distinct color. Issue was tested on both the stable and insiders versions of vscode, log submitted is from insiders build.

Setting csharp.semanticHighlighting.enabled to false fixes the issue regarding base classes and attributes, but it also removes functionality such as highlighting for parameters which I prefer to be on.

Issue does not occur instantly when starting VSCode, I can't get an exact timeframe but it seems to be linked to the analyzers loading.

Steps to Reproduce

See screenshots below

Expected Behavior

Screenshots retrieved by setting csharp.semanticHighlighting.enabled to false

Monokai theme image

Github dark theme image

Actual Behavior

csharp.semanticHighlighting.enabled to true

Monokai theme image

Github dark theme image

Logs

OmniSharp log

Starting OmniSharp server at 21/01/2022, 15:33:32 Target: c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.sln OmniSharp server started. Path: c:\Users\wrlxs\.vscode-insiders\extensions\ms-dotnettools.csharp-1.24.0\.omnisharp\1.38.0\OmniSharp.exe PID: 1788 [info]: OmniSharp.Stdio.Host Starting OmniSharp on Windows 6.2.9200.0 (x64) [info]: OmniSharp.Services.DotNetCliService Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK [info]: OmniSharp.Services.DotNetCliService Using the 'dotnet' on the PATH. [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 1 MSBuild instance(s) 1: StandAlone 17.0.0 - "c:\Users\wrlxs\.vscode-insiders\extensions\ms-dotnettools.csharp-1.24.0\.omnisharp\1.38.0\.msbuild\Current\Bin" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator MSBUILD_EXE_PATH environment variable set to 'c:\Users\wrlxs\.vscode-insiders\extensions\ms-dotnettools.csharp-1.24.0\.omnisharp\1.38.0\.msbuild\Current\Bin\MSBuild.exe' [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: StandAlone 17.0.0 - "c:\Users\wrlxs\.vscode-insiders\extensions\ms-dotnettools.csharp-1.24.0\.omnisharp\1.38.0\.msbuild\Current\Bin" CscToolExe = csc.exe CscToolPath = c:\Users\wrlxs\.vscode-insiders\extensions\ms-dotnettools.csharp-1.24.0\.omnisharp\1.38.0\.msbuild\Current\Bin\Roslyn MSBuildExtensionsPath = c:\Users\wrlxs\.vscode-insiders\extensions\ms-dotnettools.csharp-1.24.0\.omnisharp\1.38.0\.msbuild MSBuildToolsPath = c:\Users\wrlxs\.vscode-insiders\extensions\ms-dotnettools.csharp-1.24.0\.omnisharp\1.38.0\.msbuild\Current\Bin [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110 [info]: OmniSharp.WorkspaceInitializer Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140 [info]: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in 'c:\Users\wrlxs\source\repos\sero-quattuor'. [info]: OmniSharp.Cake.CakeProjectSystem Did not find any Cake files [info]: OmniSharp.MSBuild.ProjectSystem Detecting projects in 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.sln'. [info]: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.api\sero-quattuor.api.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.business\sero-quattuor.business.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.sockets\sero-quattuor.sockets.csproj' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in 'c:\Users\wrlxs\source\repos\sero-quattuor'. [info]: OmniSharp.Script.ScriptProjectSystem Did not find any CSX files [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location 'c:\Users\wrlxs\source\repos\sero-quattuor' on host 10112. [info]: OmniSharp.MSBuild.ProjectManager Loading project: c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.api\sero-quattuor.api.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.api\sero-quattuor.api.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.api\sero-quattuor.api.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.business\sero-quattuor.business.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.business\sero-quattuor.business.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.business\sero-quattuor.business.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.sockets\sero-quattuor.sockets.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.sockets\sero-quattuor.sockets.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.sockets\sero-quattuor.sockets.csproj' [info]: OmniSharp.MSBuild.ProjectManager Update project: sero-quattuor.api [info]: OmniSharp.MSBuild.ProjectManager Found referenced project outside root directory: c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.core\sero-quattuor.core.csproj [info]: OmniSharp.MSBuild.ProjectManager Adding project 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.core\sero-quattuor.core.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.core\sero-quattuor.core.csproj' [info]: OmniSharp.MSBuild.ProjectManager Found referenced project outside root directory: c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.data\sero-quattuor.data.csproj [info]: OmniSharp.MSBuild.ProjectManager Adding project 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.data\sero-quattuor.data.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.data\sero-quattuor.data.csproj' [info]: OmniSharp.MSBuild.ProjectManager Update project: sero-quattuor.business [info]: OmniSharp.MSBuild.ProjectManager Update project: sero-quattuor.sockets [info]: OmniSharp.MSBuild.ProjectManager Loading project: c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.core\sero-quattuor.core.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.core\sero-quattuor.core.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Loading project: c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.data\sero-quattuor.data.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file 'c:\Users\wrlxs\source\repos\sero-quattuor\sero-quattuor.data\sero-quattuor.data.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Update project: sero-quattuor.core [info]: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll [info]: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll [info]: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\wrlxs\.nuget\packages\microsoft.entityframeworkcore.analyzers\5.0.11\analyzers\dotnet\cs\Microsoft.EntityFrameworkCore.Analyzers.dll [info]: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.1\analyzers\dotnet\cs\System.Text.Json.SourceGeneration.dll [info]: OmniSharp.MSBuild.ProjectManager Update project: sero-quattuor.data [info]: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll [info]: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll [info]: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\wrlxs\.nuget\packages\microsoft.entityframeworkcore.analyzers\6.0.1\analyzers\dotnet\cs\Microsoft.EntityFrameworkCore.Analyzers.dll [info]: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Users\wrlxs\.nuget\packages\microsoft.extensions.logging.abstractions\6.0.0\analyzers\dotnet\roslyn4.0\cs\Microsoft.Extensions.Logging.Generators.dll [info]: OmniSharp.OmniSharpWorkspace Adding analyzer reference: C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.1\analyzers\dotnet\cs\System.Text.Json.SourceGeneration.dll Received response for /v2/getcodeactions but could not find request. Received response for /completion but could not find request.

C# log

Installing C# dependencies... Platform: win32, x86_64 Finished

Environment information

VSCode version: 1.64.0-insider C# Extension: 1.24.0

Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.101 Commit: ef49f6213a Runtime Environment: OS Name: Windows OS Version: 10.0.22000 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.101\ Host (useful for support): Version: 6.0.1 Commit: 3a25a7f1cc .NET SDKs installed: 6.0.101 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |csharp|ms-dotnettools|1.24.0| |github-vscode-theme|GitHub|5.1.0|;

Code

using Microsoft.AspNetCore.Mvc;

namespace sero_quattuor.api.Controllers;

[ApiController]
[Route("token")]
public class TokenController : ControllerBase
{

}

Csproj

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <IsPackable>false</IsPackable>
    <RootNamespace>sero_quattuor.api</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1" />
  </ItemGroup>
</Project>
gabrieldechichi commented 2 years ago

+1 same issue here (and thanks for the workaround). Really hope this gets fixed.

H3NRILiN commented 2 years ago

I have the same problem here😥

Before Omnisharp loaded : image We still can see the color they should have.

After : image Some colors are gone

I solve them by downgrade the version to 1.23.17

tyler-brandt commented 2 years ago

Same exact issue here.

Before omnisharp loaded (or before 1.24 release, or with semantic highlighting disabled): image

After omnisharp 1.24 loads: image

JoeRobich commented 2 years ago

The Roslyn classifier does not distinguish between "class name - declaration" and "class name - usage". This is a loss from the C# textmate grammar. However, the Roslyn semantic classification will always fully support new language features.

As a workaround you can disable "csharp.enableSemanticHighlighting" in your VS Code settings.

filipw commented 2 years ago

see Roslyn issue for the background discussion https://github.com/dotnet/roslyn/issues/36327 and a similar discussion for VS for Mac https://github.com/mono/monodevelop/issues/4506

we won't be able to support this until it's part of Roslyn so I think this issue can be closed as not possible to implement

Trottero commented 2 years ago

see Roslyn issue for the background discussion dotnet/roslyn#36327 and a similar discussion for VS for Mac mono/monodevelop#4506

we won't be able to support this until it's part of Roslyn so I think this issue can be closed as not possible to implement

Both issues linked are from a couple of years ago, has the situation not improved since then?

snax4a commented 2 years ago

Im having same issue, it was working in previous versions. I would prefer not to disable semantic highlighting

gregharding commented 2 years ago

I just hit this issue when updating to 1.24 - nearly every word in C# files is either underlined or a different colour.

Like others above, I disabled "csharp.enableSemanticHighlighting" in both workspace and user to clean things up again. Also, the settings in VSCode say "Defaults to false" but both of these settings seem to default to true, and setting them to false highlights blue as a changed setting. I had to set both workspace and user settings to false to return to sanity.

Update: Omnisharp 1.24.1 is back to underlining classes, attributes, etc. that is really cluttering things up when using the Monokai theme. Is there any way to disable the constant underlining everywhere or is this entirely theme related?

I have edited my settings.json to include "editor.tokenColorCustomizations" scoped to the [Monokai] theme to declutter things. If anyone else is interested here's a snippet to remove underlines for types (classes, attributes);

"editor.tokenColorCustomizations": { "[Monokai]": { "textMateRules": [ { "name": "Remove type underline", "scope": "entity.name.type", "settings": { "fontStyle": "" } } ] }, }