Skip to content

Commit 3577c44

Browse files
committed
fix: Fix fill-arguments completions not working
1 parent 4f6b2a2 commit 3577c44

File tree

8 files changed

+32
-29
lines changed

8 files changed

+32
-29
lines changed

crates/ide-completion/src/config.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ pub struct CompletionConfig {
1414
pub enable_imports_on_the_fly: bool,
1515
pub enable_self_on_the_fly: bool,
1616
pub enable_private_editable: bool,
17-
pub add_call_parenthesis: bool,
18-
pub add_call_argument_snippets: bool,
17+
pub callable: Option<CallableSnippets>,
1918
pub snippet_cap: Option<SnippetCap>,
2019
pub insert_use: InsertUseConfig,
2120
pub snippets: Vec<Snippet>,
2221
}
2322

23+
#[derive(Clone, Debug, PartialEq, Eq)]
24+
pub enum CallableSnippets {
25+
FillArguments,
26+
AddParentheses,
27+
}
28+
2429
impl CompletionConfig {
2530
pub fn postfix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
2631
self.snippets

crates/ide-completion/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use text_edit::TextEdit;
2727
use crate::{completions::Completions, context::CompletionContext};
2828

2929
pub use crate::{
30-
config::CompletionConfig,
30+
config::{CallableSnippets, CompletionConfig},
3131
item::{
3232
CompletionItem, CompletionItemKind, CompletionRelevance, CompletionRelevancePostfixMatch,
3333
},

crates/ide-completion/src/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ fn render_resolution_simple_(
287287
let type_path_no_ty_args = matches!(
288288
ctx.completion.path_context(),
289289
Some(PathCompletionCtx { kind: PathKind::Type, has_type_args: false, .. })
290-
) && ctx.completion.config.add_call_parenthesis;
290+
) && ctx.completion.config.callable.is_some();
291291
if type_path_no_ty_args {
292292
if let Some(cap) = ctx.snippet_cap() {
293293
let has_non_default_type_params = match resolution {

crates/ide-completion/src/render/function.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
context::{CompletionContext, DotAccess, NameRefContext, PathCompletionCtx, PathKind},
1111
item::{Builder, CompletionItem, CompletionItemKind, CompletionRelevance},
1212
render::{compute_exact_name_match, compute_ref_match, compute_type_match, RenderContext},
13+
CallableSnippets,
1314
};
1415

1516
enum FuncKind {
@@ -123,7 +124,7 @@ pub(super) fn add_call_parens<'b>(
123124
(format!("{}()$0", name), "()")
124125
} else {
125126
builder.trigger_call_info();
126-
let snippet = if ctx.config.add_call_argument_snippets {
127+
let snippet = if let Some(CallableSnippets::FillArguments) = ctx.config.callable {
127128
let offset = if self_param.is_some() { 2 } else { 1 };
128129
let function_params_snippet =
129130
params.iter().enumerate().format_with(", ", |(index, param), f| {
@@ -191,7 +192,7 @@ fn ref_of_param(ctx: &CompletionContext, arg: &str, ty: &hir::Type) -> &'static
191192
}
192193

193194
fn should_add_parens(ctx: &CompletionContext) -> bool {
194-
if !ctx.config.add_call_parenthesis {
195+
if ctx.config.callable.is_none() {
195196
return false;
196197
}
197198

@@ -288,7 +289,7 @@ fn params(
288289
mod tests {
289290
use crate::{
290291
tests::{check_edit, check_edit_with_config, TEST_CONFIG},
291-
CompletionConfig,
292+
CallableSnippets, CompletionConfig,
292293
};
293294

294295
#[test]
@@ -404,7 +405,7 @@ fn main() { S::foo(${1:&self})$0 }
404405
fn suppress_arg_snippets() {
405406
cov_mark::check!(suppress_arg_snippets);
406407
check_edit_with_config(
407-
CompletionConfig { add_call_argument_snippets: false, ..TEST_CONFIG },
408+
CompletionConfig { callable: Some(CallableSnippets::AddParentheses), ..TEST_CONFIG },
408409
"with_args",
409410
r#"
410411
fn with_args(x: i32, y: String) {}

crates/ide-completion/src/tests.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ use stdx::{format_to, trim_indent};
3636
use syntax::{AstNode, NodeOrToken, SyntaxElement};
3737
use test_utils::assert_eq_text;
3838

39-
use crate::{resolve_completion_edits, CompletionConfig, CompletionItem, CompletionItemKind};
39+
use crate::{
40+
resolve_completion_edits, CallableSnippets, CompletionConfig, CompletionItem,
41+
CompletionItemKind,
42+
};
4043

4144
/// Lots of basic item definitions
4245
const BASE_ITEMS_FIXTURE: &str = r#"
@@ -63,8 +66,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
6366
enable_imports_on_the_fly: true,
6467
enable_self_on_the_fly: true,
6568
enable_private_editable: true,
66-
add_call_parenthesis: true,
67-
add_call_argument_snippets: true,
69+
callable: Some(CallableSnippets::FillArguments),
6870
snippet_cap: SnippetCap::new(true),
6971
insert_use: InsertUseConfig {
7072
granularity: ImportGranularity::Crate,

crates/ide/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ pub use ide_assists::{
102102
Assist, AssistConfig, AssistId, AssistKind, AssistResolveStrategy, SingleResolve,
103103
};
104104
pub use ide_completion::{
105-
CompletionConfig, CompletionItem, CompletionItemKind, CompletionRelevance, Snippet,
106-
SnippetScope,
105+
CallableSnippets, CompletionConfig, CompletionItem, CompletionItemKind, CompletionRelevance,
106+
Snippet, SnippetScope,
107107
};
108108
pub use ide_db::{
109109
base_db::{

crates/rust-analyzer/src/config.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use std::{ffi::OsString, fmt, iter, path::PathBuf};
1111

1212
use flycheck::FlycheckConfig;
1313
use ide::{
14-
AssistConfig, CompletionConfig, DiagnosticsConfig, ExprFillDefaultMode, HighlightRelatedConfig,
15-
HoverConfig, HoverDocFormat, InlayHintsConfig, JoinLinesConfig, Snippet, SnippetScope,
14+
AssistConfig, CallableSnippets, CompletionConfig, DiagnosticsConfig, ExprFillDefaultMode,
15+
HighlightRelatedConfig, HoverConfig, HoverDocFormat, InlayHintsConfig, JoinLinesConfig,
16+
Snippet, SnippetScope,
1617
};
1718
use ide_db::{
1819
imports::insert_use::{ImportGranularity, InsertUseConfig, PrefixKind},
@@ -1029,14 +1030,10 @@ impl Config {
10291030
&& completion_item_edit_resolve(&self.caps),
10301031
enable_self_on_the_fly: self.data.completion_autoself_enable,
10311032
enable_private_editable: self.data.completion_privateEditable_enable,
1032-
add_call_parenthesis: matches!(
1033-
self.data.completion_callable_snippets,
1034-
Some(CallableCompletionDef::AddParentheses)
1035-
),
1036-
add_call_argument_snippets: matches!(
1037-
self.data.completion_callable_snippets,
1038-
Some(CallableCompletionDef::FillArguments)
1039-
),
1033+
callable: self.data.completion_callable_snippets.map(|it| match it {
1034+
CallableCompletionDef::FillArguments => CallableSnippets::FillArguments,
1035+
CallableCompletionDef::AddParentheses => CallableSnippets::AddParentheses,
1036+
}),
10401037
insert_use: self.insert_use_config(),
10411038
snippet_cap: SnippetCap::new(try_or_def!(
10421039
self.caps
@@ -1383,7 +1380,7 @@ enum ImportGranularityDef {
13831380
Module,
13841381
}
13851382

1386-
#[derive(Deserialize, Debug, Clone)]
1383+
#[derive(Deserialize, Debug, Copy, Clone)]
13871384
#[serde(rename_all = "snake_case")]
13881385
enum CallableCompletionDef {
13891386
FillArguments,

crates/rust-analyzer/src/integrated_benchmarks.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use std::sync::Arc;
1414

15-
use ide::{Change, CompletionConfig, FilePosition, TextSize};
15+
use ide::{CallableSnippets, Change, CompletionConfig, FilePosition, TextSize};
1616
use ide_db::{
1717
imports::insert_use::{ImportGranularity, InsertUseConfig},
1818
SnippetCap,
@@ -135,8 +135,7 @@ fn integrated_completion_benchmark() {
135135
enable_imports_on_the_fly: true,
136136
enable_self_on_the_fly: true,
137137
enable_private_editable: true,
138-
add_call_parenthesis: true,
139-
add_call_argument_snippets: true,
138+
callable: Some(CallableSnippets::FillArguments),
140139
snippet_cap: SnippetCap::new(true),
141140
insert_use: InsertUseConfig {
142141
granularity: ImportGranularity::Crate,
@@ -173,8 +172,7 @@ fn integrated_completion_benchmark() {
173172
enable_imports_on_the_fly: true,
174173
enable_self_on_the_fly: true,
175174
enable_private_editable: true,
176-
add_call_parenthesis: true,
177-
add_call_argument_snippets: true,
175+
callable: Some(CallableSnippets::FillArguments),
178176
snippet_cap: SnippetCap::new(true),
179177
insert_use: InsertUseConfig {
180178
granularity: ImportGranularity::Crate,

0 commit comments

Comments
 (0)