From 31076619b30107a47d2c55bc93c1ff76db6b25ff Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Mon, 25 Aug 2025 18:49:50 +0530 Subject: [PATCH] store document selector --- crates/lsp/src/capabilities.rs | 11 ++++++----- crates/lsp/src/lsp.rs | 5 +++-- crates/project/src/lsp_store.rs | 31 ++++++++----------------------- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/crates/lsp/src/capabilities.rs b/crates/lsp/src/capabilities.rs index ae803e4269..14053f8e4b 100644 --- a/crates/lsp/src/capabilities.rs +++ b/crates/lsp/src/capabilities.rs @@ -1,9 +1,10 @@ -use super::DynamicCapabilities; use lsp_types::{ ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind, TextDocumentSyncSaveOptions, }; +use super::DynamicCapabilities; + pub mod cap { pub struct DidChangeTextDocument; pub struct DidSaveTextDocument; @@ -30,11 +31,11 @@ impl EffectiveCapability for cap::DidChangeTextDocument { return None; } let mut has_incremental = false; - for &kind in id_to_sync_kind_map.values() { - if kind == TextDocumentSyncKind::FULL { + for data in id_to_sync_kind_map.values() { + if data.sync_kind == TextDocumentSyncKind::FULL { return Some(TextDocumentSyncKind::FULL); } - if kind == TextDocumentSyncKind::INCREMENTAL { + if data.sync_kind == TextDocumentSyncKind::INCREMENTAL { has_incremental = true; } } @@ -73,7 +74,7 @@ impl EffectiveCapability for cap::DidSaveTextDocument { Some( id_to_save_options_map .values() - .any(|opts| opts.include_text.unwrap_or(false)), + .any(|data| data.include_text), ) } }) diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs index 13990d4533..b618f7e6c0 100644 --- a/crates/lsp/src/lsp.rs +++ b/crates/lsp/src/lsp.rs @@ -307,8 +307,9 @@ pub struct AdapterServerCapabilities { #[derive(Debug, Default, Clone)] pub struct DynamicCapabilities { - pub text_document_sync_did_change: Option>, - pub text_document_sync_did_save: Option>, + pub text_document_sync_did_change: + Option>, + pub text_document_sync_did_save: Option>, } impl LanguageServer { diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rs index 7a21b3f7db..7cd9cb9a25 100644 --- a/crates/project/src/lsp_store.rs +++ b/crates/project/src/lsp_store.rs @@ -11832,42 +11832,27 @@ impl LspStore { } } "textDocument/didChange" => { - if let Some(sync_kind) = reg - .register_options - .and_then(|opts| opts.get("syncKind").cloned()) - .map(serde_json::from_value::) - .transpose()? - { + if let Some(options) = reg.register_options { + let options: lsp::TextDocumentChangeRegistrationOptions = + serde_json::from_value(options)?; server.update_dynamic_capabilities(|dyn_caps| { let map = dyn_caps .text_document_sync_did_change .get_or_insert_with(HashMap::default); - map.insert(reg.id, sync_kind); + map.insert(reg.id, options); }); notify_server_capabilities_updated(&server, cx); } } "textDocument/didSave" => { - if let Some(include_text) = reg - .register_options - .map(|opts| { - let transpose = opts - .get("includeText") - .cloned() - .map(serde_json::from_value::>) - .transpose(); - match transpose { - Ok(value) => Ok(value.flatten()), - Err(e) => Err(e), - } - }) - .transpose()? - { + if let Some(options) = reg.register_options { + let options: lsp::TextDocumentSaveRegistrationOptions = + serde_json::from_value(options)?; server.update_dynamic_capabilities(|dyn_caps| { let map = dyn_caps .text_document_sync_did_save .get_or_insert_with(HashMap::default); - map.insert(reg.id, lsp::SaveOptions { include_text }); + map.insert(reg.id, options); }); notify_server_capabilities_updated(&server, cx); }