dotnet / vscode-csharp

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

Syntax highlighting/colors for records does not work. #4211

Closed erichiller closed 3 years ago

erichiller commented 4 years ago

Issue Description

Syntax highlighting/colors for records does not work.

Steps to Reproduce

Create a dotnet 5 project. create a record, such as the below, I have included several positions/orders of records in the code, as well as one class for comparison

Expected Behavior

Coloration for record much like for class or struct, etc..

Actual Behavior

The output depends on the order, see how FooRecord3 moves and changes the output color.

image vs. image vs. image

The presence of { } curly braces seems to be the cause of the change. However, even with a curly braced record placed at the top, the highlighting is still inconsistent. Notice how public is colored in the record definition of FooRecord3 but not in the constructor as in FooClass nor is the keyword record displayed consistently in the 3 records included.

For a quick reproduction, here is the sample source


    public record FooRecord2(
        string param1,
        double param2,
        float param3,
        int param4,
        FooRecord param5,
        FooClass param6
    ) {
        public string SomeProperty { get; set; }
    }
    public record FooRecord(
        string param1,
        double param2,
        float param3,
        int param4,
        FooRecord param5,
        FooClass param6
    );

    public record FooRecord3 {
        public FooRecord3(
                string param1,
                double param2,
                float param3,
                int param4,
                FooRecord param5,
                FooClass param6
        ) {
            //nothing
        }
        public string SomeProperty { get; set; }
    }

    public class FooClass {
        public string SomeProperty { get; set; }

        public FooClass(
            string param1,
            double param2,
            float param3,
            int param4,
            FooRecord param5,
            FooClass param6
        ) {
            //empty
        }
    }

Note after pasting the source into this ticket, I notice that GitHub has syntax coloring issues as well with records.

OmniSharp log

Starting OmniSharp server at 11/17/2020, 5:19:31 AM
    Target: c:\Users\eric\dev\src\github.com\erichiller\mkmrk\mkmrk.sln

OmniSharp server started.
    Path: c:\Users\eric\.vscode\extensions\ms-dotnettools.csharp-1.23.6\.omnisharp\1.37.3\OmniSharp.exe
    PID: 13360

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 16.8.0 - "c:\Users\eric\.vscode\extensions\ms-dotnettools.csharp-1.23.6\.omnisharp\1.37.3\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to 'c:\Users\eric\.vscode\extensions\ms-dotnettools.csharp-1.23.6\.omnisharp\1.37.3\.msbuild\Current\Bin\MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 16.8.0 - "c:\Users\eric\.vscode\extensions\ms-dotnettools.csharp-1.23.6\.omnisharp\1.37.3\.msbuild\Current\Bin"
            CscToolExe = csc.exe
            CscToolPath = c:\Users\eric\.vscode\extensions\ms-dotnettools.csharp-1.23.6\.omnisharp\1.37.3\.msbuild\Current\Bin\Roslyn
            MSBuildExtensionsPath = c:\Users\eric\.vscode\extensions\ms-dotnettools.csharp-1.23.6\.omnisharp\1.37.3\.msbuild
            MSBuildToolsPath = c:\Users\eric\.vscode\extensions\ms-dotnettools.csharp-1.23.6\.omnisharp\1.37.3\.msbuild\Current\Bin
[info]: OmniSharp.Cake.CakeProjectSystem

C# log

none

Environment information

VSCode version: 1.51.1 C# Extension: 1.23.6

