Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

  • Understand the issue: Line comments after preprocessor directives consume end-of-line, preventing preprocessor end pattern from matching
  • Create a new comment pattern specifically for preprocessor directives that doesn't consume the end-of-line marker
  • Update the preprocessor pattern to use the new comment pattern instead of the general #comment
  • Revert incorrect end pattern change from previous attempt
  • Remove unnecessary CS pattern support (not required for fix)
  • Add test case for #pragma warning disable with inline comment followed by code on next line
  • Run tests to verify the fix works (878 tests passing)
  • Run full test suite to ensure no regressions
  • Code review feedback addressed
Original prompt

This section details on the original issue you should resolve

<issue_title>Line comments right after preprocessor directives break highlighting.</issue_title>
<issue_description>Consider the following snippet:

public class Foo
{
    void Bar()
    {
#pragma warning disable CS0000 // Internal compiler error
        var x = Baz(1, 2, 3, out object error);
#pragma warning restore CS0000 // Internal compiler error
    }
}

We have a preprocessor directive, a line comment on the same line, and some code right on the next line (not very unusual in real-world code). The line after the directive gets weirdly highlighted:

Image

This does not happen we remove the line comment, or add a blank line or block comment after the directive. It also happens if we add some more line comments in the lines between the directive and the code.

From what I saw, the whole line belongs to textmate scopes meta.preprocessor.cs, source.cs. Maybe that happens because the line comment consumes the end of line, and the directive cannot match (?<=$)?</issue_description>

<agent_instructions>Be sure to include a test for this scenario.</agent_instructions>

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.

Copilot AI and others added 5 commits December 19, 2025 21:46
- Created preprocessor-comment pattern that doesn't consume end-of-line marker
- Updated preprocessor and preprocessor-if-or-elif to use new pattern
- Added test case for pragma warning with inline comment followed by code

Co-authored-by: JoeRobich <[email protected]>
The previous fix incorrectly changed the end pattern. The correct fix is to change the comment pattern to not consume the end-of-line marker.

Co-authored-by: JoeRobich <[email protected]>
Copilot AI changed the title [WIP] Fix line comments highlighting after preprocessor directives Fix preprocessor directive highlighting when followed by line comments Dec 19, 2025
Copilot AI requested a review from JoeRobich December 19, 2025 21:53
Reverted the (?:CS)? changes as they were not necessary for the core fix

Co-authored-by: JoeRobich <[email protected]>
@JoeRobich JoeRobich marked this pull request as ready for review December 19, 2025 21:59
@JoeRobich JoeRobich merged commit 891fc35 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.

Line comments right after preprocessor directives break highlighting.

3 participants