dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.91k stars 4.01k forks source link

Syntax highlight breaks down for # right before an interpolated hole: $"#{foo}" #58637

Open Sergio0694 opened 2 years ago

Sergio0694 commented 2 years ago

Version Used: VS2022 17.0.2

Steps to Reproduce:

  1. Paste the following code:
_ = $"#{42}";

Expected Behavior:

The # character should be colored in orange like other normal characters in the interpolated expression.

Actual Behavior:

The # character is colored in gray, like a preprocessor directive:

image

Builds and works just fine at runtime, it's just a visual glitch in the syntax highlight.

CyrusNajmabadi commented 2 years ago

Weird. not repro-ing for me:

image

Youssef1313 commented 2 years ago

Just tried and couldn't repro as well.

Sergio0694 commented 2 years ago

Mmmh I wonder if this might be the JetBrains Mono font, as I can see it's using a ligature there? 🤔 Though why should a custom font possibly mess with the syntax highlight colors?

jinujoseph commented 2 years ago

cc @olegtk for info

olegtk commented 2 years ago

@gundermanc, @veler, this is interesting, do ligatures affect classification?

veler commented 2 years ago

Not AFAIK

sharwell commented 2 years ago

@veler We're specifically interested in the case where a ligature is formed from two characters which independently have two different classifications. For this case, either the ligature needs to be avoided or the ligature characters needs to be rendered with multiple colors.

Sergio0694 commented 2 years ago

Ideally it would be great if the ligature could just be skipped entirely here, as having #{ be merged makes no sense in C# anyway (or at least, here specifically) 🤔

Sergio0694 commented 1 year ago

@CyrusNajmabadi @Youssef1313 Just managed to find another repro for this, happens with vanilla VS 17.4.3:

class Repro
{
    private static int _number;

    public void Problem()
    {
        Console.WriteLine($"Hello #{_number}");
    }
}

Results in:

Youssef1313 commented 1 year ago

image

I think the font you are using is different than mine. So it may be related to the font being used.

Sergio0694 commented 1 year ago

Yeah, I have more info. I can't repro with Consolas and Cascadia Mono. With Cascadia Code I get the same result as you (both # and { are orange). In my screenshot, I'm using JetBrains Mono. So it does seem the specific font affects the syntax highlight 🤔

Youssef1313 commented 1 year ago

I'm not sure, but this might not be a roslyn issue. More likely in VS editor (internal).

PJB3005 commented 1 year ago

Yeah uh, something is very wrong if Roslyn even has a concept of font families in the first place.

This just looks like VS failing to break ligatures if the characters have mismatching colors, and thus rendering incorrectly.

CyrusNajmabadi commented 1 year ago

@olegtk to decide if you guys want to do anything here. Def not a Roslyn issue.

olegtk commented 1 year ago

yeah, it's a bug in the VS editor. @Sergio0694, would you mind reporting this via Help > Send Feedback > Report a Problem ? This way we will get publicly visible feedback ticket others can also vote on and comment. We would like to see more votes before we invest into fixing this, unfortunately it looks pretty complicated as we don't have much control over ligature rendering in WPF.