More Highlighting and Formatting Improvements (#783)

* Fix **= operator being formatted incorrectly

* Fix variables in get_node()-style function calls not being highlighted

* Move super from builtin_classes to keywords

* Fix uppercase builtin classes being highlighted as constants

* Fix setter and getter highlighting/formatting

* Fix variable as default parameter not highlighted in function declaration
This commit is contained in:
David Kincaid
2025-02-22 12:51:44 -05:00
committed by GitHub
parent 51ef0ef0c0
commit 3f7a944e96
3 changed files with 55 additions and 20 deletions

View File

@@ -8,6 +8,7 @@ func f():
x %= 1
x = 2 ** 2
x = 2 * -1
x **= 2
# bitwise
x |= 1
@@ -21,4 +22,8 @@ func f():
x = 1 << 1 | 1 >> 3
x = 1 << 1 & 1 >> 3
x = 1 ^ ~1
x = 1 ^ ~1
print(x == 1)
print(x <= 1)
print(x >= 1)

View File

@@ -0,0 +1,25 @@
# --- IN ---
func __get():
pass
func __set(val):
pass
var a: get = __get, set = __set
var b:
get = __get,
set = __set
var c = '':
get: return __get()
set(val): __set(val)
var d = '':
get:
print('get')
return __get()
set(val):
print('set')
__set(val)
var e = '' setget __get, __set

View File

@@ -35,8 +35,8 @@
},
"expression": {
"patterns": [
{ "include": "#base_expression" },
{ "include": "#getter_setter_godot4" },
{ "include": "#base_expression" },
{ "include": "#assignment_operator" },
{ "include": "#annotations" },
{ "include": "#class_name" },
@@ -170,7 +170,7 @@
}
]
},
{ "include": "#base_expression" }
{ "include": "#expression" }
]
},
"self": {
@@ -229,7 +229,7 @@
"name": "keyword.operator.comparison.gdscript"
},
"arithmetic_operator": {
"match": "->|\\+=|-=|\\*=|\\^=|/=|%=|&=|~=|\\|=|\\*\\*|\\*|/|%|\\+|-",
"match": "->|\\+=|-=|\\*\\*=|\\*=|\\^=|/=|%=|&=|~=|\\|=|\\*\\*|\\*|/|%|\\+|-",
"name": "keyword.operator.arithmetic.gdscript"
},
"assignment_operator": {
@@ -245,7 +245,7 @@
"captures": { "1": { "name": "keyword.control.gdscript" } }
},
"keywords": {
"match": "\\b(?:class|class_name|abstract|is|onready|tool|static|export|as|void|enum|assert|breakpoint|sync|remote|master|puppet|slave|remotesync|mastersync|puppetsync|trait|namespace)\\b",
"match": "\\b(?:class|class_name|abstract|is|onready|tool|static|export|as|void|enum|assert|breakpoint|sync|remote|master|puppet|slave|remotesync|mastersync|puppetsync|trait|namespace|super)\\b",
"name": "keyword.language.gdscript"
},
"letter": {
@@ -293,7 +293,7 @@
"match": "(:)?\\s*(set|get)\\s+=\\s+([a-zA-Z_]\\w*)",
"captures": {
"1": { "name": "punctuation.separator.annotation.gdscript" },
"2": { "name": "keyword.language.gdscript storage.type.const.gdscript" },
"2": { "name": "entity.name.function.gdscript" },
"3": { "name": "entity.name.function.gdscript" }
}
},
@@ -311,7 +311,7 @@
{
"match": "(setget)\\s+([a-zA-Z_]\\w*)(?:[,]\\s*([a-zA-Z_]\\w*))?",
"captures": {
"1": { "name": "keyword.language.gdscript storage.type.const.gdscript" },
"1": { "name": "keyword.language.gdscript" },
"2": { "name": "entity.name.function.gdscript" },
"3": { "name": "entity.name.function.gdscript" }
}
@@ -326,18 +326,23 @@
"getter_setter_godot4": {
"patterns": [
{
"match": "\\b(get):",
"captures": { "1": { "name": "entity.name.function.gdscript" } }
"name": "meta.variable.declaration.getter.gdscript",
"match": "(get)\\s*(:)",
"captures": {
"1": { "name": "entity.name.function.gdscript" },
"2": { "name": "punctuation.separator.annotation.gdscript" }
}
},
{
"name": "meta.function.gdscript",
"begin": "(?x) \\s+\n (set) \\s*\n (?=\\()",
"end": "(:|(?=[#'\"\\n]))",
"beginCaptures": { "1": { "name": "entity.name.function.gdscript" } },
"patterns": [
{ "include": "#parameters" },
{ "include": "#line_continuation" }
]
"name": "meta.variable.declaration.setter.gdscript",
"match": "(set)\\s*(\\()\\s*([A-Za-z_]\\w*)\\s*(\\))\\s*(:)",
"captures": {
"1": { "name": "entity.name.function.gdscript" },
"2": { "name": "punctuation.definition.arguments.begin.gdscript" },
"3": { "name": "variable.other.gdscript" },
"4": { "name": "punctuation.definition.arguments.end.gdscript" },
"5": { "name": "punctuation.separator.annotation.gdscript" }
}
}
]
},
@@ -437,7 +442,7 @@
}
},
"builtin_classes": {
"match": "(?<![^.]\\.|:)\\b(Vector2|Vector2i|Vector3|Vector3i|Vector4|Vector4i|Color|Rect2|Rect2i|Array|Basis|Dictionary|Plane|Quat|RID|Rect3|Transform|Transform2D|Transform3D|AABB|String|Color|NodePath|PoolByteArray|PoolIntArray|PoolRealArray|PoolStringArray|PoolVector2Array|PoolVector3Array|PoolColorArray|bool|int|float|Signal|Callable|StringName|Quaternion|Projection|PackedByteArray|PackedInt32Array|PackedInt64Array|PackedFloat32Array|PackedFloat64Array|PackedStringArray|PackedVector2Array|PackedVector2iArray|PackedVector3Array|PackedVector3iArray|PackedVector4Array|PackedColorArray|super)\\b",
"match": "(?<![^.]\\.|:)\\b(Vector2|Vector2i|Vector3|Vector3i|Vector4|Vector4i|Color|Rect2|Rect2i|Array|Basis|Dictionary|Plane|Quat|RID|Rect3|Transform|Transform2D|Transform3D|AABB|String|Color|NodePath|PoolByteArray|PoolIntArray|PoolRealArray|PoolStringArray|PoolVector2Array|PoolVector3Array|PoolColorArray|bool|int|float|Signal|Callable|StringName|Quaternion|Projection|PackedByteArray|PackedInt32Array|PackedInt64Array|PackedFloat32Array|PackedFloat64Array|PackedStringArray|PackedVector2Array|PackedVector2iArray|PackedVector3Array|PackedVector3iArray|PackedVector4Array|PackedColorArray|JSON|UPNP|OS|IP|JSONRPC|XRVRS)\\b",
"name": "entity.name.type.class.builtin.gdscript"
},
"const_vars": {
@@ -530,7 +535,7 @@
"end": "(,)|(?=\\))",
"beginCaptures": { "1": { "name": "keyword.operator.gdscript" } },
"endCaptures": { "1": { "name": "punctuation.separator.parameters.gdscript" } },
"patterns": [ { "include": "#base_expression" } ]
"patterns": [ { "include": "#expression" } ]
},
"annotated_parameter": {
"begin": "(?x)\n \\s* ([a-zA-Z_]\\w*) \\s* (:)\\s* ([a-zA-Z_]\\w*)? \n",
@@ -542,7 +547,7 @@
"end": "(,)|(?=\\))",
"endCaptures": { "1": { "name": "punctuation.separator.parameters.gdscript" } },
"patterns": [
{ "include": "#base_expression" },
{ "include": "#expression" },
{
"name": "keyword.operator.assignment.gdscript",
"match": "=(?!=)"