godotengine / godot-vscode-plugin

Godot development tools for VSCode

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for '##' comments grammar scope (for themes)

GustJc opened this issue · comments

Godot version

4.2.2.stable

VS Code version

1.87.0

Godot Tools VS Code extension version

v2.0.0

System information

Windows 10

Problem statement

Could it be possible to add a different scope for the double sharp comments?
I'm trying to replicate 1-to-1 the theme from Godot into VSCode. (based on godot-vscode-theme)

But it seems the scope for # commentsand ## comments are the same.
In Godot, the double symbol comments have a slight different color. I'd like to achieve that with a theme.

Here's the comment grammar location

"comment": {
"match": "(#).*$\\n?",
"name": "comment.line.number-sign.gdscript",
"captures": { "1": { "name": "punctuation.definition.comment.number-sign.gdscript" } }
},

Proposed solution

I've never worked with this, but possibly adding a new grammar entry like:
Edit:
This works, it can differentiate single and double comments

Adding base_pattern

{ "include": "#comment_double" },

And

"comment": {
	"match": "(#(?!#)).*$\\n?",
	"name": "comment.line.number-sign.gdscript",
	"captures": { "1": { "name": "punctuation.definition.comment.number-sign.gdscript" } }
},
"comment_double": {
	"match": "(##).*$\\n?",
	"name": "comment.line.number-sign-double.gdscript",
	"captures": { "1": { "name": "punctuation.definition.comment.number-sign.gdscript" } }
},

Edit2:
I've been able to colorize the double comments, and add TODO/FIXME colored keywords inside comments with grammar injections with the theme plugin.

Here are some of the keypoints.
I replaced the 'comment' from using match regex to begin/end

	"repository": {
		"comment": {
			"begin": "#(?!#)",
			"end": "$",
			"name": "comment.line.number-sign.gdscript",
			"beginCaptures": { "1": { "name": "punctuation.definition.comment.number-sign.gdscript" } }
		},
		"comment_double": {
			"name": "comment.line.double-number-sign.gdscript",
			"begin": "##",
			"end": "$"
		}
	}

Changed the "comment" to use the "Begin/End" regex instead of "Match"
so it could inject TODO/FIXME scopes inside comments. It wouldn't work when comments were using match.

{
	"injectionSelector": "L:comment.line",
	"scopeName": "comment-keywords.injection",
	"patterns": [
	  {"include": "#todo_keywords" }
	],
	"repository": {
		"todo_keywords": {
			"name": "comment.keywords.todo.gdscript",
			"match": "TODO|FIXME"
		}
	}
  }

The other missing color I found is the global vs local function color.
But that is a way more complicated problem that I'm not sure how to solve.
I think it needs a custom semantic token for that.