dotnet / csharp-tmLanguage

Syntax grammar used for C# colorization
MIT License
68 stars 34 forks source link

Grammar breaks after less-than check when not surrounded by parentheses #295

Closed alexr00 closed 11 months ago

alexr00 commented 11 months ago

Details

What editor are you seeing the problem in? (e.g. Atom, Visual Studio Code, etc.)

VS Code

What version of the editor are you using?

1.83, which has commit 525e628edad54c0f7aa15b015310df240803ea66 from this repo

What color theme are you using?

Issue occurs regardless of color theme

Repro

image

    public void nextPage()
    {
        if (!setPage(tabs[currentTab].currentPage + 1))
        {
            int lastTab = tabs.Length - 1;
            if (currentTab < lastTab && setTabWithoutUpdate(currentTab + 1))
            {
                if (!setPage(0))
                    updateItems();
            }
        }
    }
    public void prevPage()
    {
        if (!setPage(tabs[currentTab].currentPage - 1))
        {
            if (currentTab > 0 && setTabWithoutUpdate(currentTab - 1))
            {
                int lastPage = Math.Max(currentItems.Count - 1, 0) / 6;
                if (!setPage(lastPage))
                    updateItems();
            }
        }
    }

Line currentTab < lastTab && setTabWithoutUpdate(currentTab + 1) is not parsed correctly and syntax highlighting breaks after it. Adding useless brackets around (currentTab < lastTab) fixes this particular issue but there are other issues. Highlight for certain keywords changed for no reason (such as class, var, etc.). This happens with and without extensions enabled, this is purely base syntax highlighting built into VS Code.

Originally posted by @DemonikGH in https://github.com/microsoft/vscode/issues/195098

alexr00 commented 11 months ago

👋 I manage pulling updates from dotnet/csharp-tmLanguage to microsoft/vscode for the C# grammar. For now, I'm going to set VS Code back to use commit 772323937fedd65c6dc1c8ce6ea41d97415ed7d1, which was the last version we released with that didn't have this issue.

wise0704 commented 11 months ago

I suspect #273 is causing this regression.

Edit: interesting find. This seems to be a regex performance issue? Only happens at a certain length after <. image

wise0704 commented 11 months ago

... Highlight for certain keywords changed for no reason (such as class, var, etc.). This happens with and without extensions enabled, this is purely base syntax highlighting built into VS Code.

This is unrelated. Keyword scopes have been changed to follow the standards/conventions, and are thus compatible with existing themes. Refer to

for the detailed changes.