-
-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple highlighting improvements #506
Merged
DaelonSuzuka
merged 1 commit into
godotengine:master
from
DaelonSuzuka:highlighting_improvements
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,25 +132,51 @@ | |
"end": "'''" | ||
}, | ||
{ | ||
"begin": "\"", | ||
"begin": "(r)?\"\"\"", | ||
"end": "\"\"\"", | ||
"patterns": [ | ||
{ | ||
"name": "constant.character.escape.untitled", | ||
"match": "\\\\." | ||
} | ||
], | ||
"beginCaptures": { | ||
"1": { | ||
"name": "constant.character.escape.untitled" | ||
} | ||
}, | ||
"name": "string.quoted.triple.gdscript" | ||
}, | ||
{ | ||
"begin": "(r)?\"", | ||
"end": "\"", | ||
"patterns": [ | ||
{ | ||
"name": "constant.character.escape.untitled", | ||
"match": "\\\\." | ||
} | ||
], | ||
"beginCaptures": { | ||
"1": { | ||
"name": "constant.character.escape.untitled" | ||
} | ||
}, | ||
"name": "string.quoted.double.gdscript" | ||
}, | ||
{ | ||
"begin": "'", | ||
"begin": "(r)?'", | ||
"end": "'", | ||
"patterns": [ | ||
{ | ||
"name": "constant.character.escape.untitled", | ||
"match": "\\\\." | ||
} | ||
], | ||
"beginCaptures": { | ||
"1": { | ||
"name": "constant.character.escape.untitled" | ||
} | ||
}, | ||
"name": "string.quoted.single.gdscript" | ||
}, | ||
{ | ||
|
@@ -309,37 +335,41 @@ | |
"name": "keyword.operator.assignment.gdscript" | ||
}, | ||
"control_flow": { | ||
"match": "\\b(?i:if|elif|else|for|while|break|continue|pass|return|match|yield|await)\\b", | ||
"match": "\\b(?:if|elif|else|for|while|break|continue|pass|return|match|yield|await)\\b", | ||
"name": "keyword.control.gdscript" | ||
}, | ||
"keywords": { | ||
"match": "\\b(?i:class|class_name|extends|is|onready|tool|static|export|as|void|enum|preload|assert|breakpoint|rpc|sync|remote|master|puppet|slave|remotesync|mastersync|puppetsync|trait|namespace)\\b", | ||
"match": "\\b(?:class|class_name|extends|is|onready|tool|static|export|as|void|enum|preload|assert|breakpoint|rpc|sync|remote|master|puppet|slave|remotesync|mastersync|puppetsync|trait|namespace)\\b", | ||
"name": "keyword.language.gdscript" | ||
}, | ||
"letter": { | ||
"match": "\\b(?i:true|false|null)\\b", | ||
"match": "\\b(?:true|false|null)\\b", | ||
"name": "constant.language.gdscript" | ||
}, | ||
"numbers": { | ||
"patterns": [ | ||
{ | ||
"match": "\\b(?i:0x\\h*)\\b", | ||
"match": "\\b(?:0b[01_]+)\\b", | ||
"name": "constant.numeric.integer.binary.gdscript" | ||
}, | ||
{ | ||
"match": "\\b(?:0x[0-9A-Fa-f_]+)\\b", | ||
"name": "constant.numeric.integer.hexadecimal.gdscript" | ||
}, | ||
{ | ||
"match": "\\b(?i:(\\d+\\.\\d*(e[\\-\\+]?\\d+)?))\\b", | ||
"match": "\\b(?:([0-9_]+\\.[0-9_]*(e[\\-\\+]?[0-9_]+)?))\\b", | ||
"name": "constant.numeric.float.gdscript" | ||
}, | ||
{ | ||
"match": "\\b(?i:(\\.\\d+(e[\\-\\+]?\\d+)?))\\b", | ||
"match": "\\b(?:(\\.[0-9_]+(e[\\-\\+]?[0-9_]+)?))\\b", | ||
"name": "constant.numeric.float.gdscript" | ||
}, | ||
{ | ||
"match": "\\b(?i:(\\d+e[\\-\\+]?\\d+))\\b", | ||
"match": "\\b(?:([0-9_]+e[\\-\\+]?\\[0-9_]))\\b", | ||
"name": "constant.numeric.float.gdscript" | ||
}, | ||
{ | ||
"match": "\\b\\d+\\b", | ||
"match": "\\b[0-9_]+\\b", | ||
"name": "constant.numeric.integer.gdscript" | ||
} | ||
] | ||
|
@@ -494,6 +524,9 @@ | |
}, | ||
"builtin_get_node_shorthand": { | ||
"patterns": [ | ||
{ | ||
"include": "#builtin_get_nodepath_shorthand_quoted" | ||
}, | ||
{ | ||
"include": "#builtin_get_node_shorthand_quoted" | ||
}, | ||
|
@@ -502,6 +535,30 @@ | |
} | ||
] | ||
}, | ||
"builtin_get_nodepath_shorthand_quoted": { | ||
"begin": "(&|\\^|@)([\"'])", | ||
"end": "([\"'])", | ||
"name": "support.function.builtin.shorthand.gdscript", | ||
"beginCaptures": { | ||
"1": { | ||
"name": "variable.other.enummember" | ||
}, | ||
"2": { | ||
"name": "constant.character.escape" | ||
} | ||
}, | ||
"endCaptures": { | ||
"1": { | ||
"name": "constant.character.escape" | ||
} | ||
}, | ||
"patterns": [ | ||
{ | ||
"match": "[^%^\"^']*", | ||
"name": "constant.character.escape" | ||
} | ||
] | ||
}, | ||
"builtin_get_node_shorthand_quoted": { | ||
"begin": "(\\$)([\"'])", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Godot 4 also accepts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. |
||
"end": "([\"'])", | ||
|
@@ -531,7 +588,7 @@ | |
] | ||
}, | ||
"builtin_get_node_shorthand_bare": { | ||
"begin": "(\\$)", | ||
"begin": "(\\$|%)", | ||
"end": "[^\\w%]", | ||
"name": "support.function.builtin.shorthand.gdscript", | ||
"beginCaptures": { | ||
|
@@ -541,12 +598,15 @@ | |
}, | ||
"patterns": [ | ||
{ | ||
"match": "[a-zA-Z_]\\w*/?", | ||
"name": "constant.character.escape" | ||
}, | ||
{ | ||
"match": "%[a-zA-Z_]\\w*/?", | ||
"name": "invalid.illegal.escape.gdscript" | ||
"match": "(%)?([a-zA-Z_]\\w*/?)", | ||
"captures": { | ||
"1": { | ||
"name": "keyword.control.flow" | ||
}, | ||
"2": { | ||
"name": "constant.character.escape" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not right to allow
_
to intermix with numbers unconditionally. Cases like_0
are valid variable identifiers, and must not be colored like number literals. This regex need to be carefully thought out and tested, because adding the_
separator feature is not that simple. You need to ensure:_
cannot appear at the beginning, or right aftere
in floats orx
in hex literals_
should not appear at the end, but it seems Godot allows it; better confirm this properly to know how to go about this__
is not allowedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On this particular line it would probably be enough to use"\\b\\d[0-9_]*\\b"
if you won't forbid trailing_
. On float and hex literals it'd probably be similar.EDIT: Nevermind, forgot about the consecutive __. Yeah, this needs to be thought out properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not interested in completely validating numeric literals with the grammar. Invalid cases should get marked as syntax errors by the LSP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair for invalid cases that aren't valid for other rules with less priority. But I believe valid variable names like
_0
,_0e0
,_0x0
will be taken over by this rule and be incorrectly colored as numbers. At the bare minimum, these regexes gotta exclude the initial_
by using something like\d[0-9_]*
instead of[0-9_]+
.But if you don't mind me completely validating it, the ideal would be:
int:
"\\b\\d+(?:_\\d+)*\\b"
hex:
"\\b0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*\\b"
bin:
"\\b0b[01]+(?:_[01]+)*\\b"
float1:
"\\b\\d+(?:_\\d+)*\\.(?:\\d+(?:_\\d+)*)?(?:[eE][-+]?\\d+(?:_\\d+)*)?\\b"
float2:
"\\.\\d+(?:_\\d+)*(?:[eE][-+]?\\d+(?:_\\d+)*)?\\b"
float3:
"\\b\\d+(?:_\\d+)*[eE][-+]?\\d+(?:_\\d+)*\\b"
This should also fix:
[eE]
exponent which can be uppercase too\\
part of\\d+
on line 338->368 wasn't removed.
(non-word character) so it must not be preceded by a\b
word boundarySorry for writing this in a comment instead of making a PR or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I'm with you now; I misunderstood the problem.
I'll add some new test cases and then pop in your rules. Thanks for writing them up.
No worries at all. Your second set of eyes has always been a big help.