on master help sign in
lsp: Gracefully fail if binary doesn't exist.
commit5aed1f3c0049d7c00729c8a5e09ba1dc497d037c authorBlaž Hrastnik <blaz@mxxn.io> dateWed 7 Apr 2021, 13:38 (6 years ago) parent9dfd6f6
2 files changed+22−10
helix-lsp/src/client.rs+16−6 helix-lsp/src/lib.rs+6−4
helix-lsp/src/client.rs+16−6
@@ -34,15 +34,25 @@ pub struct Client {
3434}
3535
3636impl Client {
37− pub fn start(ex: &Executor, cmd: &str, args: &[String]) -> (Self, Receiver<Call>) {
38− let mut process = Command::new(cmd)
37+ pub fn start(ex: &Executor, cmd: &str, args: &[String]) -> Result<(Self, Receiver<Call>)> {
38+ // smol makes sure the process is reaped on drop, but using kill_on_drop(true) maybe?
39+ let process = Command::new(cmd)
3940 .args(args)
4041 .stdin(Stdio::piped())
4142 .stdout(Stdio::piped())
4243 .stderr(Stdio::piped())
43− .spawn()
44− .expect("Failed to start language server");
45− // smol makes sure the process is reaped on drop, but using kill_on_drop(true) maybe?
44+ .spawn();
45+
46+ // use std::io::ErrorKind;
47+ let mut process = match process {
48+ Ok(process) => process,
49+ Err(err) => match err.kind() {
50+ // ErrorKind::NotFound | ErrorKind::PermissionDenied => {
51+ // return Err(Error::Other(err.into()))
52+ // }
53+ _kind => return Err(Error::Other(err.into())),
54+ },
55+ };
4656
4757 // TODO: do we need bufreader/writer here? or do we use async wrappers on unblock?
4858 let writer = BufWriter::new(process.stdin.take().expect("Failed to open stdin"));
@@ -65,7 +75,7 @@ impl Client {
6575 // TODO: async client.initialize()
6676 // maybe use an arc<atomic> flag
6777
68− (client, incoming)
78+ Ok((client, incoming))
6979 }
7080
7181 fn next_request_id(&self) -> jsonrpc::Id {
helix-lsp/src/lib.rs+6−4
@@ -104,7 +104,7 @@ use crate::select_all::SelectAll;
104104use smol::channel::Receiver;
105105
106106pub struct Registry {
107− inner: HashMap<LanguageId, Arc<Client>>,
107+ inner: HashMap<LanguageId, Option<Arc<Client>>>,
108108
109109 pub incoming: SelectAll<Receiver<Call>>,
110110}
@@ -140,17 +140,19 @@ impl Registry {
140140 // TODO: lookup defaults for id (name, args)
141141
142142 // initialize a new client
143− let (mut client, incoming) = Client::start(&ex, &config.command, &config.args);
143+ let (mut client, incoming) =
144+ Client::start(&ex, &config.command, &config.args).ok()?;
145+
144146 // TODO: run this async without blocking
145147 smol::block_on(client.initialize()).unwrap();
146148
147149 s_incoming.push(incoming);
148150
149− Arc::new(client)
151+ Some(Arc::new(client))
150152 })
151153 .clone();
152154
153− return Some(language_server);
155+ return language_server;
154156 }
155157
156158 None