elm: Extract to zed-extensions/elm repository (#22637)
This PR extracts the Elm extension to the [zed-extensions/elm](https://github.com/zed-extensions/elm) repository. Release Notes: - N/A
This commit is contained in:
parent
b1a6e2427f
commit
dd75f85ecf
11 changed files with 1 additions and 263 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -16339,13 +16339,6 @@ dependencies = [
|
|||
"zed_extension_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zed_elm"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"zed_extension_api 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zed_emmet"
|
||||
version = "0.0.3"
|
||||
|
|
|
@ -152,7 +152,6 @@ members = [
|
|||
"extensions/csharp",
|
||||
"extensions/deno",
|
||||
"extensions/elixir",
|
||||
"extensions/elm",
|
||||
"extensions/emmet",
|
||||
"extensions/erlang",
|
||||
"extensions/glsl",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Elm
|
||||
|
||||
Elm support is available through the [Elm extension](https://github.com/zed-industries/zed/tree/main/extensions/elm).
|
||||
Elm support is available through the [Elm extension](https://github.com/zed-extensions/elm).
|
||||
|
||||
- Tree Sitter: [elm-tooling/tree-sitter-elm](https://github.com/elm-tooling/tree-sitter-elm)
|
||||
- Language Server: [elm-tooling/elm-language-server](https://github.com/elm-tooling/elm-language-server)
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
[package]
|
||||
name = "zed_elm"
|
||||
version = "0.0.1"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
license = "Apache-2.0"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/elm.rs"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
zed_extension_api = "0.1.0"
|
|
@ -1 +0,0 @@
|
|||
../../LICENSE-APACHE
|
|
@ -1,15 +0,0 @@
|
|||
id = "elm"
|
||||
name = "Elm"
|
||||
description = "Elm support."
|
||||
version = "0.0.1"
|
||||
schema_version = 1
|
||||
authors = ["Quinn Wilton <quinn@quinnwilton.com>", "Andrey Kuzmin <hi@unsoundscapes.com>"]
|
||||
repository = "https://github.com/zed-industries/zed"
|
||||
|
||||
[language_servers.elm-language-server]
|
||||
name = "elm-language-server"
|
||||
language = "Elm"
|
||||
|
||||
[grammars.elm]
|
||||
repository = "https://github.com/elm-tooling/tree-sitter-elm"
|
||||
commit = "09dbf221d7491dc8d8839616b27c21b9c025c457"
|
|
@ -1,13 +0,0 @@
|
|||
name = "Elm"
|
||||
grammar = "elm"
|
||||
path_suffixes = ["elm"]
|
||||
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, not_in = ["string"] },
|
||||
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
||||
]
|
||||
tab_size = 2
|
|
@ -1,72 +0,0 @@
|
|||
[
|
||||
"if"
|
||||
"then"
|
||||
"else"
|
||||
"let"
|
||||
"in"
|
||||
(case)
|
||||
(of)
|
||||
(backslash)
|
||||
(as)
|
||||
(port)
|
||||
(exposing)
|
||||
(alias)
|
||||
(import)
|
||||
(module)
|
||||
(type)
|
||||
(arrow)
|
||||
] @keyword
|
||||
|
||||
[
|
||||
(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
|
||||
name: (value_qid (lower_case_identifier) @function)))
|
||||
|
||||
(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)
|
||||
|
||||
(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
|
|
@ -1,2 +0,0 @@
|
|||
((glsl_content) @content
|
||||
(#set! "language" "glsl"))
|
|
@ -1,22 +0,0 @@
|
|||
(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
|
|
@ -1,113 +0,0 @@
|
|||
use std::{env, fs};
|
||||
use zed::{
|
||||
serde_json::{self, Value},
|
||||
settings::LspSettings,
|
||||
};
|
||||
use zed_extension_api::{self as zed, Result};
|
||||
|
||||
const SERVER_PATH: &str = "node_modules/@elm-tooling/elm-language-server/out/node/index.js";
|
||||
const PACKAGE_NAME: &str = "@elm-tooling/elm-language-server";
|
||||
|
||||
struct ElmExtension {
|
||||
did_find_server: bool,
|
||||
}
|
||||
|
||||
impl ElmExtension {
|
||||
fn server_exists(&self) -> bool {
|
||||
fs::metadata(SERVER_PATH).map_or(false, |stat| stat.is_file())
|
||||
}
|
||||
|
||||
fn server_script_path(&mut self, server_id: &zed::LanguageServerId) -> Result<String> {
|
||||
let server_exists = self.server_exists();
|
||||
if self.did_find_server && server_exists {
|
||||
return Ok(SERVER_PATH.to_string());
|
||||
}
|
||||
|
||||
zed::set_language_server_installation_status(
|
||||
server_id,
|
||||
&zed::LanguageServerInstallationStatus::CheckingForUpdate,
|
||||
);
|
||||
let version = zed::npm_package_latest_version(PACKAGE_NAME)?;
|
||||
|
||||
if !server_exists
|
||||
|| zed::npm_package_installed_version(PACKAGE_NAME)?.as_ref() != Some(&version)
|
||||
{
|
||||
zed::set_language_server_installation_status(
|
||||
server_id,
|
||||
&zed::LanguageServerInstallationStatus::Downloading,
|
||||
);
|
||||
let result = zed::npm_install_package(PACKAGE_NAME, &version);
|
||||
match result {
|
||||
Ok(()) => {
|
||||
if !self.server_exists() {
|
||||
Err(format!(
|
||||
"installed package '{PACKAGE_NAME}' did not contain expected path '{SERVER_PATH}'",
|
||||
))?;
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
if !self.server_exists() {
|
||||
Err(error)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.did_find_server = true;
|
||||
Ok(SERVER_PATH.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl zed::Extension for ElmExtension {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
did_find_server: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn language_server_command(
|
||||
&mut self,
|
||||
server_id: &zed::LanguageServerId,
|
||||
_worktree: &zed::Worktree,
|
||||
) -> Result<zed::Command> {
|
||||
let server_path = self.server_script_path(server_id)?;
|
||||
Ok(zed::Command {
|
||||
command: zed::node_binary_path()?,
|
||||
args: vec![
|
||||
env::current_dir()
|
||||
.unwrap()
|
||||
.join(&server_path)
|
||||
.to_string_lossy()
|
||||
.to_string(),
|
||||
"--stdio".to_string(),
|
||||
],
|
||||
env: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
fn language_server_workspace_configuration(
|
||||
&mut self,
|
||||
server_id: &zed::LanguageServerId,
|
||||
worktree: &zed::Worktree,
|
||||
) -> Result<Option<Value>> {
|
||||
// elm-language-server expects workspace didChangeConfiguration notification
|
||||
// params to be the same as lsp initialization_options
|
||||
let initialization_options = LspSettings::for_worktree(server_id.as_ref(), worktree)?
|
||||
.initialization_options
|
||||
.clone()
|
||||
.unwrap_or_default();
|
||||
|
||||
Ok(Some(match initialization_options.clone().as_object_mut() {
|
||||
Some(op) => {
|
||||
// elm-language-server requests workspace configuration
|
||||
// for the `elmLS` section, so we have to nest
|
||||
// another copy of initialization_options there
|
||||
op.insert("elmLS".into(), initialization_options);
|
||||
serde_json::to_value(op).unwrap_or_default()
|
||||
}
|
||||
None => initialization_options,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
zed::register_extension!(ElmExtension);
|
Loading…
Add table
Add a link
Reference in a new issue