YAGNI active_resolve_capabilities

This leaks a lot of LSP details into ide layer, which we want to avoid:

c9cec381bc/docs/dev (lsp-independence)

Additionally, all what this infra does is providing a toggle for
auto-import completion, but we already have one!
This commit is contained in:
Aleksey Kladov 2021-01-06 20:23:53 +03:00
parent edf03548e3
commit 6e87828756
7 changed files with 32 additions and 78 deletions

View file

@ -46,7 +46,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
acc.add_resolution(ctx, name.to_string(), &res)
});
if ctx.config.enable_autoimport_completions && ctx.config.resolve_additional_edits_lazily() {
if ctx.config.enable_autoimport_completions {
fuzzy_completion(acc, ctx);
}
}
@ -206,11 +206,7 @@ mod tests {
}
fn fuzzy_completion_config() -> CompletionConfig {
let mut completion_config = CompletionConfig::default();
completion_config
.active_resolve_capabilities
.insert(crate::CompletionResolveCapability::AdditionalTextEdits);
completion_config
CompletionConfig::default()
}
#[test]

View file

@ -5,7 +5,6 @@
//! completions if we are allowed to.
use ide_db::helpers::insert_use::MergeBehavior;
use rustc_hash::FxHashSet;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CompletionConfig {
@ -15,32 +14,12 @@ pub struct CompletionConfig {
pub add_call_argument_snippets: bool,
pub snippet_cap: Option<SnippetCap>,
pub merge: Option<MergeBehavior>,
/// A set of capabilities, enabled on the client and supported on the server.
pub active_resolve_capabilities: FxHashSet<CompletionResolveCapability>,
}
/// A resolve capability, supported on the server.
/// If the client registers any completion resolve capabilities,
/// the server is able to render completion items' corresponding fields later,
/// not during an initial completion item request.
/// See https://github.com/rust-analyzer/rust-analyzer/issues/6366 for more details.
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
pub enum CompletionResolveCapability {
Documentation,
Detail,
AdditionalTextEdits,
}
impl CompletionConfig {
pub fn allow_snippets(&mut self, yes: bool) {
self.snippet_cap = if yes { Some(SnippetCap { _private: () }) } else { None }
}
/// Whether the completions' additional edits are calculated when sending an initional completions list
/// or later, in a separate resolve request.
pub fn resolve_additional_edits_lazily(&self) -> bool {
self.active_resolve_capabilities.contains(&CompletionResolveCapability::AdditionalTextEdits)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -57,7 +36,6 @@ impl Default for CompletionConfig {
add_call_argument_snippets: true,
snippet_cap: Some(SnippetCap { _private: () }),
merge: Some(MergeBehavior::Full),
active_resolve_capabilities: FxHashSet::default(),
}
}
}

View file

@ -20,7 +20,7 @@ use text_edit::TextEdit;
use crate::{completions::Completions, context::CompletionContext, item::CompletionKind};
pub use crate::{
config::{CompletionConfig, CompletionResolveCapability},
config::CompletionConfig,
item::{CompletionItem, CompletionItemKind, CompletionScore, ImportEdit, InsertTextFormat},
};