2019-06-14 14:03:17 -05:00
|
|
|
use std::error::Error;
|
|
|
|
|
2019-07-04 15:05:17 -05:00
|
|
|
use crossbeam_channel::{Receiver, Sender};
|
|
|
|
use gen_lsp_server::{handle_shutdown, run_server, stdio_transport, RawMessage, RawResponse};
|
2019-05-22 14:45:47 -05:00
|
|
|
use lsp_types::{
|
|
|
|
request::{GotoDefinition, GotoDefinitionResponse},
|
2019-07-04 15:05:17 -05:00
|
|
|
InitializeParams, ServerCapabilities,
|
2019-05-22 14:45:47 -05:00
|
|
|
};
|
|
|
|
|
2019-06-14 14:03:17 -05:00
|
|
|
fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
|
2019-05-22 14:45:47 -05:00
|
|
|
let (receiver, sender, io_threads) = stdio_transport();
|
|
|
|
run_server(ServerCapabilities::default(), receiver, sender, main_loop)?;
|
|
|
|
io_threads.join()?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main_loop(
|
|
|
|
_params: InitializeParams,
|
|
|
|
receiver: &Receiver<RawMessage>,
|
|
|
|
sender: &Sender<RawMessage>,
|
2019-06-14 14:03:17 -05:00
|
|
|
) -> Result<(), Box<dyn Error + Sync + Send>> {
|
2019-05-22 14:45:47 -05:00
|
|
|
for msg in receiver {
|
|
|
|
match msg {
|
|
|
|
RawMessage::Request(req) => {
|
|
|
|
let req = match handle_shutdown(req, sender) {
|
|
|
|
None => return Ok(()),
|
|
|
|
Some(req) => req,
|
|
|
|
};
|
|
|
|
match req.cast::<GotoDefinition>() {
|
|
|
|
Ok((id, _params)) => {
|
|
|
|
let resp = RawResponse::ok::<GotoDefinition>(
|
|
|
|
id,
|
|
|
|
&Some(GotoDefinitionResponse::Array(Vec::new())),
|
|
|
|
);
|
|
|
|
sender.send(RawMessage::Response(resp))?;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Err(req) => req,
|
|
|
|
};
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
RawMessage::Response(_resp) => (),
|
|
|
|
RawMessage::Notification(_not) => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|