Remove installation test binary from language server instance

This commit is contained in:
Julia 2023-06-23 13:24:50 -04:00
parent 374c1a3a3e
commit 7caa096bd0
4 changed files with 18 additions and 55 deletions

View file

@ -15,7 +15,7 @@ use language::{
ToPointUtf16, ToPointUtf16,
}; };
use log::{debug, error}; use log::{debug, error};
use lsp::{LanguageServer, LanguageServerBinaries, LanguageServerBinary, LanguageServerId}; use lsp::{LanguageServer, LanguageServerBinary, LanguageServerId};
use node_runtime::NodeRuntime; use node_runtime::NodeRuntime;
use request::{LogMessage, StatusNotification}; use request::{LogMessage, StatusNotification};
use settings::SettingsStore; use settings::SettingsStore;
@ -366,13 +366,9 @@ impl Copilot {
path: node_path, path: node_path,
arguments, arguments,
}; };
let binaries = LanguageServerBinaries {
binary: binary.clone(),
installation_test_binary: Some(binary),
};
let server = LanguageServer::new( let server = LanguageServer::new(
LanguageServerId(0), LanguageServerId(0),
binaries, binary,
Path::new("/"), Path::new("/"),
None, None,
cx.clone(), cx.clone(),

View file

@ -20,7 +20,7 @@ use futures::{
use gpui::{executor::Background, AppContext, AsyncAppContext, Task}; use gpui::{executor::Background, AppContext, AsyncAppContext, Task};
use highlight_map::HighlightMap; use highlight_map::HighlightMap;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use lsp::{CodeActionKind, LanguageServerBinaries, LanguageServerBinary}; use lsp::{CodeActionKind, LanguageServerBinary};
use parking_lot::{Mutex, RwLock}; use parking_lot::{Mutex, RwLock};
use postage::watch; use postage::watch;
use regex::Regex; use regex::Regex;
@ -564,10 +564,7 @@ pub struct LanguageRegistry {
login_shell_env_loaded: Shared<Task<()>>, login_shell_env_loaded: Shared<Task<()>>,
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
lsp_binary_paths: Mutex< lsp_binary_paths: Mutex<
HashMap< HashMap<LanguageServerName, Shared<Task<Result<LanguageServerBinary, Arc<anyhow::Error>>>>>,
LanguageServerName,
Shared<Task<Result<LanguageServerBinaries, Arc<anyhow::Error>>>>,
>,
>, >,
executor: Option<Arc<Background>>, executor: Option<Arc<Background>>,
} }
@ -859,7 +856,7 @@ impl LanguageRegistry {
self.state.read().languages.iter().cloned().collect() self.state.read().languages.iter().cloned().collect()
} }
pub fn start_pending_language_server( pub fn create_pending_language_server(
self: &Arc<Self>, self: &Arc<Self>,
language: Arc<Language>, language: Arc<Language>,
adapter: Arc<CachedLspAdapter>, adapter: Arc<CachedLspAdapter>,
@ -932,7 +929,7 @@ impl LanguageRegistry {
.entry(adapter.name.clone()) .entry(adapter.name.clone())
.or_insert_with(|| { .or_insert_with(|| {
cx.spawn(|cx| { cx.spawn(|cx| {
get_binaries( get_binary(
adapter.clone(), adapter.clone(),
language.clone(), language.clone(),
delegate.clone(), delegate.clone(),
@ -953,15 +950,13 @@ impl LanguageRegistry {
task.await?; task.await?;
} }
let server = lsp::LanguageServer::new( lsp::LanguageServer::new(
server_id, server_id,
binaries, binaries,
&root_path, &root_path,
adapter.code_action_kinds(), adapter.code_action_kinds(),
cx, cx,
)?; )
Ok(server)
}) })
}; };
@ -1047,14 +1042,14 @@ impl Default for LanguageRegistry {
} }
} }
async fn get_binaries( async fn get_binary(
adapter: Arc<CachedLspAdapter>, adapter: Arc<CachedLspAdapter>,
language: Arc<Language>, language: Arc<Language>,
delegate: Arc<dyn LspAdapterDelegate>, delegate: Arc<dyn LspAdapterDelegate>,
container_dir: Arc<Path>, container_dir: Arc<Path>,
statuses: async_broadcast::Sender<(Arc<Language>, LanguageServerBinaryStatus)>, statuses: async_broadcast::Sender<(Arc<Language>, LanguageServerBinaryStatus)>,
mut cx: AsyncAppContext, mut cx: AsyncAppContext,
) -> Result<LanguageServerBinaries> { ) -> Result<LanguageServerBinary> {
if !container_dir.exists() { if !container_dir.exists() {
smol::fs::create_dir_all(&container_dir) smol::fs::create_dir_all(&container_dir)
.await .await
@ -1082,13 +1077,7 @@ async fn get_binaries(
statuses statuses
.broadcast((language.clone(), LanguageServerBinaryStatus::Cached)) .broadcast((language.clone(), LanguageServerBinaryStatus::Cached))
.await?; .await?;
let installation_test_binary = adapter return Ok(binary);
.installation_test_binary(container_dir.to_path_buf())
.await;
return Ok(LanguageServerBinaries {
binary,
installation_test_binary,
});
} else { } else {
statuses statuses
.broadcast(( .broadcast((
@ -1110,7 +1099,7 @@ async fn fetch_latest_binary(
delegate: &dyn LspAdapterDelegate, delegate: &dyn LspAdapterDelegate,
container_dir: &Path, container_dir: &Path,
lsp_binary_statuses_tx: async_broadcast::Sender<(Arc<Language>, LanguageServerBinaryStatus)>, lsp_binary_statuses_tx: async_broadcast::Sender<(Arc<Language>, LanguageServerBinaryStatus)>,
) -> Result<LanguageServerBinaries> { ) -> Result<LanguageServerBinary> {
let container_dir: Arc<Path> = container_dir.into(); let container_dir: Arc<Path> = container_dir.into();
lsp_binary_statuses_tx lsp_binary_statuses_tx
.broadcast(( .broadcast((
@ -1127,17 +1116,11 @@ async fn fetch_latest_binary(
let binary = adapter let binary = adapter
.fetch_server_binary(version_info, container_dir.to_path_buf(), delegate) .fetch_server_binary(version_info, container_dir.to_path_buf(), delegate)
.await?; .await?;
let installation_test_binary = adapter
.installation_test_binary(container_dir.to_path_buf())
.await;
lsp_binary_statuses_tx lsp_binary_statuses_tx
.broadcast((language.clone(), LanguageServerBinaryStatus::Downloaded)) .broadcast((language.clone(), LanguageServerBinaryStatus::Downloaded))
.await?; .await?;
Ok(LanguageServerBinaries { Ok(binary)
binary,
installation_test_binary,
})
} }
impl Language { impl Language {

View file

@ -43,12 +43,6 @@ pub struct LanguageServerBinary {
pub arguments: Vec<OsString>, pub arguments: Vec<OsString>,
} }
#[derive(Debug, Clone, Deserialize)]
pub struct LanguageServerBinaries {
pub binary: LanguageServerBinary,
pub installation_test_binary: Option<LanguageServerBinary>,
}
pub struct LanguageServer { pub struct LanguageServer {
server_id: LanguageServerId, server_id: LanguageServerId,
next_id: AtomicUsize, next_id: AtomicUsize,
@ -65,7 +59,6 @@ pub struct LanguageServer {
output_done_rx: Mutex<Option<barrier::Receiver>>, output_done_rx: Mutex<Option<barrier::Receiver>>,
root_path: PathBuf, root_path: PathBuf,
_server: Option<Mutex<Child>>, _server: Option<Mutex<Child>>,
installation_test_binary: Option<LanguageServerBinary>,
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@ -135,7 +128,7 @@ struct Error {
impl LanguageServer { impl LanguageServer {
pub fn new( pub fn new(
server_id: LanguageServerId, server_id: LanguageServerId,
binaries: LanguageServerBinaries, binary: LanguageServerBinary,
root_path: &Path, root_path: &Path,
code_action_kinds: Option<Vec<CodeActionKind>>, code_action_kinds: Option<Vec<CodeActionKind>>,
cx: AsyncAppContext, cx: AsyncAppContext,
@ -146,9 +139,9 @@ impl LanguageServer {
root_path.parent().unwrap_or_else(|| Path::new("/")) root_path.parent().unwrap_or_else(|| Path::new("/"))
}; };
let mut server = process::Command::new(&binaries.binary.path) let mut server = process::Command::new(&binary.path)
.current_dir(working_dir) .current_dir(working_dir)
.args(binaries.binary.arguments) .args(binary.arguments)
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
@ -162,7 +155,6 @@ impl LanguageServer {
stdin, stdin,
stout, stout,
Some(server), Some(server),
binaries.installation_test_binary,
root_path, root_path,
code_action_kinds, code_action_kinds,
cx, cx,
@ -181,7 +173,7 @@ impl LanguageServer {
}, },
); );
if let Some(name) = binaries.binary.path.file_name() { if let Some(name) = binary.path.file_name() {
server.name = name.to_string_lossy().to_string(); server.name = name.to_string_lossy().to_string();
} }
@ -193,7 +185,6 @@ impl LanguageServer {
stdin: Stdin, stdin: Stdin,
stdout: Stdout, stdout: Stdout,
server: Option<Child>, server: Option<Child>,
installation_test_binary: Option<LanguageServerBinary>,
root_path: &Path, root_path: &Path,
code_action_kinds: Option<Vec<CodeActionKind>>, code_action_kinds: Option<Vec<CodeActionKind>>,
cx: AsyncAppContext, cx: AsyncAppContext,
@ -248,14 +239,9 @@ impl LanguageServer {
output_done_rx: Mutex::new(Some(output_done_rx)), output_done_rx: Mutex::new(Some(output_done_rx)),
root_path: root_path.to_path_buf(), root_path: root_path.to_path_buf(),
_server: server.map(|server| Mutex::new(server)), _server: server.map(|server| Mutex::new(server)),
installation_test_binary,
} }
} }
pub fn installation_test_binary(&self) -> &Option<LanguageServerBinary> {
&self.installation_test_binary
}
pub fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> { pub fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
self.code_action_kinds.clone() self.code_action_kinds.clone()
} }
@ -840,7 +826,6 @@ impl LanguageServer {
stdin_writer, stdin_writer,
stdout_reader, stdout_reader,
None, None,
None,
Path::new("/"), Path::new("/"),
None, None,
cx.clone(), cx.clone(),
@ -852,7 +837,6 @@ impl LanguageServer {
stdout_writer, stdout_writer,
stdin_reader, stdin_reader,
None, None,
None,
Path::new("/"), Path::new("/"),
None, None,
cx, cx,

View file

@ -2423,7 +2423,7 @@ impl Project {
return; return;
} }
let pending_server = match self.languages.start_pending_language_server( let pending_server = match self.languages.create_pending_language_server(
language.clone(), language.clone(),
adapter.clone(), adapter.clone(),
worktree_path, worktree_path,