|
1 | | -use tower_lsp::{LspService, Server}; |
| 1 | +use lsp_server::Connection; |
| 2 | +use lsp_types::{ |
| 3 | + InitializeParams, OneOf, ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind, |
| 4 | +}; |
2 | 5 | use tracing::{debug, info}; |
3 | 6 |
|
4 | 7 | mod server; |
5 | 8 |
|
6 | | -pub(crate) async fn run_language_server() { |
| 9 | +pub(crate) fn run_language_server() { |
7 | 10 | debug!("Starting Technique Language Server"); |
8 | 11 |
|
9 | | - let stdin = tokio::io::stdin(); |
10 | | - let stdout = tokio::io::stdout(); |
| 12 | + let (connection, threads) = Connection::stdio(); |
11 | 13 |
|
12 | | - let (service, socket) = |
13 | | - LspService::build(|client| server::TechniqueLanguageServer::new(client)).finish(); |
| 14 | + let capabilities = serde_json::to_value(ServerCapabilities { |
| 15 | + text_document_sync: Some(TextDocumentSyncCapability::Kind(TextDocumentSyncKind::FULL)), |
| 16 | + document_formatting_provider: Some(OneOf::Left(true)), |
| 17 | + ..Default::default() |
| 18 | + }) |
| 19 | + .unwrap(); |
14 | 20 |
|
15 | | - info!("Technique Language Server starting on stdio"); |
| 21 | + // extract any initialization parameters passed from the editor. |
| 22 | + if let Ok(params) = connection.initialize(capabilities) { |
| 23 | + let _params = serde_json::from_value::<InitializeParams>(params).unwrap(); |
16 | 24 |
|
17 | | - Server::new(stdin, stdout, socket) |
18 | | - .serve(service) |
19 | | - .await; |
| 25 | + info!("Technique Language Server starting on stdin"); |
| 26 | + |
| 27 | + let server = server::TechniqueLanguageServer::new(); |
| 28 | + |
| 29 | + if let Err(e) = server.run(connection) { |
| 30 | + eprintln!("Server error: {}", e); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + threads |
| 35 | + .join() |
| 36 | + .unwrap(); |
20 | 37 | } |
0 commit comments