about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-05-13 19:52:44 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-05-13 19:52:44 +0200
commit3577c44dee95f0b2b5367dd034f5188317be08eb (patch)
tree0f1211aaa90526b7d486fab7046246a3d1830020
parent4f6b2a20fd0417c6c1c64163d9ce7a5c915afde1 (diff)
downloadrust-3577c44dee95f0b2b5367dd034f5188317be08eb.tar.gz
rust-3577c44dee95f0b2b5367dd034f5188317be08eb.zip
fix: Fix fill-arguments completions not working
-rw-r--r--crates/ide-completion/src/config.rs9
-rw-r--r--crates/ide-completion/src/lib.rs2
-rw-r--r--crates/ide-completion/src/render.rs2
-rw-r--r--crates/ide-completion/src/render/function.rs9
-rw-r--r--crates/ide-completion/src/tests.rs8
-rw-r--r--crates/ide/src/lib.rs4
-rw-r--r--crates/rust-analyzer/src/config.rs19
-rw-r--r--crates/rust-analyzer/src/integrated_benchmarks.rs8
8 files changed, 32 insertions, 29 deletions
diff --git a/crates/ide-completion/src/config.rs b/crates/ide-completion/src/config.rs
index 302836dd1e1..80d6af28168 100644
--- a/crates/ide-completion/src/config.rs
+++ b/crates/ide-completion/src/config.rs
@@ -14,13 +14,18 @@ pub struct CompletionConfig {
     pub enable_imports_on_the_fly: bool,
     pub enable_self_on_the_fly: bool,
     pub enable_private_editable: bool,
-    pub add_call_parenthesis: bool,
-    pub add_call_argument_snippets: bool,
+    pub callable: Option<CallableSnippets>,
     pub snippet_cap: Option<SnippetCap>,
     pub insert_use: InsertUseConfig,
     pub snippets: Vec<Snippet>,
 }
 
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub enum CallableSnippets {
+    FillArguments,
+    AddParentheses,
+}
+
 impl CompletionConfig {
     pub fn postfix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
         self.snippets
diff --git a/crates/ide-completion/src/lib.rs b/crates/ide-completion/src/lib.rs
index 7789c967070..991ab6a4b86 100644
--- a/crates/ide-completion/src/lib.rs
+++ b/crates/ide-completion/src/lib.rs
@@ -27,7 +27,7 @@ use text_edit::TextEdit;
 use crate::{completions::Completions, context::CompletionContext};
 
 pub use crate::{
-    config::CompletionConfig,
+    config::{CallableSnippets, CompletionConfig},
     item::{
         CompletionItem, CompletionItemKind, CompletionRelevance, CompletionRelevancePostfixMatch,
     },
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index 88b6435c95b..f5092183857 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -287,7 +287,7 @@ fn render_resolution_simple_(
     let type_path_no_ty_args = matches!(
         ctx.completion.path_context(),
         Some(PathCompletionCtx { kind: PathKind::Type, has_type_args: false, .. })
-    ) && ctx.completion.config.add_call_parenthesis;
+    ) && ctx.completion.config.callable.is_some();
     if type_path_no_ty_args {
         if let Some(cap) = ctx.snippet_cap() {
             let has_non_default_type_params = match resolution {
diff --git a/crates/ide-completion/src/render/function.rs b/crates/ide-completion/src/render/function.rs
index 1ede314e87b..c47696bc41d 100644
--- a/crates/ide-completion/src/render/function.rs
+++ b/crates/ide-completion/src/render/function.rs
@@ -10,6 +10,7 @@ use crate::{
     context::{CompletionContext, DotAccess, NameRefContext, PathCompletionCtx, PathKind},
     item::{Builder, CompletionItem, CompletionItemKind, CompletionRelevance},
     render::{compute_exact_name_match, compute_ref_match, compute_type_match, RenderContext},
+    CallableSnippets,
 };
 
 enum FuncKind {
@@ -123,7 +124,7 @@ pub(super) fn add_call_parens<'b>(
         (format!("{}()$0", name), "()")
     } else {
         builder.trigger_call_info();
-        let snippet = if ctx.config.add_call_argument_snippets {
+        let snippet = if let Some(CallableSnippets::FillArguments) = ctx.config.callable {
             let offset = if self_param.is_some() { 2 } else { 1 };
             let function_params_snippet =
                 params.iter().enumerate().format_with(", ", |(index, param), f| {
@@ -191,7 +192,7 @@ fn ref_of_param(ctx: &CompletionContext, arg: &str, ty: &hir::Type) -> &'static
 }
 
 fn should_add_parens(ctx: &CompletionContext) -> bool {
-    if !ctx.config.add_call_parenthesis {
+    if ctx.config.callable.is_none() {
         return false;
     }
 
@@ -288,7 +289,7 @@ fn params(
 mod tests {
     use crate::{
         tests::{check_edit, check_edit_with_config, TEST_CONFIG},
-        CompletionConfig,
+        CallableSnippets, CompletionConfig,
     };
 
     #[test]
@@ -404,7 +405,7 @@ fn main() { S::foo(${1:&self})$0 }
     fn suppress_arg_snippets() {
         cov_mark::check!(suppress_arg_snippets);
         check_edit_with_config(
-            CompletionConfig { add_call_argument_snippets: false, ..TEST_CONFIG },
+            CompletionConfig { callable: Some(CallableSnippets::AddParentheses), ..TEST_CONFIG },
             "with_args",
             r#"
 fn with_args(x: i32, y: String) {}
diff --git a/crates/ide-completion/src/tests.rs b/crates/ide-completion/src/tests.rs
index 0430aeea59b..742368ce81c 100644
--- a/crates/ide-completion/src/tests.rs
+++ b/crates/ide-completion/src/tests.rs
@@ -36,7 +36,10 @@ use stdx::{format_to, trim_indent};
 use syntax::{AstNode, NodeOrToken, SyntaxElement};
 use test_utils::assert_eq_text;
 
-use crate::{resolve_completion_edits, CompletionConfig, CompletionItem, CompletionItemKind};
+use crate::{
+    resolve_completion_edits, CallableSnippets, CompletionConfig, CompletionItem,
+    CompletionItemKind,
+};
 
 /// Lots of basic item definitions
 const BASE_ITEMS_FIXTURE: &str = r#"
@@ -63,8 +66,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
     enable_imports_on_the_fly: true,
     enable_self_on_the_fly: true,
     enable_private_editable: true,
-    add_call_parenthesis: true,
-    add_call_argument_snippets: true,
+    callable: Some(CallableSnippets::FillArguments),
     snippet_cap: SnippetCap::new(true),
     insert_use: InsertUseConfig {
         granularity: ImportGranularity::Crate,
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index da50a4b8ee5..e5160f99f34 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -102,8 +102,8 @@ pub use ide_assists::{
     Assist, AssistConfig, AssistId, AssistKind, AssistResolveStrategy, SingleResolve,
 };
 pub use ide_completion::{
-    CompletionConfig, CompletionItem, CompletionItemKind, CompletionRelevance, Snippet,
-    SnippetScope,
+    CallableSnippets, CompletionConfig, CompletionItem, CompletionItemKind, CompletionRelevance,
+    Snippet, SnippetScope,
 };
 pub use ide_db::{
     base_db::{
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index abc1541b536..c7158648d86 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -11,8 +11,9 @@ use std::{ffi::OsString, fmt, iter, path::PathBuf};
 
 use flycheck::FlycheckConfig;
 use ide::{
-    AssistConfig, CompletionConfig, DiagnosticsConfig, ExprFillDefaultMode, HighlightRelatedConfig,
-    HoverConfig, HoverDocFormat, InlayHintsConfig, JoinLinesConfig, Snippet, SnippetScope,
+    AssistConfig, CallableSnippets, CompletionConfig, DiagnosticsConfig, ExprFillDefaultMode,
+    HighlightRelatedConfig, HoverConfig, HoverDocFormat, InlayHintsConfig, JoinLinesConfig,
+    Snippet, SnippetScope,
 };
 use ide_db::{
     imports::insert_use::{ImportGranularity, InsertUseConfig, PrefixKind},
@@ -1029,14 +1030,10 @@ impl Config {
                 && completion_item_edit_resolve(&self.caps),
             enable_self_on_the_fly: self.data.completion_autoself_enable,
             enable_private_editable: self.data.completion_privateEditable_enable,
-            add_call_parenthesis: matches!(
-                self.data.completion_callable_snippets,
-                Some(CallableCompletionDef::AddParentheses)
-            ),
-            add_call_argument_snippets: matches!(
-                self.data.completion_callable_snippets,
-                Some(CallableCompletionDef::FillArguments)
-            ),
+            callable: self.data.completion_callable_snippets.map(|it| match it {
+                CallableCompletionDef::FillArguments => CallableSnippets::FillArguments,
+                CallableCompletionDef::AddParentheses => CallableSnippets::AddParentheses,
+            }),
             insert_use: self.insert_use_config(),
             snippet_cap: SnippetCap::new(try_or_def!(
                 self.caps
@@ -1383,7 +1380,7 @@ enum ImportGranularityDef {
     Module,
 }
 
-#[derive(Deserialize, Debug, Clone)]
+#[derive(Deserialize, Debug, Copy, Clone)]
 #[serde(rename_all = "snake_case")]
 enum CallableCompletionDef {
     FillArguments,
diff --git a/crates/rust-analyzer/src/integrated_benchmarks.rs b/crates/rust-analyzer/src/integrated_benchmarks.rs
index 4e6acaa877a..5f110274b2e 100644
--- a/crates/rust-analyzer/src/integrated_benchmarks.rs
+++ b/crates/rust-analyzer/src/integrated_benchmarks.rs
@@ -12,7 +12,7 @@
 
 use std::sync::Arc;
 
-use ide::{Change, CompletionConfig, FilePosition, TextSize};
+use ide::{CallableSnippets, Change, CompletionConfig, FilePosition, TextSize};
 use ide_db::{
     imports::insert_use::{ImportGranularity, InsertUseConfig},
     SnippetCap,
@@ -135,8 +135,7 @@ fn integrated_completion_benchmark() {
             enable_imports_on_the_fly: true,
             enable_self_on_the_fly: true,
             enable_private_editable: true,
-            add_call_parenthesis: true,
-            add_call_argument_snippets: true,
+            callable: Some(CallableSnippets::FillArguments),
             snippet_cap: SnippetCap::new(true),
             insert_use: InsertUseConfig {
                 granularity: ImportGranularity::Crate,
@@ -173,8 +172,7 @@ fn integrated_completion_benchmark() {
             enable_imports_on_the_fly: true,
             enable_self_on_the_fly: true,
             enable_private_editable: true,
-            add_call_parenthesis: true,
-            add_call_argument_snippets: true,
+            callable: Some(CallableSnippets::FillArguments),
             snippet_cap: SnippetCap::new(true),
             insert_use: InsertUseConfig {
                 granularity: ImportGranularity::Crate,