Report if language server requires Node or not

This commit is contained in:
Julia 2023-03-21 14:39:20 -04:00
parent d89936e4a9
commit b579211861
13 changed files with 75 additions and 8 deletions

View file

@ -77,6 +77,12 @@ pub trait ToLspPosition {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct LanguageServerName(pub Arc<str>);
#[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<dyn HttpClient>,
@ -1442,6 +1450,10 @@ impl LspAdapter for Arc<FakeLspAdapter> {
LanguageServerName(self.name.into())
}
async fn server_execution_kind(&self) -> ServerExecutionKind {
ServerExecutionKind::Launch
}
async fn fetch_latest_server_version(
&self,
_: Arc<dyn HttpClient>,

View file

@ -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<dyn HttpClient>,

View file

@ -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<dyn HttpClient>,

View file

@ -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<String> {
vec!["-mode=stdio".into()]
}

View file

@ -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<String> {
vec!["--stdio".into()]
}

View file

@ -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<String> {
vec!["--stdio".into()]
}

View file

@ -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<Background>) -> Result<PluginLspAdapter> {
pub struct PluginLspAdapter {
name: WasiFn<(), String>,
server_execution_kind: WasiFn<(), ServerExecutionKind>,
server_args: WasiFn<(), Vec<String>>,
fetch_latest_server_version: WasiFn<(), Option<String>>,
fetch_server_binary: WasiFn<(PathBuf, String), Result<PathBuf, String>>,
@ -47,6 +48,7 @@ impl PluginLspAdapter {
pub async fn new(mut plugin: Plugin, executor: Arc<Background>) -> Result<Self> {
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<String> {
self.runtime
.lock()

View file

@ -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<String> {
vec![
"--logpath=~/lua-language-server.log".into(),

View file

@ -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<String> {
vec!["--stdio".into()]
}

View file

@ -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<String> {
vec!["stdio".into()]
}

View file

@ -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<dyn HttpClient>,

View file

@ -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<String> {
["--stdio", "--tsserver-path", "node_modules/typescript/lib"]
.into_iter()

View file

@ -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<String> {
vec!["--stdio".into()]
}