Skip to content

Conversation

Copy link

Copilot AI commented Dec 8, 2025

TextMate grammars support a comment field on rules for documentation purposes. This field was being parsed but not exposed to consumers, making it inaccessible to tools like VS Code's scope inspector.

Changes

Type System

  • Added optional comment field to IRawRule interface
  • Added scopeComments: (string | null)[] to IToken interface, parallel to existing scopes array

Rule Storage

  • Updated Rule base class and all subclasses (CaptureRule, MatchRule, IncludeOnlyRule, BeginEndRule, BeginWhileRule) to store and expose comments via getComment() method
  • Modified RuleFactory to extract comment field from grammar rules during compilation

Scope Stack

  • Extended ScopeStack to track scopeComment alongside scopeName, added getComments() method
  • Updated AttributedScopeStack.pushAttributed() to accept and propagate comment parameter
  • For multi-scope pushes (space-separated scopes), comment is assigned to first scope only

Tokenization

  • Modified tokenization logic to retrieve comments from rules and pass through pushAttributed() calls
  • Token creation now includes scope comments array matching scope hierarchy

Example

// Grammar with comments
{
  "match": "\\b(hello)\\b",
  "name": "keyword.test",
  "comment": "Matches the hello keyword"
}

// Resulting token
{
  scopes: ["source.test", "keyword.test"],
  scopeComments: [null, "Matches the hello keyword"]
}

Comments default to null when not present, maintaining backward compatibility.

Original prompt

This section details on the original issue you should resolve

<issue_title>Expose scope comment in IToken</issue_title>
<issue_description>There's a feature request in VS Code to include grammar scope comments in microsoft/vscode#206192. First, the scope comments need to be exposed in IToken in vscode-textmate. </issue_description>

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 3 commits December 8, 2025 11:30
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
Copilot AI changed the title [WIP] Expose scope comment in IToken for vscode-textmate Expose scope comments in IToken Dec 8, 2025
Copilot AI requested a review from alexr00 December 8, 2025 11:40
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.

Expose scope comment in IToken

2 participants