From 381062518e1ab4f9b91c86b689c79e14344b971a Mon Sep 17 00:00:00 2001 From: Patrick Cleaveliln Date: Wed, 23 Jul 2025 01:35:10 +0000 Subject: [PATCH] add rust syntax --- src/core/file_buffer.odin | 2 ++ src/tree_sitter/ts.odin | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/core/file_buffer.odin b/src/core/file_buffer.odin index 2c8d1c1..443a129 100644 --- a/src/core/file_buffer.odin +++ b/src/core/file_buffer.odin @@ -746,6 +746,8 @@ new_file_buffer :: proc(allocator: mem.Allocator, file_path: string, base_dir: s file_type: ts.LanguageType = .None if extension == ".odin" { file_type = .Odin + } else if extension == ".rs" { + file_type = .Rust } else if extension == ".json" { file_type = .Json } diff --git a/src/tree_sitter/ts.odin b/src/tree_sitter/ts.odin index 7d95133..3c91b4d 100644 --- a/src/tree_sitter/ts.odin +++ b/src/tree_sitter/ts.odin @@ -97,6 +97,11 @@ foreign ts_odin { tree_sitter_odin :: proc "c" () -> Language --- } +foreign import ts_rust "../../bin/libtree-sitter-rust.a" +foreign ts_rust { + tree_sitter_rust :: proc "c" () -> Language --- +} + foreign import ts_json "../../bin/libtree-sitter-json.a" foreign ts_json { tree_sitter_json :: proc "c" () -> Language --- @@ -123,6 +128,7 @@ LanguageType :: enum { None, Json, Odin, + Rust, } TestStuff :: struct { @@ -211,6 +217,7 @@ make_state :: proc(type: LanguageType, allocator := context.allocator) -> State switch (type) { case .None: {} case .Odin: language = tree_sitter_odin() + case .Rust: language = tree_sitter_rust() case .Json: language = tree_sitter_json() } @@ -234,7 +241,7 @@ delete_state :: proc(state: ^State) { } parse_buffer :: proc(state: ^State, input: Input) { - if state.parser == nil { + if state.parser == nil || state.language_type == .None { return } @@ -315,6 +322,27 @@ load_highlights :: proc(state: ^State) { capture_to_color["comment"] = .Gray } + case .Rust: { + capture_to_color["string"] = .Green + capture_to_color["comment"] = .Gray + + capture_to_color["type"] = .BrightBlue + + capture_to_color["type.builtin"] = .Aqua + + capture_to_color["label"] = .Red + capture_to_color["variable.builtin"] = .Red + + capture_to_color["keyword"] = .Blue + capture_to_color["function"] = .Blue + capture_to_color["function.method"] = .Blue + + capture_to_color["property"] = .BrightYellow + capture_to_color["constructor"] = .Yellow + capture_to_color["attribute"] = .BrightGray + + capture_to_color["constant.builtin"] = .Purple + } } path: string @@ -327,6 +355,9 @@ load_highlights :: proc(state: ^State) { case .Odin: { path = "../tree-sitter-odin/queries/highlights.scm" } + case .Rust: { + path = "../tree-sitter-rust/queries/highlights.scm" + } } fd, err := os.open(path)