From 3f7a944e967856b5d0dc65045f1696c00234d006 Mon Sep 17 00:00:00 2001 From: David Kincaid Date: Sat, 22 Feb 2025 12:51:44 -0500 Subject: [PATCH] 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 --- src/formatter/snapshots/operators.gd | 7 +++- src/formatter/snapshots/setters_getters.gd | 25 +++++++++++++ syntaxes/GDScript.tmLanguage.json | 43 ++++++++++++---------- 3 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 src/formatter/snapshots/setters_getters.gd diff --git a/src/formatter/snapshots/operators.gd b/src/formatter/snapshots/operators.gd index 159354b..8580076 100644 --- a/src/formatter/snapshots/operators.gd +++ b/src/formatter/snapshots/operators.gd @@ -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 \ No newline at end of file + x = 1 ^ ~1 + + print(x == 1) + print(x <= 1) + print(x >= 1) \ No newline at end of file diff --git a/src/formatter/snapshots/setters_getters.gd b/src/formatter/snapshots/setters_getters.gd new file mode 100644 index 0000000..aa434cd --- /dev/null +++ b/src/formatter/snapshots/setters_getters.gd @@ -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 diff --git a/syntaxes/GDScript.tmLanguage.json b/syntaxes/GDScript.tmLanguage.json index caf2b02..47a3a42 100644 --- a/syntaxes/GDScript.tmLanguage.json +++ b/syntaxes/GDScript.tmLanguage.json @@ -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": "(?