diff options
author | Aleksey Kladov <[email protected]> | 2018-08-10 16:01:59 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-10 16:02:26 +0100 |
commit | 1be7af26a83b79863efb0d66a77b1fb7c0235bd2 (patch) | |
tree | 1742c2adb8c850cede85a72f06acc5c11ec0d09b /codeless/server/src | |
parent | 2e165ae82eed1dc62f1f4c68e45440c143c7c8ef (diff) |
cleaner shutdown
Diffstat (limited to 'codeless/server/src')
-rw-r--r-- | codeless/server/src/main.rs | 42 | ||||
-rw-r--r-- | codeless/server/src/req.rs | 1 |
2 files changed, 27 insertions, 16 deletions
diff --git a/codeless/server/src/main.rs b/codeless/server/src/main.rs index 92f6a400c..fdb2fe2d5 100644 --- a/codeless/server/src/main.rs +++ b/codeless/server/src/main.rs | |||
@@ -20,7 +20,6 @@ mod caps; | |||
20 | mod req; | 20 | mod req; |
21 | mod dispatch; | 21 | mod dispatch; |
22 | 22 | ||
23 | use languageserver_types::InitializeResult; | ||
24 | use threadpool::ThreadPool; | 23 | use threadpool::ThreadPool; |
25 | use crossbeam_channel::{bounded, Sender, Receiver}; | 24 | use crossbeam_channel::{bounded, Sender, Receiver}; |
26 | use flexi_logger::Logger; | 25 | use flexi_logger::Logger; |
@@ -46,7 +45,7 @@ fn main() -> Result<()> { | |||
46 | Err(_) => { | 45 | Err(_) => { |
47 | error!("server panicked"); | 46 | error!("server panicked"); |
48 | bail!("server panicked") | 47 | bail!("server panicked") |
49 | }, | 48 | } |
50 | } | 49 | } |
51 | } | 50 | } |
52 | 51 | ||
@@ -72,7 +71,7 @@ fn initialize(io: &mut Io) -> Result<()> { | |||
72 | match io.recv()? { | 71 | match io.recv()? { |
73 | RawMsg::Request(req) => { | 72 | RawMsg::Request(req) => { |
74 | if let Some((_params, resp)) = dispatch::expect::<req::Initialize>(io, req)? { | 73 | if let Some((_params, resp)) = dispatch::expect::<req::Initialize>(io, req)? { |
75 | resp.result(io, InitializeResult { | 74 | resp.result(io, req::InitializeResult { |
76 | capabilities: caps::SERVER_CAPABILITIES | 75 | capabilities: caps::SERVER_CAPABILITIES |
77 | })?; | 76 | })?; |
78 | match io.recv()? { | 77 | match io.recv()? { |
@@ -107,6 +106,7 @@ fn initialized(io: &mut Io) -> Result<()> { | |||
107 | let res = main_loop(io, &mut world, &mut pool, sender, receiver.clone()); | 106 | let res = main_loop(io, &mut world, &mut pool, sender, receiver.clone()); |
108 | info!("waiting for background jobs to finish..."); | 107 | info!("waiting for background jobs to finish..."); |
109 | receiver.for_each(drop); | 108 | receiver.for_each(drop); |
109 | pool.join(); | ||
110 | info!("...background jobs have finished"); | 110 | info!("...background jobs have finished"); |
111 | res | 111 | res |
112 | } | 112 | } |
@@ -148,19 +148,29 @@ fn main_loop( | |||
148 | 148 | ||
149 | match msg { | 149 | match msg { |
150 | RawMsg::Request(req) => { | 150 | RawMsg::Request(req) => { |
151 | if let Some((params, resp)) = dispatch::expect::<req::SyntaxTree>(io, req)? { | 151 | let req = match dispatch::parse_as::<req::SyntaxTree>(req)? { |
152 | let world = world.snapshot(); | 152 | Ok((params, resp)) => { |
153 | let sender = sender.clone(); | 153 | let world = world.snapshot(); |
154 | pool.execute(move || { | 154 | let sender = sender.clone(); |
155 | let res: Result<String> = (|| { | 155 | pool.execute(move || { |
156 | let path = params.text_document.uri.to_file_path() | 156 | let res: Result<String> = (|| { |
157 | .map_err(|()| format_err!("invalid path"))?; | 157 | let path = params.text_document.uri.to_file_path() |
158 | let file = world.file_syntax(&path)?; | 158 | .map_err(|()| format_err!("invalid path"))?; |
159 | Ok(libeditor::syntax_tree(&file)) | 159 | let file = world.file_syntax(&path)?; |
160 | })(); | 160 | Ok(libeditor::syntax_tree(&file)) |
161 | 161 | })(); | |
162 | sender.send(Box::new(|io: &mut Io| resp.response(io, res))) | 162 | |
163 | }); | 163 | sender.send(Box::new(|io: &mut Io| resp.response(io, res))) |
164 | }); | ||
165 | continue; | ||
166 | } | ||
167 | Err(req) => req, | ||
168 | }; | ||
169 | |||
170 | if let Some(((), resp)) = dispatch::expect::<req::Shutdown>(io, req)? { | ||
171 | info!("shutdown request"); | ||
172 | resp.result(io, ())?; | ||
173 | return Ok(()); | ||
164 | } | 174 | } |
165 | } | 175 | } |
166 | msg => { | 176 | msg => { |
diff --git a/codeless/server/src/req.rs b/codeless/server/src/req.rs index bc54c1d33..35a20a229 100644 --- a/codeless/server/src/req.rs +++ b/codeless/server/src/req.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | use languageserver_types::TextDocumentIdentifier; | 1 | use languageserver_types::TextDocumentIdentifier; |
2 | pub use languageserver_types::request::*; | 2 | pub use languageserver_types::request::*; |
3 | pub use languageserver_types::{InitializeResult}; | ||
3 | 4 | ||
4 | pub enum SyntaxTree {} | 5 | pub enum SyntaxTree {} |
5 | 6 | ||