aboutsummaryrefslogtreecommitdiff
path: root/crates/gen_lsp_server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/gen_lsp_server')
-rw-r--r--crates/gen_lsp_server/src/lib.rs20
1 files changed, 12 insertions, 8 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
15use crossbeam_channel::{Sender, Receiver}; 15use crossbeam_channel::{Sender, Receiver};
16use languageserver_types::{ 16use 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
28pub fn run_server( 28pub 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}