Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

Syntax highlighting breaks for all code following a constructor when the opening parenthesis is placed on a new line:

public class TestClass
{
    public TestClass
    (
        string s
    )
    {
    }

    public void Method()  // All highlighting lost from here onwards
    {
    }
}

Root cause: The constructor-declaration pattern used a lookahead (?=identifier\s*\() that only matched when both the constructor name and ( were on the same line. When split across lines, property-declaration matched instead, consuming the identifier and breaking subsequent parsing.

Changes:

  • Reordered class-or-struct-members patterns to check constructor-declaration before property-declaration and field-declaration
  • Changed constructor pattern from (?=@?[_[:alpha:]][_[:alnum:]]*\s*\() to (@?[_[:alpha:]][_[:alnum:]]*)\s*(?=\(|$) to match identifiers at end-of-line
  • Moved identifier capture from internal match to beginCaptures for cleaner pattern structure

The pattern now matches when the identifier is followed by ( on the same line OR at end-of-line, with the actual ( matched by the subsequent parenthesized-parameter-list include.

Original prompt

This section details on the original issue you should resolve

<issue_title>Syntax highlighting breaks with newline in constructor</issue_title>
<issue_description>Issue originally posted at dotnet/vscode-csharp#4190

Issue Description

Syntax highlighting fails for methods after constructor if the parenthesis are moved to a new line.

Steps to Reproduce

  1. Write a constructor with at least one parameter.
  2. Now format it so the opening parenthesis is in the next line.
  3. Now add a method after the constructor.

Expected Behavior

The lines after the constructor should have correct syntax highlighting.
image

Actual Behavior

All text is white.
image

Logs

OmniSharp log

DetailsPost the output from Output-->OmniSharp log here

C# log

DetailsPost the output from Output-->C# here

Environment information

VSCode version: 1.50.1
C# Extension: 1.23.5

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.301 Commit: 7feb845744

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.301\

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

.NET Core SDKs installed:
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.502 [C:\Program Files\dotnet\sdk]
2.1.503 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
3.1.301 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

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

Visual Studio Code Extensions
Extension Author Version
atlascode atlassian 2.8.3
cpptools ms-vscode 1.1.0
csharp ms-dotnettools 1.23.5
debugger-for-chrome msjsdiag 4.12.11
docomment k--kato 0.1.18
git-easy bibhasdn 1.11.0
git-graph mhutchie 1.27.0
gitlens eamodio 10.2.3
hexeditor ms-vscode 1.3.0
remote-wsl ms-vscode-remote 0.50.1
vscode-drawio hediet 1.0.3
vscode-eslint dbaeumer 2.1.13
vscode-language-pack-es MS-CEINTL 1.50.2
vscode-markdownlint DavidAnson 0.37.2
vscode-yaml redhat 0.12.0

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@JoeRobich JoeRobich marked this pull request as ready for review December 19, 2025 22:39
Copilot AI changed the title [WIP] Fix syntax highlighting after constructor with new line Fix constructor highlighting when opening parenthesis on new line Dec 19, 2025
Copilot AI requested a review from JoeRobich December 19, 2025 22:40
@JoeRobich JoeRobich merged commit 2e35d8d into main Dec 19, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Syntax highlighting breaks with newline in constructor

3 participants