Extract Haskell support into an extension (#9814)

This PR extracts Haskell support into an extension and removes the
built-in Haskell support from Zed.

I tested out the extension locally in a Nix shell using `nix-shell -p
ghc haskell-language-server` to confirm the language server still
operated as expected:

<img width="341" alt="Screenshot 2024-03-26 at 11 26 26 AM"
src="https://github.com/zed-industries/zed/assets/1486634/df16fd38-4046-4a45-ac9f-c2b85bffe5c0">

Release Notes:

- Removed built-in support for Haskell, in favor of making it available
as an extension. The Haskell extension will be suggested for download
when you open a `.hs` file.
This commit is contained in:
Marshall Bowers 2024-03-26 11:41:41 -04:00 committed by GitHub
parent 9d4c6c60fb
commit 1d6792b17d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 72 additions and 67 deletions

View file

@ -0,0 +1,16 @@
[package]
name = "zed_haskell"
version = "0.0.1"
edition = "2021"
publish = false
license = "Apache-2.0"
[lints]
workspace = true
[lib]
path = "src/haskell.rs"
crate-type = ["cdylib"]
[dependencies]
zed_extension_api = "0.0.4"

View file

@ -0,0 +1 @@
../../LICENSE-APACHE

View file

@ -0,0 +1,19 @@
id = "haskell"
name = "Haskell"
description = "Haskell support for Zed"
version = "0.0.1"
schema_version = 1
authors = [
"Marshall Bowers <elliott.codes@gmail.com>",
"Pseudomata <pseudomata@proton.me>",
"Lei <45155667+leifu1128@users.noreply.github.com>"
]
repository = "https://github.com/zed-industries/zed"
[language_servers.hls]
name = "Haskell Language Server"
language = "Haskell"
[grammars.haskell]
repository = "https://github.com/tree-sitter/tree-sitter-haskell"
commit = "8a99848fc734f9c4ea523b3f2a07df133cbbcec2"

View file

@ -0,0 +1,3 @@
("(" @open ")" @close)
("[" @open "]" @close)
("{" @open "}" @close)

View file

@ -0,0 +1,14 @@
name = "Haskell"
grammar = "haskell"
path_suffixes = ["hs"]
autoclose_before = ",=)}]"
line_comments = ["-- "]
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 },
{ start = "'", end = "'", close = true, newline = false },
{ start = "`", end = "`", close = true, newline = false },
]

View file

@ -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"
"∀"
] @keyword
(pragma) @constant
[
"if"
"then"
"else"
"case"
"of"
] @keyword
(exp_lambda_cases "\\" ("cases" @variant))
[
"import"
"qualified"
"module"
] @keyword
[
(operator)
(constructor_operator)
(type_operator)
(tycon_arrow)
(qualified_module) ; grabs the `.` (dot), ex: import System.IO
(all_names)
(wildcard)
"="
"|"
"::"
"=>"
"->"
"<-"
"\\"
"`"
"@"
] @operator
(module) @title
[
(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

View file

@ -0,0 +1,3 @@
(_ "[" "]" @end) @indent
(_ "{" "}" @end) @indent
(_ "(" ")" @end) @indent

View file

@ -0,0 +1,26 @@
(adt
"data" @context
name: (type) @name) @item
(type_alias
"type" @context
name: (type) @name) @item
(newtype
"newtype" @context
name: (type) @name) @item
(signature
name: (variable) @name) @item
(class
"class" @context
(class_head) @name) @item
(instance
"instance" @context
(instance_head) @name) @item
(foreign_import
"foreign" @context
(impent) @name) @item

View file

@ -0,0 +1,27 @@
use zed_extension_api::{self as zed, Result};
struct HaskellExtension;
impl zed::Extension for HaskellExtension {
fn new() -> Self {
Self
}
fn language_server_command(
&mut self,
_config: zed::LanguageServerConfig,
worktree: &zed::Worktree,
) -> Result<zed::Command> {
let path = worktree
.which("haskell-language-server-wrapper")
.ok_or_else(|| "hls must be installed via ghcup".to_string())?;
Ok(zed::Command {
command: path,
args: vec!["lsp".to_string()],
env: Default::default(),
})
}
}
zed::register_extension!(HaskellExtension);