From 7b88fc5cda9dbf1dfa748fb20126337e395f305b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Bergstr=C3=B6m?= Date: Sun, 21 Jul 2024 17:38:24 +0200 Subject: [PATCH] erlang: Add Erlang Language Platform support (#14879) Added support for the [Erlang Language Platform](https://whatsapp.github.io/erlang-language-platform/) language server to the Erlang extension. Release Notes: - N/A Co-authored-by: Marshall Bowers --- extensions/erlang/extension.toml | 6 +++- extensions/erlang/src/erlang.rs | 14 ++++++-- extensions/erlang/src/language_servers.rs | 2 ++ .../erlang_language_platform.rs | 33 +++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 extensions/erlang/src/language_servers/erlang_language_platform.rs diff --git a/extensions/erlang/extension.toml b/extensions/erlang/extension.toml index 944dadc1bb..3d9dbb8675 100644 --- a/extensions/erlang/extension.toml +++ b/extensions/erlang/extension.toml @@ -3,13 +3,17 @@ name = "Erlang" description = "Erlang support." version = "0.0.1" schema_version = 1 -authors = ["Dairon M "] +authors = ["Dairon M ", "Fabian Bergström "] repository = "https://github.com/zed-industries/zed" [language_servers.erlang-ls] name = "Erlang Language Server" language = "Erlang" +[language_servers.elp] +name = "Erlang Language Platform" +language = "Erlang" + [grammars.erlang] repository = "https://github.com/WhatsApp/tree-sitter-erlang" commit = "57e69513efd831f9cc8207d65d96bad917ca4aa4" diff --git a/extensions/erlang/src/erlang.rs b/extensions/erlang/src/erlang.rs index c23496ca4b..887a0d2a3f 100644 --- a/extensions/erlang/src/erlang.rs +++ b/extensions/erlang/src/erlang.rs @@ -2,15 +2,19 @@ mod language_servers; use zed_extension_api::{self as zed, Result}; -use crate::language_servers::ErlangLs; +use crate::language_servers::{ErlangLanguagePlatform, ErlangLs}; struct ErlangExtension { erlang_ls: Option, + erlang_language_platform: Option, } impl zed::Extension for ErlangExtension { fn new() -> Self { - Self { erlang_ls: None } + Self { + erlang_ls: None, + erlang_language_platform: None, + } } fn language_server_command( @@ -28,6 +32,12 @@ impl zed::Extension for ErlangExtension { env: Default::default(), }) } + ErlangLanguagePlatform::LANGUAGE_SERVER_ID => { + let erlang_language_platform = self + .erlang_language_platform + .get_or_insert_with(|| ErlangLanguagePlatform::new()); + erlang_language_platform.language_server_command(language_server_id, worktree) + } language_server_id => Err(format!("unknown language server: {language_server_id}")), } } diff --git a/extensions/erlang/src/language_servers.rs b/extensions/erlang/src/language_servers.rs index 388484e3c8..cefa451ae8 100644 --- a/extensions/erlang/src/language_servers.rs +++ b/extensions/erlang/src/language_servers.rs @@ -1,3 +1,5 @@ +mod erlang_language_platform; mod erlang_ls; +pub use erlang_language_platform::*; pub use erlang_ls::*; diff --git a/extensions/erlang/src/language_servers/erlang_language_platform.rs b/extensions/erlang/src/language_servers/erlang_language_platform.rs new file mode 100644 index 0000000000..d5642f6097 --- /dev/null +++ b/extensions/erlang/src/language_servers/erlang_language_platform.rs @@ -0,0 +1,33 @@ +use zed_extension_api::{self as zed, LanguageServerId, Result}; + +pub struct ErlangLanguagePlatform; + +impl ErlangLanguagePlatform { + pub const LANGUAGE_SERVER_ID: &'static str = "elp"; + + pub fn new() -> Self { + Self + } + + pub fn language_server_command( + &mut self, + language_server_id: &LanguageServerId, + worktree: &zed::Worktree, + ) -> Result { + Ok(zed::Command { + command: self.language_server_binary_path(language_server_id, worktree)?, + args: vec!["server".to_string()], + env: Default::default(), + }) + } + + fn language_server_binary_path( + &mut self, + _language_server_id: &LanguageServerId, + worktree: &zed::Worktree, + ) -> Result { + worktree + .which("elp") + .ok_or_else(|| "elp must be installed and available on your $PATH".to_string()) + } +}