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 <elliott.codes@gmail.com>
This commit is contained in:
Fabian Bergström 2024-07-21 17:38:24 +02:00 committed by GitHub
parent 2f3df9fd93
commit 7b88fc5cda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 52 additions and 3 deletions

View File

@ -3,13 +3,17 @@ name = "Erlang"
description = "Erlang support."
version = "0.0.1"
schema_version = 1
authors = ["Dairon M <dairon.medina@gmail.com>"]
authors = ["Dairon M <dairon.medina@gmail.com>", "Fabian Bergström <fabian@fmbb.se>"]
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"

View File

@ -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<ErlangLs>,
erlang_language_platform: Option<ErlangLanguagePlatform>,
}
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}")),
}
}

View File

@ -1,3 +1,5 @@
mod erlang_language_platform;
mod erlang_ls;
pub use erlang_language_platform::*;
pub use erlang_ls::*;

View File

@ -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<zed::Command> {
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<String> {
worktree
.which("elp")
.ok_or_else(|| "elp must be installed and available on your $PATH".to_string())
}
}