()
| 8 | use lsp_server::{Connection, ExtractError, Message, Request, RequestId, Response}; |
| 9 | |
| 10 | pub fn run() -> Result<(), Box<dyn Error + Sync + Send>> { |
| 11 | // Note that we must have our logging only write out to stderr. |
| 12 | eprintln!("starting PRQL LSP server"); |
| 13 | |
| 14 | // Create the transport. Includes the stdio (stdin and stdout) versions but this could |
| 15 | // also be implemented to use sockets or HTTP. |
| 16 | let (connection, io_threads) = Connection::stdio(); |
| 17 | |
| 18 | // Run the server and wait for the two threads to end (typically by trigger LSP Exit event). |
| 19 | let server_capabilities = serde_json::to_value(&ServerCapabilities { |
| 20 | definition_provider: Some(OneOf::Left(true)), |
| 21 | ..Default::default() |
| 22 | }) |
| 23 | .unwrap(); |
| 24 | let initialization_params = match connection.initialize(server_capabilities) { |
| 25 | Ok(it) => it, |
| 26 | Err(e) => { |
| 27 | if e.channel_is_disconnected() { |
| 28 | io_threads.join()?; |
| 29 | } |
| 30 | return Err(e.into()); |
| 31 | } |
| 32 | }; |
| 33 | main_loop(connection, initialization_params)?; |
| 34 | io_threads.join()?; |
| 35 | |
| 36 | // Shut down gracefully. |
| 37 | eprintln!("shutting down server"); |
| 38 | Ok(()) |
| 39 | } |
| 40 | |
| 41 | fn main_loop( |
| 42 | connection: Connection, |
no test coverage detected