Skip to content

Commit 2aeb59b

Browse files
committed
feat(syntax): add Godot file highlighting
Support GDScript, Godot shaders, and text scene/resource files with tree-sitter parsers and focused highlight queries. Register the related extensions and cover representative tokens with tests.
1 parent cb87e51 commit 2aeb59b

10 files changed

Lines changed: 307 additions & 4 deletions

File tree

‎Cargo.lock‎

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ tree-sitter-css = "0.25"
5050
tree-sitter-dart = "0.2.0"
5151
tree-sitter-elixir = "0.3"
5252
tree-sitter-erlang = "0.20"
53+
tree-sitter-gdscript = "6.1"
54+
tree-sitter-gdshader = "0.4"
5355
tree-sitter-go = "0.25"
56+
tree-sitter-godot-resource = "0.7"
5457
tree-sitter-haskell = "0.23"
5558
tree-sitter-html = "0.23"
5659
tree-sitter-java = "0.23"

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ See the [Installation Guide](docs/installation.md) for more options and troubles
7373

7474
🎬 **Commit Replay as Animation** — Realistic typing, cursor movement, deletions, and file operations
7575
🔍 **Working Tree Diff View** — Visualize staged/unstaged changes before committing
76-
🎨 **Tree-sitter Syntax Highlighting** — 29 languages supported
76+
🎨 **Tree-sitter Syntax Highlighting** — 32 languages supported
7777
🌳 **Project File Tree** — Directory structure with change statistics
7878
🖥️ **Screensaver Mode** — Endless random commit playback
7979
🎭 **Themes** — 9 built-in themes + full customization support
@@ -189,7 +189,7 @@ See the [Configuration Guide](docs/configuration.md) for full options and exampl
189189

190190
## Supported Languages
191191

192-
Astro, Bash, C, C#, C++, Clojure, CSS, Dart, Elixir, Erlang, Go, Haskell, HTML, Java, JavaScript, JSON, Kotlin, Lua, Markdown, Nix, PHP, Python, Ruby, Rust, Scala, Svelte, Swift, TypeScript, XML, YAML, Zig
192+
Astro, Bash, C, C#, C++, Clojure, CSS, Dart, Elixir, Erlang, Go, Godot (GDScript / Shader / Resource), Haskell, HTML, Java, JavaScript, JSON, Kotlin, Lua, Markdown, Nix, PHP, Python, Ruby, Rust, Scala, Svelte, Swift, TypeScript, XML, YAML, Zig
193193

194194
## Documentation
195195

‎src/syntax/languages/gdscript.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn language() -> tree_sitter::Language {
2+
tree_sitter_gdscript::LANGUAGE.into()
3+
}
4+
5+
pub const HIGHLIGHT_QUERY: &str = include_str!("queries/gdscript_highlights.scm");

‎src/syntax/languages/gdshader.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn language() -> tree_sitter::Language {
2+
tree_sitter_gdshader::LANGUAGE.into()
3+
}
4+
5+
pub const HIGHLIGHT_QUERY: &str = tree_sitter_gdshader::HIGHLIGHTS_QUERY;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn language() -> tree_sitter::Language {
2+
tree_sitter_godot_resource::LANGUAGE.into()
3+
}
4+
5+
pub const HIGHLIGHT_QUERY: &str = include_str!("queries/godot_resource_highlights.scm");

