From 085360f052fc4fa3aaed663b88bf029f8ea5317e Mon Sep 17 00:00:00 2001 From: hatoo Date: Wed, 20 Sep 2023 14:28:22 +0900 Subject: [PATCH] save workspace --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1a12732..62faa4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::process::Stdio; use dashmap::DashMap; +use tokio::sync::RwLock; use tower_lsp::jsonrpc::{Error, Result}; use tower_lsp::lsp_types::*; use tower_lsp::{Client, LanguageServer, LspService, Server}; @@ -40,6 +41,7 @@ const TS_HIGHLIGHT_NAMES: &[&str] = &[ #[derive(Debug)] struct Backend { client: Client, + workspace: RwLock>, document_map: DashMap, } @@ -84,7 +86,11 @@ impl Backend { #[tower_lsp::async_trait] impl LanguageServer for Backend { - async fn initialize(&self, _: InitializeParams) -> Result { + async fn initialize(&self, params: InitializeParams) -> Result { + *self.workspace.write().await = params + .workspace_folders + .and_then(|v| v.get(0).map(|w| w.uri.clone())); + Ok(InitializeResult { capabilities: ServerCapabilities { text_document_sync: Some(TextDocumentSyncCapability::Kind( @@ -441,6 +447,7 @@ async fn main() { let (service, socket) = LspService::new(|client| Backend { client, + workspace: RwLock::new(None), document_map: DashMap::new(), }); Server::new(stdin, stdout, socket).serve(service).await;