-
-
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
Multiple highlighting improvements #506
Conversation
Will this fix the |
Is |
"name": "constant.character.escape" | ||
} | ||
] | ||
}, | ||
"builtin_get_node_shorthand_quoted": { | ||
"begin": "(\\$)([\"'])", |
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.
Godot 4 also accepts %"..."
and %'...'
quoted syntax.
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.
Good catch.
|
"name": "constant.numeric.float.gdscript" | ||
}, | ||
{ | ||
"match": "\\b\\d+\\b", | ||
"match": "\\b[0-9_]+\\b", |
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- consecutive
__
is not allowed
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.
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- a typo where the
\\
part of\\d+
on line 338->368 wasn't removed - float2 starts with
.
(non-word character) so it must not be preceded by a\b
word boundary
Sorry 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.
... other rules with less priority. But I believe valid variable names like _0, _0e0, _0x0 will be taken over by this rule ...
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.
Sorry for writing this in a comment instead of making a PR or something.
No worries at all. Your second set of eyes has always been a big help.
Ah I see, so it's a new feature.
I've never used this r-string before, but if I understood correctly, it seems some care needs to be taken about the internal patterns, because I believe nothing inside should be colored like an escape character. It would probably need a separate rule(s). Otherwise it can be misleading and people won't understand the difference in the syntax. For example, in |
Makes sense. I was just making sure they were highlighted at all.
Wait a second, are triple single quotes valid in Godot 4? IIRC they're illegal in Godot 3 and I have them marked as such. |
I think I took those screenshots with this PR, not
Why would this matter? |
I think LSP can affect some highlighting behaviour IIRC |
It could, if the Godot LSP supported semantic tokenization, but it doesn't. |
Triple single quotes for multiline strings have always been allowed, even in Godot 1.0. |
For some reason, 2 years ago I thought it wasn't. Maybe I wrote a python-style docstring, got an error, and assumed, who knows? Either way I've fixed it now. |
_
spacers in numeric literals