diff options
-rw-r--r-- | crates/gen_lsp_server/src/lib.rs | 20 | ||||
-rw-r--r-- | 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 b25017045..baca921df 100644 --- a/crates/gen_lsp_server/src/lib.rs +++ b/crates/gen_lsp_server/src/lib.rs | |||
@@ -14,7 +14,7 @@ mod stdio; | |||
14 | 14 | ||
15 | use crossbeam_channel::{Sender, Receiver}; | 15 | use crossbeam_channel::{Sender, Receiver}; |
16 | use languageserver_types::{ | 16 | use languageserver_types::{ |
17 | ServerCapabilities, InitializeResult, | 17 | ServerCapabilities, InitializeResult, InitializeParams, |
18 | request::{Initialize, Shutdown}, | 18 | request::{Initialize, Shutdown}, |
19 | notification::{Initialized, Exit}, | 19 | notification::{Initialized, Exit}, |
20 | }; | 20 | }; |
@@ -27,14 +27,18 @@ pub use { | |||
27 | 27 | ||
28 | pub fn run_server( | 28 | pub fn run_server( |
29 | caps: ServerCapabilities, | 29 | caps: ServerCapabilities, |
30 | server: impl FnOnce(&mut Receiver<RawMessage>, &mut Sender<RawMessage>) -> Result<()>, | 30 | server: impl FnOnce( |
31 | InitializeParams, | ||
32 | &mut Receiver<RawMessage>, | ||
33 | &mut Sender<RawMessage>, | ||
34 | ) -> Result<()>, | ||
31 | mut receiver: Receiver<RawMessage>, | 35 | mut receiver: Receiver<RawMessage>, |
32 | mut sender: Sender<RawMessage>, | 36 | mut sender: Sender<RawMessage>, |
33 | ) -> Result<()> { | 37 | ) -> Result<()> { |
34 | info!("lsp server initializes"); | 38 | info!("lsp server initializes"); |
35 | initialize(&mut receiver, &mut sender, caps)?; | 39 | let params = initialize(&mut receiver, &mut sender, caps)?; |
36 | info!("lsp server initialized, serving requests"); | 40 | info!("lsp server initialized, serving requests"); |
37 | server(&mut receiver, &mut sender)?; | 41 | server(params, &mut receiver, &mut sender)?; |
38 | info!("lsp server waiting for exit notification"); | 42 | info!("lsp server waiting for exit notification"); |
39 | match receiver.recv() { | 43 | match receiver.recv() { |
40 | Some(RawMessage::Notification(n)) => { | 44 | Some(RawMessage::Notification(n)) => { |
@@ -63,11 +67,11 @@ fn initialize( | |||
63 | receiver: &mut Receiver<RawMessage>, | 67 | receiver: &mut Receiver<RawMessage>, |
64 | sender: &mut Sender<RawMessage>, | 68 | sender: &mut Sender<RawMessage>, |
65 | caps: ServerCapabilities, | 69 | caps: ServerCapabilities, |
66 | ) -> Result<()> { | 70 | ) -> Result<InitializeParams> { |
67 | let id = match receiver.recv() { | 71 | let (id, params) = match receiver.recv() { |
68 | Some(RawMessage::Request(req)) => match req.cast::<Initialize>() { | 72 | Some(RawMessage::Request(req)) => match req.cast::<Initialize>() { |
69 | Err(req) => bail!("expected initialize request, got {:?}", req), | 73 | Err(req) => bail!("expected initialize request, got {:?}", req), |
70 | Ok(req) => req.0, | 74 | Ok(req) => req, |
71 | } | 75 | } |
72 | msg => | 76 | msg => |
73 | bail!("expected initialize request, got {:?}", msg), | 77 | bail!("expected initialize request, got {:?}", msg), |
@@ -82,5 +86,5 @@ fn initialize( | |||
82 | } | 86 | } |
83 | _ => bail!("expected initialized notification"), | 87 | _ => bail!("expected initialized notification"), |
84 | } | 88 | } |
85 | Ok(()) | 89 | Ok(params) |
86 | } | 90 | } |
diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index 5c0166a61..baabde629 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs | |||
@@ -31,10 +31,15 @@ fn main() -> Result<()> { | |||
31 | 31 | ||
32 | fn main_inner() -> Result<()> { | 32 | fn main_inner() -> Result<()> { |
33 | let (receiver, sender, threads) = stdio_transport(); | 33 | let (receiver, sender, threads) = stdio_transport(); |
34 | let root = ::std::env::current_dir()?; | 34 | let cwd = ::std::env::current_dir()?; |
35 | run_server( | 35 | run_server( |
36 | m::server_capabilities(), | 36 | m::server_capabilities(), |
37 | |r, s| m::main_loop(false, root, r, s), | 37 | |params, r, s| { |
38 | let root = params.root_uri | ||
39 | .and_then(|it| it.to_file_path().ok()) | ||
40 | .unwrap_or(cwd); | ||
41 | m::main_loop(false, root, r, s) | ||
42 | }, | ||
38 | receiver, | 43 | receiver, |
39 | sender, | 44 | sender, |
40 | )?; | 45 | )?; |