‎src/syntax/languages/mod.rs‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ pub mod css;
88
pub mod dart;
99
pub mod elixir;
1010
pub mod erlang;
11+
pub mod gdscript;
12+
pub mod gdshader;
1113
pub mod go_lang;
14+
pub mod godot_resource;
1215
pub mod haskell;
1316
pub mod html;
1417
pub mod java;
@@ -52,7 +55,10 @@ enum LanguageKind {
5255
Dart,
5356
Elixir,
5457
Erlang,
58+
Gdscript,
59+
Gdshader,
5560
Go,
61+
GodotResource,
5662
Haskell,
5763
Html,
5864
Java,
@@ -137,11 +143,26 @@ fn by_name(raw: &str) -> Option<LanguageSupport> {
137143
highlight_query: erlang::HIGHLIGHT_QUERY,
138144
injection_query: None,
139145
},
146+
LanguageKind::Gdscript => LanguageSupport {
147+
language: gdscript::language(),
148+
highlight_query: gdscript::HIGHLIGHT_QUERY,
149+
injection_query: None,
150+
},
151+
LanguageKind::Gdshader => LanguageSupport {
152+
language: gdshader::language(),
153+
highlight_query: gdshader::HIGHLIGHT_QUERY,
154+
injection_query: None,
155+
},
140156
LanguageKind::Go => LanguageSupport {
141157
language: go_lang::language(),
142158
highlight_query: go_lang::HIGHLIGHT_QUERY,
143159
injection_query: None,
144160
},
161+
LanguageKind::GodotResource => LanguageSupport {
162+
language: godot_resource::language(),
163+
highlight_query: godot_resource::HIGHLIGHT_QUERY,
164+
injection_query: None,
165+
},
145166
LanguageKind::Haskell => LanguageSupport {
146167
language: haskell::language(),
147168
highlight_query: haskell::HIGHLIGHT_QUERY,
@@ -265,7 +286,10 @@ fn resolve_language_kind(raw: &str) -> Option<LanguageKind> {
265286
"dart" => Some(LanguageKind::Dart),
266287
"ex" | "exs" | "elixir" => Some(LanguageKind::Elixir),
267288
"erl" | "hrl" | "es" | "escript" | "erlang" => Some(LanguageKind::Erlang),
289+
"gd" | "gdscript" => Some(LanguageKind::Gdscript),
290+
"gdshader" | "gdshaderinc" => Some(LanguageKind::Gdshader),
268291
"go" | "golang" => Some(LanguageKind::Go),
292+
"tscn" | "tres" | "godot" | "godot-resource" => Some(LanguageKind::GodotResource),
269293
"hs" | "lhs" | "haskell" => Some(LanguageKind::Haskell),
270294
"html" | "htm" => Some(LanguageKind::Html),
271295
"java" => Some(LanguageKind::Java),
@@ -304,7 +328,10 @@ impl LanguageKind {
304328
LanguageKind::Dart => "dart",
305329
LanguageKind::Elixir => "elixir",
306330
LanguageKind::Erlang => "erlang",
331+
LanguageKind::Gdscript => "gdscript",
332+
LanguageKind::Gdshader => "gdshader",
307333
LanguageKind::Go => "go",
334+
LanguageKind::GodotResource => "godot-resource",
308335
LanguageKind::Haskell => "haskell",
309336
LanguageKind::Html => "html",
310337
LanguageKind::Java => "java",
@@ -334,7 +361,7 @@ mod tests {
334361
use super::*;
335362
use tree_sitter::Parser;
336363

337-
const SUPPORTED_LANGUAGES: [(&str, bool); 31] = [
364+
const SUPPORTED_LANGUAGES: [(&str, bool); 34] = [
338365
("astro", true),
339366
("bash", false),
340367
("c", false),
@@ -345,7 +372,10 @@ mod tests {
345372
("dart", false),
346373
("elixir", false),
347374
("erlang", false),
375+
("gdscript", false),
376+
("gdshader", false),
348377
("go", false),
378+
("godot-resource", false),
349379
("haskell", false),
350380
("html", true),
351381
("java", false),
@@ -368,7 +398,7 @@ mod tests {
368398
("zig", false),
369399
];
370400

371-
const CANONICAL_ALIASES: [(&str, &str); 31] = [
401+
const CANONICAL_ALIASES: [(&str, &str); 34] = [
372402
("astro", "astro"),
373403
("shell", "bash"),
374404
("h", "c"),
@@ -379,7 +409,10 @@ mod tests {
379409
("dart", "dart"),
380410
("exs", "elixir"),
381411
("escript", "erlang"),
412+
("gd", "gdscript"),
413+
("gdshaderinc", "gdshader"),
382414
("golang", "go"),
415+
("tscn", "godot-resource"),
383416
("lhs", "haskell"),
384417
("htm", "html"),
385418
("java", "java"),
@@ -452,6 +485,11 @@ mod tests {
452485
("styles/site.scss", "css"),
453486
("components/App.tsx", "typescript"),
454487
("templates/index.phtml", "php"),
488+
("scripts/player.gd", "gdscript"),
489+
("shaders/water.gdshaderinc", "gdshader"),
490+
("scenes/main.tscn", "godot-resource"),
491+
("resources/player.tres", "godot-resource"),
492+
("game/project.godot", "godot-resource"),
455493
("docs/guide.md", "markdown"),
456494
]
457495
.iter()
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
; Comments and literals
2+
(comment) @comment
3+
(string) @string
4+
(string_name) @string
5+
(node_path) @string
6+
(escape_sequence) @string.escape
7+
(integer) @number
8+
(float) @number
9+
[
10+
(true)
11+
(false)
12+
(null)
13+
] @constant
14+
15+
; Types and declarations
16+
(type) @type
17+
(class_name_statement (name) @type)
18+
(class_definition (name) @type)
19+
(enum_definition (name) @type)
20+
(enumerator (identifier) @constant)
21+
(variable_statement (identifier) @variable)
22+
(const_statement (name) @constant)
23+
(signal_statement (name) @label)
24+
25+
; Functions, methods, and members
26+
(function_definition
27+
name: (name) @function
28+
parameters: (parameters) @parameter)
29+
(constructor_definition "_init" @function)
30+
(lambda (name) @function)
31+
(lambda (parameters) @parameter)
32+
(call (identifier) @function)
33+
(attribute_call (identifier) @function)
34+
(base_call (identifier) @function)
35+
(attribute
36+
(identifier)
37+
(identifier) @property)
38+
39+
; Annotations and keywords
40+
(annotation (identifier) @keyword)
41+
[
42+
"if"
43+
"else"
44+
"elif"
45+
"match"
46+
"when"
47+
"while"
48+
"for"
49+
"return"
50+
"pass"
51+
"break"
52+
"continue"
53+
"func"
54+
"export"
55+
"in"
56+
"is"
57+
"as"
58+
"and"
59+
"or"
60+
"not"
61+
"var"
62+
"class"
63+
"class_name"
64+
"enum"
65+
"const"
66+
"signal"
67+
"setget"
68+
"onready"
69+
"extends"
70+
"set"
71+
"get"
72+
"await"
73+
(remote_keyword)
74+
(static_keyword)
75+
] @keyword
76+
77+
; Operators and punctuation
78+
[
79+
"+"
80+
"-"
81+
"*"
82+
"/"
83+
"%"
84+
"=="
85+
"!="
86+
">"
87+
"<"
88+
">="
89+
"<="
90+
"="
91+
"+="
92+
"-="
93+
"*="
94+
"/="
95+
"%="
96+
"&"
97+
"|"
98+
"^"
99+
"~"
100+
"<<"
101+
">>"
102+
":="
103+
":"
104+
] @operator
105+
[
106+
"("
107+
")"
108+
"["
109+
"]"
110+
"{"
111+
"}"
112+
","
113+
"."
114+
] @punctuation
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
(comment) @comment
2+
3+
(string) @string
4+
5+
[
6+
(integer)
7+
(float)
8+
] @number
9+
10+
[
11+
(true)
12+
(false)
13+
(null)
14+
] @constant.builtin
15+
16+
(section
17+
.
18+
(identifier) @keyword)
19+
20+
(attribute
21+
.
22+
(identifier) @property)
23+
24+
(property
25+
.
26+
(path) @property)
27+
28+
(constructor
29+
.
30+
(identifier) @type)
31+
32+
(identifier) @variable
33+
34+
[
35+
"="
36+
":"
37+
] @operator
38+
39+
[
40+
"["
41+
"]"
42+
"("
43+
")"
44+
"{"
45+
"}"
46+
] @punctuation.bracket
47+
48+
"," @punctuation.delimiter

0 commit comments

Comments
 (0)