Setup C adapter with test binary

This commit is contained in:
Julia 2023-06-15 12:03:11 -04:00
parent 4d24eae901
commit f81ccbd652
5 changed files with 40 additions and 24 deletions

View file

@ -368,7 +368,7 @@ impl Copilot {
}; };
let binaries = LanguageServerBinaries { let binaries = LanguageServerBinaries {
binary: binary.clone(), binary: binary.clone(),
installation_test_binary: binary, installation_test_binary: Some(binary),
}; };
let server = LanguageServer::new( let server = LanguageServer::new(
LanguageServerId(0), LanguageServerId(0),

View file

@ -141,8 +141,11 @@ impl CachedLspAdapter {
self.adapter.cached_server_binary(container_dir).await self.adapter.cached_server_binary(container_dir).await
} }
async fn installation_test_binary(&self, container_dir: PathBuf) -> LanguageServerBinary { async fn installation_test_binary(
self.adapter.installation_test_binary(container_dir) &self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
self.adapter.installation_test_binary(container_dir).await
} }
pub fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> { pub fn code_action_kinds(&self) -> Option<Vec<CodeActionKind>> {
@ -202,7 +205,10 @@ pub trait LspAdapter: 'static + Send + Sync {
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<LanguageServerBinary>; async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<LanguageServerBinary>;
fn installation_test_binary(&self, _container_dir: PathBuf) -> LanguageServerBinary { async fn installation_test_binary(
&self,
_container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
unimplemented!(); unimplemented!();
} }

View file

@ -46,7 +46,7 @@ pub struct LanguageServerBinary {
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
pub struct LanguageServerBinaries { pub struct LanguageServerBinaries {
pub binary: LanguageServerBinary, pub binary: LanguageServerBinary,
pub installation_test_binary: LanguageServerBinary, pub installation_test_binary: Option<LanguageServerBinary>,
} }
pub struct LanguageServer { pub struct LanguageServer {
@ -162,7 +162,7 @@ impl LanguageServer {
stdin, stdin,
stout, stout,
Some(server), Some(server),
Some(binaries.installation_test_binary), binaries.installation_test_binary,
root_path, root_path,
code_action_kinds, code_action_kinds,
cx, cx,

View file

@ -3002,27 +3002,29 @@ impl Project {
if !language_server.is_dead() { if !language_server.is_dead() {
return; return;
} }
let server_id = language_server.server_id(); let server_id = language_server.server_id();
let test_binary = match language_server.test_installation_binary() {
Some(test_binary) => test_binary.clone(), // A lack of test binary counts as a failure
None => return, let process = language_server
}; .test_installation_binary()
.as_ref()
.and_then(|binary| {
smol::process::Command::new(&binary.path)
.current_dir(&binary.path)
.args(&binary.arguments)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.kill_on_drop(true)
.spawn()
.ok()
});
const PROCESS_TIMEOUT: Duration = Duration::from_secs(5); const PROCESS_TIMEOUT: Duration = Duration::from_secs(5);
let mut timeout = cx.background().timer(PROCESS_TIMEOUT).fuse(); let mut timeout = cx.background().timer(PROCESS_TIMEOUT).fuse();
let mut errored = false; let mut errored = false;
let result = smol::process::Command::new(&test_binary.path) if let Some(mut process) = process {
.current_dir(&test_binary.path)
.args(test_binary.arguments)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.kill_on_drop(true)
.spawn();
if let Ok(mut process) = result {
futures::select! { futures::select! {
status = process.status().fuse() => match status { status = process.status().fuse() => match status {
Ok(status) => errored = !status.success(), Ok(status) => errored = !status.success(),

View file

@ -110,8 +110,16 @@ impl super::LspAdapter for CLspAdapter {
.log_err() .log_err()
} }
fn installation_test_binary(&self, container_dir: PathBuf) -> LanguageServerBinary { async fn installation_test_binary(
unimplemented!(); &self,
container_dir: PathBuf,
) -> Option<LanguageServerBinary> {
self.cached_server_binary(container_dir)
.await
.map(|mut binary| {
binary.arguments = vec!["--help".into()];
binary
})
} }
async fn label_for_completion( async fn label_for_completion(