aboutsummaryrefslogtreecommitdiff
path: root/codeless
diff options
context:
space:
mode:
Diffstat (limited to 'codeless')
-rw-r--r--codeless/server/src/main.rs42
-rw-r--r--codeless/server/src/req.rs1
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;
20mod req; 20mod req;
21mod dispatch; 21mod dispatch;
22 22
23use languageserver_types::InitializeResult;
24use threadpool::ThreadPool; 23use threadpool::ThreadPool;
25use crossbeam_channel::{bounded, Sender, Receiver}; 24use crossbeam_channel::{bounded, Sender, Receiver};
26use flexi_logger::Logger; 25use 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 @@
1use languageserver_types::TextDocumentIdentifier; 1use languageserver_types::TextDocumentIdentifier;
2pub use languageserver_types::request::*; 2pub use languageserver_types::request::*;
3pub use languageserver_types::{InitializeResult};
3 4
4pub enum SyntaxTree {} 5pub enum SyntaxTree {}
5 6