Skip to content

Support multiple inline and block comment styles per language - #664

Draft
Giulia Stocco (gfs) with Copilot wants to merge 3 commits into
mainfrom
copilot/add-multiple-block-comment-support
Draft

Giulia Stocco (gfs) with Copilot wants to merge 3 commits into
mainfrom
copilot/add-multiple-block-comment-support

Conversation

Copilot AI commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Some languages have more than one kind of comment — Razor supports @* *@, <!-- --> and /* */, Terraform supports #, // and /* */. The comment model allowed exactly one inline marker and one block prefix/suffix pair per language, and commented-state detection searched backwards for that single marker, so it could neither express nor correctly pair these cases.

Configuration format (backward compatible)

  • comments.json entries accept inlines (extra single line markers) and blocks (extra prefix/suffix pairs) alongside the existing inline/prefix/suffix.
  • Multiple entries matching the same language are now aggregated rather than first-match-wins.
{
  "language": [ "razor" ],
  "inline": "//",
  "blocks": [
    { "prefix": "@*",   "suffix": "*@" },
    { "prefix": "<!--", "suffix": "-->" },
    { "prefix": "/*",   "suffix": "*/" }
  ]
}

Languages

  • New GetCommentInlines(language) / GetCommentBlocks(language) return every style.
  • GetCommentInline/GetCommentPrefix/GetCommentSuffix are retained and return the first style.

TextContainer comment scanning

  • Commented state is now computed by scanning content forward (lazily, up to the requested index, cached in the existing CommentedStates map) instead of searching backwards from the query index for one known prefix. Ordering makes pairing correct by construction:
    • a block comment is only terminated by the suffix paired with the prefix that opened it — @* <!-- *@ ends at *@, not at -->;
    • markers inside an existing comment don't open a new one;
    • block markers are matched before inline markers and longest-first, so /* isn't read as //.
  • The "marker inside a quoted string isn't a comment" heuristic is preserved, now via sequential quote tracking (with escape handling) rather than per-line quote counting.
  • ScopeMatch's "language has no block comments → all scopes match" shortcut is unchanged in behavior, keyed off the block list being empty.

Default data

  • terraform: #, //, /* */ (previously had no comment definition, so comment scoping was inoperative).
  • html: <!-- -->.
  • New razor language for .razor (a previously unmapped extension, so additive) with the three block styles above.
  • .cshtml deliberately stays mapped to html; remapping it would silently drop html-targeted rules, which is the sub-language rule inheritance problem tracked in Paired language rules? #662.

Tests

  • MultipleCommentStylesTests covers razor block pairing (including cross-style markers and unterminated comments), terraform multi-inline comments, and the new Languages accessors.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI and others added 2 commits September 15, 2026 22:16
Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for multiple kinds of block comment pairs Support multiple inline and block comment styles per language Sep 15, 2026
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.

Some languages support multiple kinds of block comment pairs

2 participants