dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 670 forks source link

Wrong syntax highlighting when using `await using` #3914

Open gidoca opened 4 years ago

gidoca commented 4 years ago

When creating a simple file that uses the await using construct, syntax highlighting is broken below the point where it is used. For example, keywords like public are no longer displayed in dark blue, see screenshot below. This is a simple example code:

using System;
using System.Threading.Tasks;

namespace vscode_await_using_bug
{
    class Program : IAsyncDisposable
    {
        static async Task Main(string[] args)
        {
            await using (var v = new Program())
            {
                Foo();
            }
        }

        public async ValueTask DisposeAsync()
        {
            await Task.Delay(50);
            Console.WriteLine("Byebye");
        }

        public static void Foo()
        {
            Console.WriteLine("Hello World!");
        }
    }
}

Environment data

dotnet --info output: .NET Core SDK (reflecting any global.json): Version: 3.1.301 Commit: 7feb845744

Runtime Environment: OS Name: ubuntu OS Version: 20.04 OS Platform: Linux RID: linux-x64 Base Path: /usr/share/dotnet/sdk/3.1.301/

Host (useful for support): Version: 3.1.5 Commit: 65cd789777

.NET Core SDKs installed: 3.1.301 [/usr/share/dotnet/sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

VS Code version: 1.47.1

C# Extension version: 1.22.1

OmniSharp log

Starting OmniSharp server at 7/16/2020, 5:33:04 PM Target: /home/gidoca/src/vscode-await-using-bug

OmniSharp server started. Path: /home/gidoca/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/run PID: 264088

    Starting OmniSharp on ubuntu 20.4 (x64)
    DotNetPath set to dotnet
    Located 1 MSBuild instance(s)
        1: StandAlone 16.4 - "/home/gidoca/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin"
    MSBUILD_EXE_PATH environment variable set to '/home/gidoca/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin/MSBuild.dll'
    Registered MSBuild instance: StandAlone 16.4 - "/home/gidoca/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin"
        CscToolExe = csc.exe
        MSBuildToolsPath = /home/gidoca/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin
        CscToolPath = /home/gidoca/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin/Roslyn
        BypassFrameworkInstallChecks = true
        MSBuildExtensionsPath = /home/gidoca/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild
    Detecting Cake files in '/home/gidoca/src/vscode-await-using-bug'.
    Could not find any Cake files
    No solution files found in '/home/gidoca/src/vscode-await-using-bug'
    Detecting CSX files in '/home/gidoca/src/vscode-await-using-bug'.
    Could not find any CSX files
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
    Configuration finished.
    Omnisharp server running using Stdio at location '/home/gidoca/src/vscode-await-using-bug' on host 263959.

Steps to reproduce

Expected behavior

The syntax highlight is the same as synchronous using. image

Actual behavior

The syntax highlighting no longer marks keywords correctly. using is yellow, public and static are light blue. image

JoeRobich commented 4 years ago

@gidoca To workaround some of the limitations of our C# textmate theme, you can enable editor.semanticHighlighting.enabled and csharp.semanticHighlighting.enabled. It required using a theme that supports semantic highlight. You can try our Visual Studio 2019 Dark theme if you like, or you can tell VS Code that you current theme supports semanticHighlighting by following the instructions here (https://github.com/microsoft/vscode/issues/92740#issuecomment-600100176) to update your "editor.tokenColorCustomizations".