From b57921186113f15c812743ff7eddc931b6cfbd9c Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 21 Mar 2023 14:39:20 -0400 Subject: [PATCH] Report if language server requires Node or not --- crates/language/src/language.rs | 12 ++++++++++++ crates/zed/src/languages/c.rs | 4 ++++ crates/zed/src/languages/elixir.rs | 4 ++++ crates/zed/src/languages/go.rs | 4 ++++ crates/zed/src/languages/html.rs | 6 +++++- crates/zed/src/languages/json.rs | 6 +++++- crates/zed/src/languages/language_plugin.rs | 13 ++++++++++++- crates/zed/src/languages/lua.rs | 6 +++++- crates/zed/src/languages/python.rs | 6 +++++- crates/zed/src/languages/ruby.rs | 6 +++++- crates/zed/src/languages/rust.rs | 4 ++++ crates/zed/src/languages/typescript.rs | 6 +++++- crates/zed/src/languages/yaml.rs | 6 +++++- 13 files changed, 75 insertions(+), 8 deletions(-) diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index ed02b8de59..201eb8c7fc 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -77,6 +77,12 @@ pub trait ToLspPosition { #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct LanguageServerName(pub Arc); +#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)] +pub enum ServerExecutionKind { + Launch, + Node, +} + /// Represents a Language Server, with certain cached sync properties. /// Uses [`LspAdapter`] under the hood, but calls all 'static' methods /// once at startup, and caches the results. @@ -172,6 +178,8 @@ impl CachedLspAdapter { pub trait LspAdapter: 'static + Send + Sync { async fn name(&self) -> LanguageServerName; + async fn server_execution_kind(&self) -> ServerExecutionKind; + async fn fetch_latest_server_version( &self, http: Arc, @@ -1442,6 +1450,10 @@ impl LspAdapter for Arc { LanguageServerName(self.name.into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Launch + } + async fn fetch_latest_server_version( &self, _: Arc, diff --git a/crates/zed/src/languages/c.rs b/crates/zed/src/languages/c.rs index 9fbb12857f..826de55874 100644 --- a/crates/zed/src/languages/c.rs +++ b/crates/zed/src/languages/c.rs @@ -16,6 +16,10 @@ impl super::LspAdapter for CLspAdapter { LanguageServerName("clangd".into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Launch + } + async fn fetch_latest_server_version( &self, http: Arc, diff --git a/crates/zed/src/languages/elixir.rs b/crates/zed/src/languages/elixir.rs index 75b35bb630..0bdbaddd68 100644 --- a/crates/zed/src/languages/elixir.rs +++ b/crates/zed/src/languages/elixir.rs @@ -17,6 +17,10 @@ impl LspAdapter for ElixirLspAdapter { LanguageServerName("elixir-ls".into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Launch + } + async fn fetch_latest_server_version( &self, http: Arc, diff --git a/crates/zed/src/languages/go.rs b/crates/zed/src/languages/go.rs index dd819338d0..4e34b126a1 100644 --- a/crates/zed/src/languages/go.rs +++ b/crates/zed/src/languages/go.rs @@ -23,6 +23,10 @@ impl super::LspAdapter for GoLspAdapter { LanguageServerName("gopls".into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Launch + } + async fn server_args(&self) -> Vec { vec!["-mode=stdio".into()] } diff --git a/crates/zed/src/languages/html.rs b/crates/zed/src/languages/html.rs index 5497841d88..2fcf3b2699 100644 --- a/crates/zed/src/languages/html.rs +++ b/crates/zed/src/languages/html.rs @@ -3,7 +3,7 @@ use anyhow::{anyhow, Context, Result}; use async_trait::async_trait; use client::http::HttpClient; use futures::StreamExt; -use language::{LanguageServerName, LspAdapter}; +use language::{LanguageServerName, LspAdapter, ServerExecutionKind}; use serde_json::json; use smol::fs; use std::{any::Any, path::PathBuf, sync::Arc}; @@ -22,6 +22,10 @@ impl LspAdapter for HtmlLspAdapter { LanguageServerName("vscode-html-language-server".into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Node + } + async fn server_args(&self) -> Vec { vec!["--stdio".into()] } diff --git a/crates/zed/src/languages/json.rs b/crates/zed/src/languages/json.rs index d5c59d28d1..9df5bec6c0 100644 --- a/crates/zed/src/languages/json.rs +++ b/crates/zed/src/languages/json.rs @@ -6,7 +6,7 @@ use client::http::HttpClient; use collections::HashMap; use futures::{future::BoxFuture, io::BufReader, FutureExt, StreamExt}; use gpui::MutableAppContext; -use language::{LanguageRegistry, LanguageServerName, LspAdapter}; +use language::{LanguageRegistry, LanguageServerName, LspAdapter, ServerExecutionKind}; use serde_json::json; use settings::{keymap_file_json_schema, settings_file_json_schema}; use smol::fs::{self, File}; @@ -37,6 +37,10 @@ impl LspAdapter for JsonLspAdapter { LanguageServerName("json-language-server".into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Node + } + async fn server_args(&self) -> Vec { vec!["--stdio".into()] } diff --git a/crates/zed/src/languages/language_plugin.rs b/crates/zed/src/languages/language_plugin.rs index bd9a9d005f..de3cabcef8 100644 --- a/crates/zed/src/languages/language_plugin.rs +++ b/crates/zed/src/languages/language_plugin.rs @@ -4,7 +4,7 @@ use client::http::HttpClient; use collections::HashMap; use futures::lock::Mutex; use gpui::executor::Background; -use language::{LanguageServerName, LspAdapter}; +use language::{LanguageServerName, LspAdapter, ServerExecutionKind}; use plugin_runtime::{Plugin, PluginBinary, PluginBuilder, WasiFn}; use std::{any::Any, path::PathBuf, sync::Arc}; use util::ResultExt; @@ -32,6 +32,7 @@ pub async fn new_json(executor: Arc) -> Result { pub struct PluginLspAdapter { name: WasiFn<(), String>, + server_execution_kind: WasiFn<(), ServerExecutionKind>, server_args: WasiFn<(), Vec>, fetch_latest_server_version: WasiFn<(), Option>, fetch_server_binary: WasiFn<(PathBuf, String), Result>, @@ -47,6 +48,7 @@ impl PluginLspAdapter { pub async fn new(mut plugin: Plugin, executor: Arc) -> Result { Ok(Self { name: plugin.function("name")?, + server_execution_kind: plugin.function("server_execution_kind")?, server_args: plugin.function("server_args")?, fetch_latest_server_version: plugin.function("fetch_latest_server_version")?, fetch_server_binary: plugin.function("fetch_server_binary")?, @@ -72,6 +74,15 @@ impl LspAdapter for PluginLspAdapter { LanguageServerName(name.into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + self.runtime + .lock() + .await + .call(&self.server_execution_kind, ()) + .await + .unwrap() + } + async fn server_args<'a>(&'a self) -> Vec { self.runtime .lock() diff --git a/crates/zed/src/languages/lua.rs b/crates/zed/src/languages/lua.rs index 4bcffca908..c51235e1f1 100644 --- a/crates/zed/src/languages/lua.rs +++ b/crates/zed/src/languages/lua.rs @@ -6,7 +6,7 @@ use async_tar::Archive; use async_trait::async_trait; use client::http::HttpClient; use futures::{io::BufReader, StreamExt}; -use language::LanguageServerName; +use language::{LanguageServerName, ServerExecutionKind}; use smol::fs; use util::{async_iife, ResultExt}; @@ -21,6 +21,10 @@ impl super::LspAdapter for LuaLspAdapter { LanguageServerName("lua-language-server".into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Launch + } + async fn server_args(&self) -> Vec { vec![ "--logpath=~/lua-language-server.log".into(), diff --git a/crates/zed/src/languages/python.rs b/crates/zed/src/languages/python.rs index 1391494ab1..a980e2ad75 100644 --- a/crates/zed/src/languages/python.rs +++ b/crates/zed/src/languages/python.rs @@ -3,7 +3,7 @@ use anyhow::{anyhow, Context, Result}; use async_trait::async_trait; use client::http::HttpClient; use futures::StreamExt; -use language::{LanguageServerName, LspAdapter}; +use language::{LanguageServerName, LspAdapter, ServerExecutionKind}; use smol::fs; use std::{any::Any, path::PathBuf, sync::Arc}; use util::ResultExt; @@ -20,6 +20,10 @@ impl LspAdapter for PythonLspAdapter { LanguageServerName("pyright".into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Node + } + async fn server_args(&self) -> Vec { vec!["--stdio".into()] } diff --git a/crates/zed/src/languages/ruby.rs b/crates/zed/src/languages/ruby.rs index cbfb5e35a7..1308610a5a 100644 --- a/crates/zed/src/languages/ruby.rs +++ b/crates/zed/src/languages/ruby.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, Result}; use async_trait::async_trait; use client::http::HttpClient; -use language::{LanguageServerName, LspAdapter}; +use language::{LanguageServerName, LspAdapter, ServerExecutionKind}; use std::{any::Any, path::PathBuf, sync::Arc}; pub struct RubyLanguageServer; @@ -12,6 +12,10 @@ impl LspAdapter for RubyLanguageServer { LanguageServerName("solargraph".into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Launch + } + async fn server_args(&self) -> Vec { vec!["stdio".into()] } diff --git a/crates/zed/src/languages/rust.rs b/crates/zed/src/languages/rust.rs index a8f7fcbc4d..1f9940ac0d 100644 --- a/crates/zed/src/languages/rust.rs +++ b/crates/zed/src/languages/rust.rs @@ -19,6 +19,10 @@ impl LspAdapter for RustLspAdapter { LanguageServerName("rust-analyzer".into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Launch + } + async fn fetch_latest_server_version( &self, http: Arc, diff --git a/crates/zed/src/languages/typescript.rs b/crates/zed/src/languages/typescript.rs index 5290158dea..3f2e25d9e6 100644 --- a/crates/zed/src/languages/typescript.rs +++ b/crates/zed/src/languages/typescript.rs @@ -3,7 +3,7 @@ use anyhow::{anyhow, Context, Result}; use async_trait::async_trait; use client::http::HttpClient; use futures::StreamExt; -use language::{LanguageServerName, LspAdapter}; +use language::{LanguageServerName, LspAdapter, ServerExecutionKind}; use serde_json::json; use smol::fs; use std::{any::Any, path::PathBuf, sync::Arc}; @@ -27,6 +27,10 @@ impl LspAdapter for TypeScriptLspAdapter { LanguageServerName("typescript-language-server".into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Node + } + async fn server_args(&self) -> Vec { ["--stdio", "--tsserver-path", "node_modules/typescript/lib"] .into_iter() diff --git a/crates/zed/src/languages/yaml.rs b/crates/zed/src/languages/yaml.rs index 9750ecce88..c179ec5b2d 100644 --- a/crates/zed/src/languages/yaml.rs +++ b/crates/zed/src/languages/yaml.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use client::http::HttpClient; use futures::{future::BoxFuture, FutureExt, StreamExt}; use gpui::MutableAppContext; -use language::{LanguageServerName, LspAdapter}; +use language::{LanguageServerName, LspAdapter, ServerExecutionKind}; use serde_json::Value; use settings::Settings; use smol::fs; @@ -24,6 +24,10 @@ impl LspAdapter for YamlLspAdapter { LanguageServerName("yaml-language-server".into()) } + async fn server_execution_kind(&self) -> ServerExecutionKind { + ServerExecutionKind::Node + } + async fn server_args(&self) -> Vec { vec!["--stdio".into()] }