From a4914fcf3b0e80505ead8ef3734d572be027aab1 Mon Sep 17 00:00:00 2001 From: Quinn Wilton Date: Sun, 23 Jul 2023 16:32:14 -0700 Subject: [PATCH 1/9] Add tree-sitter-elm --- Cargo.lock | 11 ++++ Cargo.toml | 1 + crates/zed/Cargo.toml | 1 + crates/zed/src/languages.rs | 1 + crates/zed/src/languages/elm/config.toml | 11 ++++ crates/zed/src/languages/elm/highlights.scm | 71 +++++++++++++++++++++ crates/zed/src/languages/elm/injections.scm | 2 + 7 files changed, 98 insertions(+) create mode 100644 crates/zed/src/languages/elm/config.toml create mode 100644 crates/zed/src/languages/elm/highlights.scm create mode 100644 crates/zed/src/languages/elm/injections.scm diff --git a/Cargo.lock b/Cargo.lock index f0c8917aa2..eb6c51e47f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7989,6 +7989,16 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-elm" +version = "5.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec83a2e1cfc69d03c8e73636e95662d6c6728539538d341b21251a77039fb94e" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-embedded-template" version = "0.20.0" @@ -9543,6 +9553,7 @@ dependencies = [ "tree-sitter-cpp", "tree-sitter-css", "tree-sitter-elixir", + "tree-sitter-elm", "tree-sitter-embedded-template", "tree-sitter-go", "tree-sitter-heex", diff --git a/Cargo.toml b/Cargo.toml index fa824115cb..03614e61e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -112,6 +112,7 @@ tree-sitter-c = "0.20.1" tree-sitter-cpp = "0.20.0" tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev = "769203d0f9abe1a9a691ac2b9fe4bb4397a73c51" } tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "4ba9dab6e2602960d95b2b625f3386c27e08084e" } +tree-sitter-elm = "5.6.4" tree-sitter-embedded-template = "0.20.0" tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "aeb2f33b366fd78d5789ff104956ce23508b85db" } tree-sitter-heex = { git = "https://github.com/phoenixframework/tree-sitter-heex", rev = "2e1348c3cf2c9323e87c2744796cf3f3868aa82a" } diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index c5bf313701..df7f4bcce9 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -109,6 +109,7 @@ tree-sitter-c.workspace = true tree-sitter-cpp.workspace = true tree-sitter-css.workspace = true tree-sitter-elixir.workspace = true +tree-sitter-elm.workspace = true tree-sitter-embedded-template.workspace = true tree-sitter-go.workspace = true tree-sitter-heex.workspace = true diff --git a/crates/zed/src/languages.rs b/crates/zed/src/languages.rs index 365e8a3023..c7b5c59b87 100644 --- a/crates/zed/src/languages.rs +++ b/crates/zed/src/languages.rs @@ -152,6 +152,7 @@ pub fn init(languages: Arc, node_runtime: Arc) { tree_sitter_php::language(), vec![Arc::new(php::IntelephenseLspAdapter::new(node_runtime))], ); + language("elm", tree_sitter_elm::language(), vec![]); } #[cfg(any(test, feature = "test-support"))] diff --git a/crates/zed/src/languages/elm/config.toml b/crates/zed/src/languages/elm/config.toml new file mode 100644 index 0000000000..5051427a93 --- /dev/null +++ b/crates/zed/src/languages/elm/config.toml @@ -0,0 +1,11 @@ +name = "Elm" +path_suffixes = ["elm"] +line_comment = "-- " +block_comment = ["{- ", " -}"] +brackets = [ + { start = "{", end = "}", close = true, newline = true }, + { start = "[", end = "]", close = true, newline = true }, + { start = "(", end = ")", close = true, newline = true }, + { start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] }, + { start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] }, +] diff --git a/crates/zed/src/languages/elm/highlights.scm b/crates/zed/src/languages/elm/highlights.scm new file mode 100644 index 0000000000..f6be193f83 --- /dev/null +++ b/crates/zed/src/languages/elm/highlights.scm @@ -0,0 +1,71 @@ +[ + "if" + "then" + "else" + "let" + "in" + (case) + (of) + (backslash) + (as) + (port) + (exposing) + (alias) + (import) + (module) + (type) + ] @keyword + +[ + (arrow) + (eq) + (operator_identifier) + (colon) +] @operator + +(type_annotation(lower_case_identifier) @function) +(port_annotation(lower_case_identifier) @function) +(function_declaration_left(lower_case_identifier) @function.definition) +(function_call_expr target: (value_expr) @identifier) + +(exposed_value(lower_case_identifier) @function) +(exposed_type(upper_case_identifier) @type) + +(field_access_expr(value_expr(value_qid)) @identifier) +(lower_pattern) @variable +(record_base_identifier) @identifier + +[ + "(" + ")" +] @punctuation.bracket + +[ + "|" + "," +] @punctuation.delimiter + +(number_constant_expr) @constant + +(type_declaration(upper_case_identifier) @type) +(type_ref) @type +(type_alias_declaration name: (upper_case_identifier) @type) + +(union_variant(upper_case_identifier) @variant) +(union_pattern) @variant +(value_expr(upper_case_qid(upper_case_identifier)) @type) + +[ + (line_comment) + (block_comment) +] @comment + +(string_escape) @string.escape + +[ + (open_quote) + (close_quote) + (regular_string_part) + (open_char) + (close_char) +] @string diff --git a/crates/zed/src/languages/elm/injections.scm b/crates/zed/src/languages/elm/injections.scm new file mode 100644 index 0000000000..0567320675 --- /dev/null +++ b/crates/zed/src/languages/elm/injections.scm @@ -0,0 +1,2 @@ +((glsl_content) @content + (#set! "language" "glsl")) From dd504f5965f62d4d3aa4d079b039e68461ae1487 Mon Sep 17 00:00:00 2001 From: Quinn Wilton Date: Sun, 23 Jul 2023 16:43:44 -0700 Subject: [PATCH 2/9] Add tree-sitter-glsl --- Cargo.lock | 10 ++ Cargo.toml | 1 + crates/zed/Cargo.toml | 1 + crates/zed/src/languages.rs | 1 + crates/zed/src/languages/glsl/config.toml | 9 ++ crates/zed/src/languages/glsl/highlights.scm | 118 +++++++++++++++++++ 6 files changed, 140 insertions(+) create mode 100644 crates/zed/src/languages/glsl/config.toml create mode 100644 crates/zed/src/languages/glsl/highlights.scm diff --git a/Cargo.lock b/Cargo.lock index eb6c51e47f..3aa77e2ce1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8009,6 +8009,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-glsl" +version = "0.1.4" +source = "git+https://github.com/theHamsta/tree-sitter-glsl?rev=2a56fb7bc8bb03a1892b4741279dd0a8758b7fb3#2a56fb7bc8bb03a1892b4741279dd0a8758b7fb3" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-go" version = "0.19.1" @@ -9555,6 +9564,7 @@ dependencies = [ "tree-sitter-elixir", "tree-sitter-elm", "tree-sitter-embedded-template", + "tree-sitter-glsl", "tree-sitter-go", "tree-sitter-heex", "tree-sitter-html", diff --git a/Cargo.toml b/Cargo.toml index 03614e61e4..10f2160f45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -114,6 +114,7 @@ tree-sitter-css = { git = "https://github.com/tree-sitter/tree-sitter-css", rev tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", rev = "4ba9dab6e2602960d95b2b625f3386c27e08084e" } tree-sitter-elm = "5.6.4" tree-sitter-embedded-template = "0.20.0" +tree-sitter-glsl = { git = "https://github.com/theHamsta/tree-sitter-glsl", rev = "2a56fb7bc8bb03a1892b4741279dd0a8758b7fb3" } tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "aeb2f33b366fd78d5789ff104956ce23508b85db" } tree-sitter-heex = { git = "https://github.com/phoenixframework/tree-sitter-heex", rev = "2e1348c3cf2c9323e87c2744796cf3f3868aa82a" } tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "40a81c01a40ac48744e0c8ccabbaba1920441199" } diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index df7f4bcce9..9bd2de0acc 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -111,6 +111,7 @@ tree-sitter-css.workspace = true tree-sitter-elixir.workspace = true tree-sitter-elm.workspace = true tree-sitter-embedded-template.workspace = true +tree-sitter-glsl.workspace = true tree-sitter-go.workspace = true tree-sitter-heex.workspace = true tree-sitter-json.workspace = true diff --git a/crates/zed/src/languages.rs b/crates/zed/src/languages.rs index c7b5c59b87..09f5162c12 100644 --- a/crates/zed/src/languages.rs +++ b/crates/zed/src/languages.rs @@ -153,6 +153,7 @@ pub fn init(languages: Arc, node_runtime: Arc) { vec![Arc::new(php::IntelephenseLspAdapter::new(node_runtime))], ); language("elm", tree_sitter_elm::language(), vec![]); + language("glsl", tree_sitter_glsl::language(), vec![]); } #[cfg(any(test, feature = "test-support"))] diff --git a/crates/zed/src/languages/glsl/config.toml b/crates/zed/src/languages/glsl/config.toml new file mode 100644 index 0000000000..4081a6381f --- /dev/null +++ b/crates/zed/src/languages/glsl/config.toml @@ -0,0 +1,9 @@ +name = "GLSL" +path_suffixes = ["vert", "frag", "tesc", "tese", "geom", "comp"] +line_comment = "// " +block_comment = ["/* ", " */"] +brackets = [ + { start = "{", end = "}", close = true, newline = true }, + { start = "[", end = "]", close = true, newline = true }, + { start = "(", end = ")", close = true, newline = true }, +] diff --git a/crates/zed/src/languages/glsl/highlights.scm b/crates/zed/src/languages/glsl/highlights.scm new file mode 100644 index 0000000000..e4503c6fbb --- /dev/null +++ b/crates/zed/src/languages/glsl/highlights.scm @@ -0,0 +1,118 @@ +"break" @keyword +"case" @keyword +"const" @keyword +"continue" @keyword +"default" @keyword +"do" @keyword +"else" @keyword +"enum" @keyword +"extern" @keyword +"for" @keyword +"if" @keyword +"inline" @keyword +"return" @keyword +"sizeof" @keyword +"static" @keyword +"struct" @keyword +"switch" @keyword +"typedef" @keyword +"union" @keyword +"volatile" @keyword +"while" @keyword + +"#define" @keyword +"#elif" @keyword +"#else" @keyword +"#endif" @keyword +"#if" @keyword +"#ifdef" @keyword +"#ifndef" @keyword +"#include" @keyword +(preproc_directive) @keyword + +"--" @operator +"-" @operator +"-=" @operator +"->" @operator +"=" @operator +"!=" @operator +"*" @operator +"&" @operator +"&&" @operator +"+" @operator +"++" @operator +"+=" @operator +"<" @operator +"==" @operator +">" @operator +"||" @operator + +"." @delimiter +";" @delimiter + +(string_literal) @string +(system_lib_string) @string + +(null) @constant +(number_literal) @number +(char_literal) @number + +(call_expression + function: (identifier) @function) +(call_expression + function: (field_expression + field: (field_identifier) @function)) +(function_declarator + declarator: (identifier) @function) +(preproc_function_def + name: (identifier) @function.special) + +(field_identifier) @property +(statement_identifier) @label +(type_identifier) @type +(primitive_type) @type +(sized_type_specifier) @type + +((identifier) @constant + (#match? @constant "^[A-Z][A-Z\\d_]*$")) + +(identifier) @variable + +(comment) @comment +; inherits: c + +[ + "in" + "out" + "inout" + "uniform" + "shared" + "layout" + "attribute" + "varying" + "buffer" + "coherent" + "readonly" + "writeonly" + "precision" + "highp" + "mediump" + "lowp" + "centroid" + "sample" + "patch" + "smooth" + "flat" + "noperspective" + "invariant" + "precise" +] @type.qualifier + +"subroutine" @keyword.function + +(extension_storage_class) @storageclass + +( + (identifier) @variable.builtin + (#match? @variable.builtin "^gl_") +) From 6ad0852a70402a482841d7cc3d090553a719c19b Mon Sep 17 00:00:00 2001 From: Quinn Wilton Date: Mon, 24 Jul 2023 00:58:59 -0700 Subject: [PATCH 3/9] Add outline.scm for Elm --- crates/zed/src/languages/elm/outline.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 crates/zed/src/languages/elm/outline.scm diff --git a/crates/zed/src/languages/elm/outline.scm b/crates/zed/src/languages/elm/outline.scm new file mode 100644 index 0000000000..c220676290 --- /dev/null +++ b/crates/zed/src/languages/elm/outline.scm @@ -0,0 +1,22 @@ +(type_declaration + (type) @context + (upper_case_identifier) @name) @item + +(type_alias_declaration + (type) @context + (alias) @context + name: (upper_case_identifier) @name) @item + +(type_alias_declaration + typeExpression: + (type_expression + part: (record_type + (field_type + name: (lower_case_identifier) @name)))) @item + +(union_variant + name: (upper_case_identifier) @name) @item + +(value_declaration + functionDeclarationLeft: + (function_declaration_left(lower_case_identifier) @name)) @item From ea74734b0a8ff445609732fe334a15284a26acee Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 24 Jul 2023 08:51:44 -0700 Subject: [PATCH 4/9] Touch up elm tree sitter integration --- crates/zed/src/languages/elm/highlights.scm | 1 + crates/zed/src/languages/elm/outline.scm | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/zed/src/languages/elm/highlights.scm b/crates/zed/src/languages/elm/highlights.scm index f6be193f83..e20873af1b 100644 --- a/crates/zed/src/languages/elm/highlights.scm +++ b/crates/zed/src/languages/elm/highlights.scm @@ -53,6 +53,7 @@ (union_variant(upper_case_identifier) @variant) (union_pattern) @variant + (value_expr(upper_case_qid(upper_case_identifier)) @type) [ diff --git a/crates/zed/src/languages/elm/outline.scm b/crates/zed/src/languages/elm/outline.scm index c220676290..88ff9a5af2 100644 --- a/crates/zed/src/languages/elm/outline.scm +++ b/crates/zed/src/languages/elm/outline.scm @@ -12,11 +12,10 @@ (type_expression part: (record_type (field_type - name: (lower_case_identifier) @name)))) @item + name: (lower_case_identifier) @name) @item))) (union_variant name: (upper_case_identifier) @name) @item -(value_declaration - functionDeclarationLeft: - (function_declaration_left(lower_case_identifier) @name)) @item +(type_annotation + name: (_) @name) @item From d95c4fdb2b182c0ae6238614cdc966b829646de4 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Mon, 24 Jul 2023 09:01:15 -0700 Subject: [PATCH 5/9] Remove unbound highlight queries --- crates/zed/src/languages/elm/highlights.scm | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/zed/src/languages/elm/highlights.scm b/crates/zed/src/languages/elm/highlights.scm index e20873af1b..3ab1028a3a 100644 --- a/crates/zed/src/languages/elm/highlights.scm +++ b/crates/zed/src/languages/elm/highlights.scm @@ -51,9 +51,6 @@ (type_ref) @type (type_alias_declaration name: (upper_case_identifier) @type) -(union_variant(upper_case_identifier) @variant) -(union_pattern) @variant - (value_expr(upper_case_qid(upper_case_identifier)) @type) [ From fbe01089598fee96a5bbf87a44161dba330d7ec8 Mon Sep 17 00:00:00 2001 From: Quinn Wilton Date: Mon, 24 Jul 2023 10:44:56 -0700 Subject: [PATCH 6/9] Highlight Elm arrows as keywords --- crates/zed/src/languages/elm/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/zed/src/languages/elm/highlights.scm b/crates/zed/src/languages/elm/highlights.scm index 3ab1028a3a..be66578453 100644 --- a/crates/zed/src/languages/elm/highlights.scm +++ b/crates/zed/src/languages/elm/highlights.scm @@ -14,10 +14,10 @@ (import) (module) (type) + (arrow) ] @keyword [ - (arrow) (eq) (operator_identifier) (colon) From 62ee52a5fc6e98409aa25e9e6dd7b815068f42be Mon Sep 17 00:00:00 2001 From: Quinn Wilton Date: Mon, 24 Jul 2023 10:45:15 -0700 Subject: [PATCH 7/9] Highlight qualified Elm function calls --- crates/zed/src/languages/elm/highlights.scm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/zed/src/languages/elm/highlights.scm b/crates/zed/src/languages/elm/highlights.scm index be66578453..5838aa4796 100644 --- a/crates/zed/src/languages/elm/highlights.scm +++ b/crates/zed/src/languages/elm/highlights.scm @@ -26,6 +26,11 @@ (type_annotation(lower_case_identifier) @function) (port_annotation(lower_case_identifier) @function) (function_declaration_left(lower_case_identifier) @function.definition) + +(function_call_expr + target: (value_expr + name: (value_qid (dot) (lower_case_identifier) @function))) + (function_call_expr target: (value_expr) @identifier) (exposed_value(lower_case_identifier) @function) From 3cc88904bfa33f2fd84aa75271b4df851c2148dd Mon Sep 17 00:00:00 2001 From: Quinn Wilton Date: Mon, 24 Jul 2023 10:45:46 -0700 Subject: [PATCH 8/9] Add all Elm functions to the outline, including locals --- crates/zed/src/languages/elm/outline.scm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/zed/src/languages/elm/outline.scm b/crates/zed/src/languages/elm/outline.scm index 88ff9a5af2..1d7d5a70b0 100644 --- a/crates/zed/src/languages/elm/outline.scm +++ b/crates/zed/src/languages/elm/outline.scm @@ -17,5 +17,6 @@ (union_variant name: (upper_case_identifier) @name) @item -(type_annotation - name: (_) @name) @item +(value_declaration + functionDeclarationLeft: + (function_declaration_left(lower_case_identifier) @name)) @item From e199a6a3a1024a4f49ed5bc9dd68c025e3d4ff66 Mon Sep 17 00:00:00 2001 From: Quinn Wilton Date: Mon, 24 Jul 2023 10:55:15 -0700 Subject: [PATCH 9/9] Highlight all Elm function calls --- crates/zed/src/languages/elm/highlights.scm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/zed/src/languages/elm/highlights.scm b/crates/zed/src/languages/elm/highlights.scm index 5838aa4796..5723c7eecb 100644 --- a/crates/zed/src/languages/elm/highlights.scm +++ b/crates/zed/src/languages/elm/highlights.scm @@ -29,9 +29,7 @@ (function_call_expr target: (value_expr - name: (value_qid (dot) (lower_case_identifier) @function))) - -(function_call_expr target: (value_expr) @identifier) + name: (value_qid (lower_case_identifier) @function))) (exposed_value(lower_case_identifier) @function) (exposed_type(upper_case_identifier) @type)