Dotnet Information .NET SDK (reflecting any global.json): Version: 5.0.100 Commit: 5044b93829 Runtime Environment: OS Name: Windows OS Version: 10.0.19042 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.100\ Host (useful for support): Version: 5.0.0 Commit: cf258a14b7 .NET SDKs installed: 3.1.102 [C:\Program Files\dotnet\sdk] 3.1.302 [C:\Program Files\dotnet\sdk] 3.1.401 [C:\Program Files\dotnet\sdk] 5.0.100 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.0 [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| |---|---|---| |better-align|wwm|1.1.6| |cpptools|ms-vscode|1.1.1| |csharp|ms-dotnettools|1.23.6| |docomment|k--kato|0.1.19| |erlang-otp|yuce|0.2.4| |errorlens|usernamehw|3.2.4| |githistory|donjayamanne|0.6.14| |gitignore|codezombiech|0.6.0| |graphql-for-vscode|kumar-harsh|1.15.3| |hexeditor|ms-vscode|1.3.0| |jsdoc-markdown-highlighting|bierner|0.0.1| |markdown-all-in-one|yzhang|3.4.0| |msbuild-project-tools|tintoy|0.3.10| |path-intellisense|christian-kohler|2.3.0| |powershell-preview|ms-vscode|2020.9.0| |rainbow-csv|mechatroner|1.7.1| |remote-ssh-edit|ms-vscode-remote|0.56.0| |remote-wsl|ms-vscode-remote|0.51.3| |selected-lines-count|gurumukhi|1.4.0| |sqltools|mtxr|0.23.0| |svg|jock|1.4.1| |template-string-converter|meganrogge|0.3.0| |theme-karyfoundation-themes|karyfoundation|20.0.3| |todo-tree|Gruntfuggly|0.0.188| |toml|be5invis|0.5.1| |unique-lines|bibhasdn|1.0.0| |vscode-docker|ms-azuretools|1.8.0| |vscode-eslint|dbaeumer|2.1.13| |vscode-great-icons|emmanuelbeziat|2.1.60| |vscode-json5|mrmlnc|1.0.0| |vscode-scss|mrmlnc|0.9.0| |vscode-scss-formatter|sibiraj-s|2.0.2| |vscode-solution-explorer|fernandoescolar|0.3.11| |vscode-yaml|redhat|0.12.0| |xml|DotJoshJohnson|2.5.1|;
filipw commented 4 years ago

you should enable semantic highlighting

"csharp.semanticHighlighting.enabled": true,
"editor.semanticHighlighting.enabled": true
JoeRobich commented 4 years ago

@erichiller Sematntic classification for Records was added for Roslyn 3.9.0-2 but we are still on 3.8.0. Once we move OmniSharp-Roslyn to a suitable Roslyn, we can add a new classification for Records. Thanks for logging. We will use this issue to track adding this.

filipw commented 4 years ago

Sematntic classification for Records was added for Roslyn 3.9.0-2 but we are still on 3.8.0.

Oh really? I would have sworn it worked, sorry for the confusion 🤔

Youssef1313 commented 4 years ago

@JoeRobich Is there something that blocks updating from 3.8.0 to 3.9.0-2 or higher?

Youssef1313 commented 4 years ago

Looks like it was already updated in https://github.com/OmniSharp/omnisharp-roslyn/pull/2022

NejcBW commented 3 years ago

I still experience this issue with the extension version 1.23.8.

When I want to inspect editor scopes O# logs the following error:

{ "Request_seq": 945, "Command": "/v2/highlight", "Running": true, "Success": false, "Message": "\"System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.\r\n at System.ThrowHelper.ThrowKeyNotFoundException()\r\n at System.Collections.Generic.Dictionary2.get_Item(TKey key)\\r\\n at OmniSharp.Roslyn.CSharp.Services.SemanticHighlight.SemanticHighlightService.CreateSemanticSpan(IEnumerable1 results, TextLineCollection lines) in D:\\a\\1\\s\\src\\OmniSharp.Roslyn.CSharp\\Services\\SemanticHighlight\\SemanticHighlightService.cs:line 72\r\n at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()\\r\\n at System.Linq.Buffer1..ctor(IEnumerable1 source)\\r\\n at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)\r\n at OmniSharp.Roslyn.CSharp.Services.SemanticHighlight.SemanticHighlightService.d1.MoveNext() in D:\\a\\1\\s\\src\\OmniSharp.Roslyn.CSharp\\Services\\SemanticHighlight\\SemanticHighlightService.cs:line 53\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at OmniSharp.Endpoint.EndpointHandler`2.d19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at OmniSharp.Endpoint.EndpointHandler2.<HandleRequestForLanguage>d__20.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 230\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Endpoint.EndpointHandler2.d16.MoveNext() in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 131\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at OmniSharp.Stdio.Host.d13.MoveNext() in D:\\a\\1\\s\\src\\OmniSharp.Stdio\\Host.cs:line 215\"", "Body": null, "Seq": 17467, "Type": "response" }

fasetto commented 3 years ago

Any updates on this ? I have same issue.

filipw commented 3 years ago

this was already merged into OmniSharp and released 3 days ago https://github.com/OmniSharp/omnisharp-roslyn/releases

it will be consumed in the next release of the C# extension for VS Code

cc: @JoeRobich

karl-sjogren commented 3 years ago

This one seems to have been fixed for a while (early february) so this could be closed now right?

filipw commented 3 years ago

yes, thanks

onionhammer commented 3 years ago

@filipw this should be reopened, unless this is how it is supposed to look (v1.23.11)

image

filipw commented 3 years ago

do you have semantic highlighting enabled? if so, and it still happens, then please open a new bug with the file that reproduces this - there could be some specific positioning/alignment of symbols that results in this behavior.

onionhammer commented 3 years ago

@filipw Thanks, enabling that works; but shouldnt this be considered a bug if omnisharp on default settings doesnt highlight a standard C# record?

filipw commented 3 years ago

this is up to @JoeRobich to judge 🙂

Also, it's not an OmniSharp issue really - the OmniSharp server only provides semantic highlighting, the "regular" highlighting is based on static textmate grammar which is part of VS Code itself and is maintained here https://github.com/dotnet/csharp-tmLanguage

Youssef1313 commented 3 years ago

Opened https://github.com/dotnet/csharp-tmLanguage/issues/202