diff --git a/Cargo.lock b/Cargo.lock index e187738528..a9294e4adc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5297,6 +5297,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-go" +version = "0.19.1" +source = "git+https://github.com/tree-sitter/tree-sitter-go?rev=aeb2f33b366fd78d5789ff104956ce23508b85db#aeb2f33b366fd78d5789ff104956ce23508b85db" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-json" version = "0.19.0" @@ -6048,6 +6057,7 @@ dependencies = [ "tree-sitter", "tree-sitter-c", "tree-sitter-cpp", + "tree-sitter-go", "tree-sitter-json 0.20.0", "tree-sitter-markdown", "tree-sitter-rust", diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index d18adbd98e..2f1ab109af 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -89,6 +89,7 @@ toml = "0.5" tree-sitter = "0.20.6" tree-sitter-c = "0.20.1" tree-sitter-cpp = "0.20.0" +tree-sitter-go = { git = "https://github.com/tree-sitter/tree-sitter-go", rev = "aeb2f33b366fd78d5789ff104956ce23508b85db" } tree-sitter-json = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "137e1ce6a02698fc246cdb9c6b886ed1de9a1ed8" } tree-sitter-rust = "0.20.1" tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" } diff --git a/crates/zed/src/languages/go/brackets.scm b/crates/zed/src/languages/go/brackets.scm new file mode 100644 index 0000000000..9e8c9cd93c --- /dev/null +++ b/crates/zed/src/languages/go/brackets.scm @@ -0,0 +1,3 @@ +("[" @open "]" @close) +("{" @open "}" @close) +("\"" @open "\"" @close) diff --git a/crates/zed/src/languages/go/config.toml b/crates/zed/src/languages/go/config.toml new file mode 100644 index 0000000000..fc6167e311 --- /dev/null +++ b/crates/zed/src/languages/go/config.toml @@ -0,0 +1,11 @@ +name = "Go" +path_suffixes = ["go"] +line_comment = "// " +autoclose_before = ";:.,=}])>" +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 }, + { start = "/*", end = " */", close = true, newline = false }, +] diff --git a/crates/zed/src/languages/go/highlights.scm b/crates/zed/src/languages/go/highlights.scm new file mode 100644 index 0000000000..6a9be8aae0 --- /dev/null +++ b/crates/zed/src/languages/go/highlights.scm @@ -0,0 +1,107 @@ +(identifier) @variable +(type_identifier) @type +(field_identifier) @property + +(call_expression + function: (identifier) @function) + +(call_expression + function: (selector_expression + field: (field_identifier) @function.method)) + +(function_declaration + name: (identifier) @function) + +(method_declaration + name: (field_identifier) @function.method) + +[ + "--" + "-" + "-=" + ":=" + "!" + "!=" + "..." + "*" + "*" + "*=" + "/" + "/=" + "&" + "&&" + "&=" + "%" + "%=" + "^" + "^=" + "+" + "++" + "+=" + "<-" + "<" + "<<" + "<<=" + "<=" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "|" + "|=" + "||" + "~" +] @operator + +[ + "break" + "case" + "chan" + "const" + "continue" + "default" + "defer" + "else" + "fallthrough" + "for" + "func" + "go" + "goto" + "if" + "import" + "interface" + "map" + "package" + "range" + "return" + "select" + "struct" + "switch" + "type" + "var" +] @keyword + +[ + (interpreted_string_literal) + (raw_string_literal) + (rune_literal) +] @string + +(escape_sequence) @escape + +[ + (int_literal) + (float_literal) + (imaginary_literal) +] @number + +[ + (true) + (false) + (nil) + (iota) +] @constant.builtin + +(comment) @comment diff --git a/crates/zed/src/languages/go/indents.scm b/crates/zed/src/languages/go/indents.scm new file mode 100644 index 0000000000..abbb72eb37 --- /dev/null +++ b/crates/zed/src/languages/go/indents.scm @@ -0,0 +1,9 @@ +[ + (assignment_statement) + (call_expression) + (selector_expression) +] @indent + +(_ "[" "]" @end) @indent +(_ "{" "}" @end) @indent +(_ "(" ")" @end) @indent diff --git a/crates/zed/src/languages/go/outline.scm b/crates/zed/src/languages/go/outline.scm new file mode 100644 index 0000000000..1a754d2da5 --- /dev/null +++ b/crates/zed/src/languages/go/outline.scm @@ -0,0 +1,26 @@ +(type_declaration + "type" @context + (type_spec + name: (_) @name)) @item + +(function_declaration + "func" @context + name: (identifier) @name) @item + +(method_declaration + "func" @context + receiver: (parameter_list + (parameter_declaration + type: (_) @context)) + name: (field_identifier) @name) @item + +(const_declaration + "const" @context + (const_spec + name: (identifier) @name)) @item + +(source_file + (var_declaration + "var" @context + (var_spec + name: (identifier) @name)) @item)