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::{
|
use lsp_types::{
|
||||||
ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind,
|
ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind,
|
||||||
TextDocumentSyncSaveOptions,
|
TextDocumentSyncSaveOptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::DynamicCapabilities;
|
||||||
|
|
||||||
pub mod cap {
|
pub mod cap {
|
||||||
pub struct DidChangeTextDocument;
|
pub struct DidChangeTextDocument;
|
||||||
pub struct DidSaveTextDocument;
|
pub struct DidSaveTextDocument;
|
||||||
|
@ -30,11 +31,11 @@ impl EffectiveCapability for cap::DidChangeTextDocument {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let mut has_incremental = false;
|
let mut has_incremental = false;
|
||||||
for &kind in id_to_sync_kind_map.values() {
|
for data in id_to_sync_kind_map.values() {
|
||||||
if kind == TextDocumentSyncKind::FULL {
|
if data.sync_kind == TextDocumentSyncKind::FULL {
|
||||||
return Some(TextDocumentSyncKind::FULL);
|
return Some(TextDocumentSyncKind::FULL);
|
||||||
}
|
}
|
||||||
if kind == TextDocumentSyncKind::INCREMENTAL {
|
if data.sync_kind == TextDocumentSyncKind::INCREMENTAL {
|
||||||
has_incremental = true;
|
has_incremental = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +74,7 @@ impl EffectiveCapability for cap::DidSaveTextDocument {
|
||||||
Some(
|
Some(
|
||||||
id_to_save_options_map
|
id_to_save_options_map
|
||||||
.values()
|
.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)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct DynamicCapabilities {
|
pub struct DynamicCapabilities {
|
||||||
pub text_document_sync_did_change: Option<HashMap<String, TextDocumentSyncKind>>,
|
pub text_document_sync_did_change:
|
||||||
pub text_document_sync_did_save: Option<HashMap<String, SaveOptions>>,
|
Option<HashMap<String, TextDocumentChangeRegistrationOptions>>,
|
||||||
|
pub text_document_sync_did_save: Option<HashMap<String, TextDocumentSaveRegistrationOptions>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LanguageServer {
|
impl LanguageServer {
|
||||||
|
|
|
@ -11832,42 +11832,27 @@ impl LspStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"textDocument/didChange" => {
|
"textDocument/didChange" => {
|
||||||
if let Some(sync_kind) = reg
|
if let Some(options) = reg.register_options {
|
||||||
.register_options
|
let options: lsp::TextDocumentChangeRegistrationOptions =
|
||||||
.and_then(|opts| opts.get("syncKind").cloned())
|
serde_json::from_value(options)?;
|
||||||
.map(serde_json::from_value::<lsp::TextDocumentSyncKind>)
|
|
||||||
.transpose()?
|
|
||||||
{
|
|
||||||
server.update_dynamic_capabilities(|dyn_caps| {
|
server.update_dynamic_capabilities(|dyn_caps| {
|
||||||
let map = dyn_caps
|
let map = dyn_caps
|
||||||
.text_document_sync_did_change
|
.text_document_sync_did_change
|
||||||
.get_or_insert_with(HashMap::default);
|
.get_or_insert_with(HashMap::default);
|
||||||
map.insert(reg.id, sync_kind);
|
map.insert(reg.id, options);
|
||||||
});
|
});
|
||||||
notify_server_capabilities_updated(&server, cx);
|
notify_server_capabilities_updated(&server, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"textDocument/didSave" => {
|
"textDocument/didSave" => {
|
||||||
if let Some(include_text) = reg
|
if let Some(options) = reg.register_options {
|
||||||
.register_options
|
let options: lsp::TextDocumentSaveRegistrationOptions =
|
||||||
.map(|opts| {
|
serde_json::from_value(options)?;
|
||||||
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()?
|
|
||||||
{
|
|
||||||
server.update_dynamic_capabilities(|dyn_caps| {
|
server.update_dynamic_capabilities(|dyn_caps| {
|
||||||
let map = dyn_caps
|
let map = dyn_caps
|
||||||
.text_document_sync_did_save
|
.text_document_sync_did_save
|
||||||
.get_or_insert_with(HashMap::default);
|
.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);
|
notify_server_capabilities_updated(&server, cx);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue