From 47e8b80e9b67d5012fbc860a7763975e99fdf28d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 5 Sep 2018 21:38:43 +0300 Subject: [PATCH] use correct workdir for the server --- crates/gen_lsp_server/src/lib.rs | 20 ++++++++++++-------- crates/server/src/main.rs | 9 +++++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs index b250170456..baca921dfc 100644 --- a/crates/gen_lsp_server/src/lib.rs +++ b/crates/gen_lsp_server/src/lib.rs @@ -14,7 +14,7 @@ mod stdio; use crossbeam_channel::{Sender, Receiver}; use languageserver_types::{ - ServerCapabilities, InitializeResult, + ServerCapabilities, InitializeResult, InitializeParams, request::{Initialize, Shutdown}, notification::{Initialized, Exit}, }; @@ -27,14 +27,18 @@ pub use { pub fn run_server( caps: ServerCapabilities, - server: impl FnOnce(&mut Receiver, &mut Sender) -> Result<()>, + server: impl FnOnce( + InitializeParams, + &mut Receiver, + &mut Sender, + ) -> Result<()>, mut receiver: Receiver, mut sender: Sender, ) -> Result<()> { info!("lsp server initializes"); - initialize(&mut receiver, &mut sender, caps)?; + let params = initialize(&mut receiver, &mut sender, caps)?; info!("lsp server initialized, serving requests"); - server(&mut receiver, &mut sender)?; + server(params, &mut receiver, &mut sender)?; info!("lsp server waiting for exit notification"); match receiver.recv() { Some(RawMessage::Notification(n)) => { @@ -63,11 +67,11 @@ fn initialize( receiver: &mut Receiver, sender: &mut Sender, caps: ServerCapabilities, -) -> Result<()> { - let id = match receiver.recv() { +) -> Result { + let (id, params) = match receiver.recv() { Some(RawMessage::Request(req)) => match req.cast::() { Err(req) => bail!("expected initialize request, got {:?}", req), - Ok(req) => req.0, + Ok(req) => req, } msg => bail!("expected initialize request, got {:?}", msg), @@ -82,5 +86,5 @@ fn initialize( } _ => bail!("expected initialized notification"), } - Ok(()) + Ok(params) } diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index 5c0166a614..baabde6298 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs @@ -31,10 +31,15 @@ fn main() -> Result<()> { fn main_inner() -> Result<()> { let (receiver, sender, threads) = stdio_transport(); - let root = ::std::env::current_dir()?; + let cwd = ::std::env::current_dir()?; run_server( m::server_capabilities(), - |r, s| m::main_loop(false, root, r, s), + |params, r, s| { + let root = params.root_uri + .and_then(|it| it.to_file_path().ok()) + .unwrap_or(cwd); + m::main_loop(false, root, r, s) + }, receiver, sender, )?;