Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 96 additions & 39 deletions languages/gdscript/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
; Any uncovered text,
; var a = 10 has 'a' matching @variable
; but a = 10 has 'a matching nothing.
; This is to keep consistency, and is like 'text_editor/theme/highlighting/text_color' in Godot Editor Settings
(identifier) @variable


; Class
(class_name_statement (name) @type)
(class_definition (name) @type)


; Function calls

(attribute_call (identifier) @function)
(base_call (identifier) @function)
(attribute_call (identifier) @function.method)
(base_call (identifier) @function.builtin)
(call (identifier) @function)

; Function definitions

(function_definition
name: (name) @function
parameters: (parameters) @variable)
(constructor_definition "_init" @function)
(lambda (parameters) @variable)

name: (name) @function.definition)
; Constructor definition
(function_definition
name: (name) @constructor
(#eq? @constructor "_init"))
; Untyped function parameter defintiion: a in func foo(a)
(parameters (identifier) @variable.parameter)
; Typed function parameter defition: b in func foo(b: int)
(parameters
(typed_parameter
. (identifier) @variable.parameter))
; both of the above work with lambdas too!

;; Literals
(comment) @comment
Expand All @@ -25,28 +37,46 @@
[
(region_start)
(region_end)
] @comment.doc
] @tag

; Critical comment
((comment) @error
(#match? @error "\\b(ALERT|ATTENTION|CAUTION|CRITICAL|DANGER|SECURITY)\\b"))

; Warning comment
((comment) @warning
(#match? @warning "\\b(BUG|DEPRECATED|FIXME|HACK|TASK|TBD|TODO|WARNING)\\b"))

; Info comment
((comment) @info
(#match? @info "\\b(INFO|NOTE|NOTICE|TEST|TESTING)\\b"))

(string) @string

; currently no differentiation between built-in types (int, Vector2), and custom ones (with class_name)
(type) @type
(enum_definition (name) @type)
(enumerator (identifier) @variant)
(null) @type

(variable_statement (identifier) @variable)
; Catch the name in a 'var' declaration
(variable_statement
name: (name) @variable)

; Catch the name in a 'var' declaration with a type hint (like dirs: Dictionary)
(variable_statement
name: (name) @variable
type: (type))
(attribute
(identifier)
(identifier) @property)

((identifier) @type
(#match? @type "^(bool|float|int)$"))

[
(string_name)
(node_path)
(get_node)
] @label
(signal_statement (name) @label)
(string_name) @string.special.symbol
(node_path) @string.special.path
(get_node) @string.special
(signal_statement (name) @variable.special)

(const_statement (name) @constant)

Expand All @@ -56,10 +86,14 @@
] @number

(escape_sequence) @string.escape

((identifier) @constant.builtin
(#match? @constant.builtin "^(PI|TAU|NAN|INF)$"))
[
(null)
(true)
(false)
] @boolean
] @constant.builtin

[
"+"
Expand Down Expand Up @@ -95,17 +129,27 @@
"<<="
">>="
"**="
":" ; for consistency (to make :type= same as :=)
] @operator

; Keywords
(annotation (identifier) @keyword)

; Annotations
(annotation (identifier) @attribute)

; Storage
[
(remote_keyword)
"var"
"const"
"signal"
"enum"
(static_keyword)
(breakpoint_statement)
] @keyword
] @keyword.storage

; Function
"func" @keyword.function

; Action
[
"if"
"else"
Expand All @@ -114,33 +158,46 @@
"while"
"for"
"return"
"pass"
"break"
"continue"
"func"
"in"
"is"
"as"
"await"
"pass"
(breakpoint_statement)
] @keyword.control

; Operator
[
"and"
"or"
"not"
"var"
"class"
"class_name"
"enum"
"const"
"signal"
"in"
"is"
"as"
] @keyword.operator

; Attribute
[
"@"
; "export" covered in Annotations above (@ followed by anything)
; "onready"
"setget"
"onready"
"extends"
"set"
"get"
"await"
] @attribute

; Import
((identifier) @keyword.import
(#match? @keyword.import "^(load|preload)$"))

; Remaining Keywords
[
"class"
"class_name"
"extends"
] @keyword

((identifier) @keyword
(#match? @keyword "^(self|super)$"))
((identifier) @variable.language
(#match? @variable.language "^(self|super)$"))

; Identifier naming conventions
; This needs to be at the very end in order to override earlier queries
Expand Down