store document selector
This commit is contained in:
parent
ae6b79a398
commit
31076619b3
3 changed files with 17 additions and 30 deletions
|
@ -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),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -307,8 +307,9 @@ pub struct AdapterServerCapabilities {
|
|||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct DynamicCapabilities {
|
||||
pub text_document_sync_did_change: Option<HashMap<String, TextDocumentSyncKind>>,
|
||||
pub text_document_sync_did_save: Option<HashMap<String, SaveOptions>>,
|
||||
pub text_document_sync_did_change:
|
||||
Option<HashMap<String, TextDocumentChangeRegistrationOptions>>,
|
||||
pub text_document_sync_did_save: Option<HashMap<String, TextDocumentSaveRegistrationOptions>>,
|
||||
}
|
||||
|
||||
impl LanguageServer {
|
||||
|
|
|
@ -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::<lsp::TextDocumentSyncKind>)
|
||||
.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::<Option<bool>>)
|
||||
.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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue