diff --git a/Cargo.lock b/Cargo.lock index 04b3dee49c..b02087080a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8477,6 +8477,15 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "tree-sitter-haskell" +version = "0.14.0" +source = "git+https://github.com/tree-sitter/tree-sitter-haskell?rev=dd924b8df1eb76261f009e149fc6f3291c5081c2#dd924b8df1eb76261f009e149fc6f3291c5081c2" +dependencies = [ + "cc", + "tree-sitter", +] + [[package]] name = "tree-sitter-heex" version = "0.0.1" @@ -9740,6 +9749,7 @@ dependencies = [ "tree-sitter-embedded-template", "tree-sitter-glsl", "tree-sitter-go", + "tree-sitter-haskell", "tree-sitter-heex", "tree-sitter-html", "tree-sitter-json 0.20.0", diff --git a/Cargo.toml b/Cargo.toml index 7acc460af8..11e426a2ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -150,6 +150,7 @@ tree-sitter-python = "0.20.2" tree-sitter-toml = { git = "https://github.com/tree-sitter/tree-sitter-toml", rev = "342d9be207c2dba869b9967124c679b5e6fd0ebe" } tree-sitter-typescript = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259" } tree-sitter-ruby = "0.20.0" +tree-sitter-haskell = { git = "https://github.com/tree-sitter/tree-sitter-haskell", rev = "dd924b8df1eb76261f009e149fc6f3291c5081c2" } tree-sitter-html = "0.19.0" tree-sitter-scheme = { git = "https://github.com/6cdh/tree-sitter-scheme", rev = "af0fd1fa452cb2562dc7b5c8a8c55551c39273b9"} tree-sitter-svelte = { git = "https://github.com/Himujjal/tree-sitter-svelte", rev = "697bb515471871e85ff799ea57a76298a71a9cca"} diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 683a7c6fed..813f3e7075 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -130,6 +130,7 @@ tree-sitter-python.workspace = true tree-sitter-toml.workspace = true tree-sitter-typescript.workspace = true tree-sitter-ruby.workspace = true +tree-sitter-haskell.workspace = true tree-sitter-html.workspace = true tree-sitter-php.workspace = true tree-sitter-scheme.workspace = true diff --git a/crates/zed/src/languages.rs b/crates/zed/src/languages.rs index 3fdcad46fe..474fce456a 100644 --- a/crates/zed/src/languages.rs +++ b/crates/zed/src/languages.rs @@ -13,6 +13,7 @@ mod c; mod css; mod elixir; mod go; +mod haskell; mod html; mod json; #[cfg(feature = "plugin_runtime")] @@ -160,6 +161,7 @@ pub fn init( Arc::new(tailwind::TailwindLspAdapter::new(node_runtime.clone())), ], ); + language("haskell", tree_sitter_haskell::language(), vec![]); language( "html", tree_sitter_html::language(), diff --git a/crates/zed/src/languages/haskell.rs b/crates/zed/src/languages/haskell.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/crates/zed/src/languages/haskell.rs @@ -0,0 +1 @@ + diff --git a/crates/zed/src/languages/haskell/brackets.scm b/crates/zed/src/languages/haskell/brackets.scm new file mode 100644 index 0000000000..191fd9c084 --- /dev/null +++ b/crates/zed/src/languages/haskell/brackets.scm @@ -0,0 +1,3 @@ +("(" @open ")" @close) +("[" @open "]" @close) +("{" @open "}" @close) diff --git a/crates/zed/src/languages/haskell/config.toml b/crates/zed/src/languages/haskell/config.toml new file mode 100644 index 0000000000..15fdd7b78e --- /dev/null +++ b/crates/zed/src/languages/haskell/config.toml @@ -0,0 +1,12 @@ +name = "Haskell" +path_suffixes = ["hs"] +autoclose_before = ",=)}]" +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 = false, newline = false }, + { start = "'", end = "'", close = false, newline = false }, +] diff --git a/crates/zed/src/languages/haskell/highlights.scm b/crates/zed/src/languages/haskell/highlights.scm new file mode 100644 index 0000000000..3ab843e833 --- /dev/null +++ b/crates/zed/src/languages/haskell/highlights.scm @@ -0,0 +1,156 @@ +;; Copyright 2022 nvim-treesitter +;; +;; Licensed under the Apache License, Version 2.0 (the "License"); +;; you may not use this file except in compliance with the License. +;; You may obtain a copy of the License at +;; +;; http://www.apache.org/licenses/LICENSE-2.0 +;; +;; Unless required by applicable law or agreed to in writing, software +;; distributed under the License is distributed on an "AS IS" BASIS, +;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +;; See the License for the specific language governing permissions and +;; limitations under the License. + +;; ---------------------------------------------------------------------------- +;; Literals and comments + +(integer) @number +(exp_negation) @number +(exp_literal (float)) @float +(char) @character +(string) @string + +(con_unit) @symbol ; unit, as in () + +(comment) @comment + + +;; ---------------------------------------------------------------------------- +;; Punctuation + +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @punctuation.bracket + +[ + (comma) + ";" +] @punctuation.delimiter + + +;; ---------------------------------------------------------------------------- +;; Keywords, operators, includes + +[ + "forall" + "∀" +] @repeat + +(pragma) @constant.macro + +[ + "if" + "then" + "else" + "case" + "of" +] @conditional + +(exp_lambda_cases "\\" ("cases" @conditional)) + +[ + "import" + "qualified" + "module" +] @include + +[ + (operator) + (constructor_operator) + (type_operator) + (tycon_arrow) + (qualified_module) ; grabs the `.` (dot), ex: import System.IO + (all_names) + (wildcard) + "=" + "|" + "::" + "=>" + "->" + "<-" + "\\" + "`" + "@" +] @operator + +(module) @namespace + +[ + (where) + "let" + "in" + "class" + "instance" + "data" + "newtype" + "family" + "type" + "as" + "hiding" + "deriving" + "via" + "stock" + "anyclass" + "do" + "mdo" + "rec" + "infix" + "infixl" + "infixr" +] @keyword + + +;; ---------------------------------------------------------------------------- +;; Functions and variables + +(variable) @variable +(pat_wildcard) @variable + +(signature name: (variable) @type) +(function + name: (variable) @function + patterns: (patterns)) +((signature (fun)) . (function (variable) @function)) +((signature (context (fun))) . (function (variable) @function)) +((signature (forall (context (fun)))) . (function (variable) @function)) + +(exp_infix (variable) @operator) ; consider infix functions as operators + +(exp_infix (exp_name) @function (#set! "priority" 101)) +(exp_apply . (exp_name (variable) @function)) +(exp_apply . (exp_name (qualified_variable (variable) @function))) + + +;; ---------------------------------------------------------------------------- +;; Types + +(type) @type +(type_variable) @type + +(constructor) @constructor + +; True or False +((constructor) @_bool (#match? @_bool "(True|False)")) @boolean + + +;; ---------------------------------------------------------------------------- +;; Quasi-quotes + +(quoter) @function +; Highlighting of quasiquote_body is handled by injections.scm diff --git a/crates/zed/src/languages/haskell/indents.scm b/crates/zed/src/languages/haskell/indents.scm new file mode 100644 index 0000000000..112b414aa4 --- /dev/null +++ b/crates/zed/src/languages/haskell/indents.scm @@ -0,0 +1,3 @@ +(_ "[" "]" @end) @indent +(_ "{" "}" @end) @indent +(_ "(" ")" @end) @indent