Add config setting for self-on-the-fly

This commit is contained in:
Lukas Wirth 2021-05-30 16:41:33 +02:00
parent 4507382f2e
commit fb7105a580
10 changed files with 27 additions and 2 deletions

View file

@ -30,7 +30,7 @@ pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
}
fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
if !ctx.is_trivial_path {
if !ctx.is_trivial_path || !ctx.config.enable_self_on_the_fly {
return;
}
ctx.scope.process_all_names(&mut |name, def| {

View file

@ -10,6 +10,7 @@ use ide_db::helpers::{insert_use::InsertUseConfig, SnippetCap};
pub struct CompletionConfig {
pub enable_postfix_completions: bool,
pub enable_imports_on_the_fly: bool,
pub enable_self_on_the_fly: bool,
pub add_call_parenthesis: bool,
pub add_call_argument_snippets: bool,
pub snippet_cap: Option<SnippetCap>,

View file

@ -139,7 +139,7 @@ impl<'a> Render<'a> {
let mut item = CompletionItem::new(
CompletionKind::Reference,
self.ctx.source_range(),
receiver.map_or_else(|| name.to_string(), |receiver| format!("{}.{}", receiver, name)),
receiver.map_or_else(|| name.clone(), |receiver| format!("{}.{}", receiver, name)),
);
item.kind(SymbolKind::Field)
.detail(ty.display(self.ctx.db()).to_string())

View file

@ -19,6 +19,7 @@ use crate::{item::CompletionKind, CompletionConfig, CompletionItem};
pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
enable_postfix_completions: true,
enable_imports_on_the_fly: true,
enable_self_on_the_fly: true,
add_call_parenthesis: true,
add_call_argument_snippets: true,
snippet_cap: SnippetCap::new(true),