dotnet / vscode-csharp

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

C# syntax highlighting is broken after a particular string format string #3718

Open Funbit opened 4 years ago

Funbit commented 4 years ago

Issue Description

C# syntax highlighting is broken after a particular string format string (but works fine in Visual Studio 2019).

Steps to Reproduce

This line makes C# parser go crazy: return $"{firstDate:MMMMdd[HH:mm}-{lastDate:HH:mm}]";

Expected Behavior

C# syntax highlighting should continue to work after the above line.

Actual Behavior

C# syntax highlighting gets broken after the mentioned line (i.e. starting from the "async Task ClearDatabaseAsync" line it looks strange): image

Logs

Environment information

VSCode version: 1.44.0 C# Extension: 1.21.16

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.201 Commit: b1768b4ae7 Runtime Environment: OS Name: Windows OS Version: 10.0.18363 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.201\ Host (useful for support): Version: 3.1.3 Commit: 4a9f85e9f8 .NET Core SDKs installed: 3.1.201 [C:\Program Files\dotnet\sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |bash-ide-vscode|mads-hartmann|1.8.0| |cpptools|ms-vscode|0.27.0| |csharp|ms-dotnettools|1.21.16| |debugger-for-chrome|msjsdiag|4.12.6| |hg|mrcrowl|1.3.0| |json-tools|eriklynd|1.0.2| |markdown-all-in-one|yzhang|2.8.0| |material-icon-theme|PKief|4.0.1| |plantuml|jebbs|2.13.6| |powershell|ms-vscode|2020.3.0| |remote-wsl|ms-vscode-remote|0.42.4| |rest-client|humao|0.23.2| |rust|rust-lang|0.7.0| |trailing-spaces|shardulm94|0.3.1| |vscode-base64|adamhartford|0.1.0| |vscode-raml|blzjns|3.0.1| |vscode-yaml|redhat|0.7.2|;
JoeRobich commented 4 years ago

@Funbit Please try out the semantic highlighting in our 1.21.19-beta1 release.

Funbit commented 4 years ago

Unfortunately, the latest beta does not fix the issue. The highlighting is still incorrect:

image

JoeRobich commented 4 years ago

@Funbit, Did you follow the instructions to enable semantic highlight? That was the part that I expected to resolve your issue.

JoeRobich commented 4 years ago

Tested locally and it is much improved with semantic highlight enabled. I did find that I haven't setup the scope for the punctuation token properly. Will get this fixed before 1.21.19 releases.

image

Funbit commented 4 years ago

Hmm, this is strange.. The semantic highlighting is enabled in the settings: image But does not seem to be really applied. I tried to reopen .cs file and restart VSCode, no changes. Is there anything I forgot to change/enable? image

JoeRobich commented 4 years ago

@Funbit Sorry I will make sure it is more clear in the release notes. You also need to set csharp.semanticHighlighting.enabled to true for the time being since we consider the semantic highlight in the C# extension as experimental.

Funbit commented 4 years ago

This is really strange. If I open settings.json, the enabled flag is already set to true (because I set it via UI, as shown on the screenshot I posted above):

image

I tried to switch it to false then true again, but I didn't help :( I will try again later on the clean VSCode installation, to exclude any extension/settings interference, will post the results.

Funbit commented 4 years ago

Clean VSCode produces the same results.. enabled flag is true, but semantic highlighting does not seem to be really enabled. Just in case: I use 1.21.19-beta1 version from the VSIX file.

JoeRobich commented 4 years ago

@funbit I apologize. I misread your screenshot earlier and thought you had set editor.semanticHighlighting.enabled to true. Are both settings set?

Funbit commented 4 years ago

No problem. But unfortunately setting editor.semanticHighlighting.enabled to true did not help :( To be sure, I'm testing everything in a clean VM with clean VSCode, the settings.json file looks like this:

image

The only installed plugin is the "C#" 1.21.19:

image

Here is the editor screenshot:

image

And here is the full PoC source code, just in case:

namespace Test
{
    public partial class MainForm : Form
    {               
        string GetGroupName()
        {
            var firstDate = System.DateTime.Now;
            var lastDate = System.DateTime.Now;
            return $"{firstDate:MMMMdd [HH:mm}-{lastDate:HH:mm}]";
        }

        async Task ClearDatabaseAsync()
        {
            using (var faceClient = CreateFaceClient())
            {
                var largeGroups = await faceClient.LargePersonGroup.ListAsync();
            }
        }
    }
}

Am I missing something? 🤷

PS. Of course, I could just swap the last two chars }] to get ]} to fix this particular highlighting issue, but since VS 2019 (+R#) does render it correctly, it just feels wrong that VS Code does not. So, please, help me find out the problem 🙏

Funbit commented 4 years ago

Just in case, the issue is still reproducable :(