Change summary
crates/lsp/src/capabilities.rs | 27 ++++++++++++++-------------
crates/lsp/src/lsp.rs | 1 +
2 files changed, 15 insertions(+), 13 deletions(-)
Detailed changes
@@ -27,20 +27,21 @@ impl EffectiveCapability for cap::DidChangeTextDocument {
.as_ref()
.and_then(|id_to_sync_kind_map| {
if id_to_sync_kind_map.is_empty() {
- None
- } else {
- let mut best: Option<TextDocumentSyncKind> = None;
- for kind in id_to_sync_kind_map.values() {
- best = Some(match (best, kind) {
- (None, kind) => *kind,
- (
- Some(TextDocumentSyncKind::FULL),
- &TextDocumentSyncKind::INCREMENTAL,
- ) => TextDocumentSyncKind::INCREMENTAL,
- (Some(kind), _) => kind,
- });
+ return None;
+ }
+ let mut has_incremental = false;
+ for &kind in id_to_sync_kind_map.values() {
+ if kind == TextDocumentSyncKind::FULL {
+ return Some(TextDocumentSyncKind::FULL);
+ }
+ if kind == TextDocumentSyncKind::INCREMENTAL {
+ has_incremental = true;
}
- best
+ }
+ if has_incremental {
+ Some(TextDocumentSyncKind::INCREMENTAL)
+ } else {
+ None
}
})
.or_else(|| {
@@ -1148,6 +1148,7 @@ impl LanguageServer {
update(self.dynamic_capabilities.write().deref_mut());
}
+ /// Get effective capabilities by combining static and dynamic capabilities.
pub fn effective_capability<Cap: EffectiveCapability>(&self) -> Cap::Value {
let static_capabilities = self.capabilities();
let dynamic_capabilities = self.dynamic_capabilities.read().clone();