mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 22:24:14 +00:00
fix: Fix fill-arguments completions not working
This commit is contained in:
parent
4f6b2a20fd
commit
3577c44dee
8 changed files with 32 additions and 29 deletions
|
@ -14,13 +14,18 @@ pub struct CompletionConfig {
|
||||||
pub enable_imports_on_the_fly: bool,
|
pub enable_imports_on_the_fly: bool,
|
||||||
pub enable_self_on_the_fly: bool,
|
pub enable_self_on_the_fly: bool,
|
||||||
pub enable_private_editable: bool,
|
pub enable_private_editable: bool,
|
||||||
pub add_call_parenthesis: bool,
|
pub callable: Option<CallableSnippets>,
|
||||||
pub add_call_argument_snippets: bool,
|
|
||||||
pub snippet_cap: Option<SnippetCap>,
|
pub snippet_cap: Option<SnippetCap>,
|
||||||
pub insert_use: InsertUseConfig,
|
pub insert_use: InsertUseConfig,
|
||||||
pub snippets: Vec<Snippet>,
|
pub snippets: Vec<Snippet>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
pub enum CallableSnippets {
|
||||||
|
FillArguments,
|
||||||
|
AddParentheses,
|
||||||
|
}
|
||||||
|
|
||||||
impl CompletionConfig {
|
impl CompletionConfig {
|
||||||
pub fn postfix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
|
pub fn postfix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
|
||||||
self.snippets
|
self.snippets
|
||||||
|
|
|
@ -27,7 +27,7 @@ use text_edit::TextEdit;
|
||||||
use crate::{completions::Completions, context::CompletionContext};
|
use crate::{completions::Completions, context::CompletionContext};
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
config::CompletionConfig,
|
config::{CallableSnippets, CompletionConfig},
|
||||||
item::{
|
item::{
|
||||||
CompletionItem, CompletionItemKind, CompletionRelevance, CompletionRelevancePostfixMatch,
|
CompletionItem, CompletionItemKind, CompletionRelevance, CompletionRelevancePostfixMatch,
|
||||||
},
|
},
|
||||||
|
|
|
@ -287,7 +287,7 @@ fn render_resolution_simple_(
|
||||||
let type_path_no_ty_args = matches!(
|
let type_path_no_ty_args = matches!(
|
||||||
ctx.completion.path_context(),
|
ctx.completion.path_context(),
|
||||||
Some(PathCompletionCtx { kind: PathKind::Type, has_type_args: false, .. })
|
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 type_path_no_ty_args {
|
||||||
if let Some(cap) = ctx.snippet_cap() {
|
if let Some(cap) = ctx.snippet_cap() {
|
||||||
let has_non_default_type_params = match resolution {
|
let has_non_default_type_params = match resolution {
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::{
|
||||||
context::{CompletionContext, DotAccess, NameRefContext, PathCompletionCtx, PathKind},
|
context::{CompletionContext, DotAccess, NameRefContext, PathCompletionCtx, PathKind},
|
||||||
item::{Builder, CompletionItem, CompletionItemKind, CompletionRelevance},
|
item::{Builder, CompletionItem, CompletionItemKind, CompletionRelevance},
|
||||||
render::{compute_exact_name_match, compute_ref_match, compute_type_match, RenderContext},
|
render::{compute_exact_name_match, compute_ref_match, compute_type_match, RenderContext},
|
||||||
|
CallableSnippets,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum FuncKind {
|
enum FuncKind {
|
||||||
|
@ -123,7 +124,7 @@ pub(super) fn add_call_parens<'b>(
|
||||||
(format!("{}()$0", name), "()")
|
(format!("{}()$0", name), "()")
|
||||||
} else {
|
} else {
|
||||||
builder.trigger_call_info();
|
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 offset = if self_param.is_some() { 2 } else { 1 };
|
||||||
let function_params_snippet =
|
let function_params_snippet =
|
||||||
params.iter().enumerate().format_with(", ", |(index, param), f| {
|
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 {
|
fn should_add_parens(ctx: &CompletionContext) -> bool {
|
||||||
if !ctx.config.add_call_parenthesis {
|
if ctx.config.callable.is_none() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +289,7 @@ fn params(
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
tests::{check_edit, check_edit_with_config, TEST_CONFIG},
|
tests::{check_edit, check_edit_with_config, TEST_CONFIG},
|
||||||
CompletionConfig,
|
CallableSnippets, CompletionConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -404,7 +405,7 @@ fn main() { S::foo(${1:&self})$0 }
|
||||||
fn suppress_arg_snippets() {
|
fn suppress_arg_snippets() {
|
||||||
cov_mark::check!(suppress_arg_snippets);
|
cov_mark::check!(suppress_arg_snippets);
|
||||||
check_edit_with_config(
|
check_edit_with_config(
|
||||||
CompletionConfig { add_call_argument_snippets: false, ..TEST_CONFIG },
|
CompletionConfig { callable: Some(CallableSnippets::AddParentheses), ..TEST_CONFIG },
|
||||||
"with_args",
|
"with_args",
|
||||||
r#"
|
r#"
|
||||||
fn with_args(x: i32, y: String) {}
|
fn with_args(x: i32, y: String) {}
|
||||||
|
|
|
@ -36,7 +36,10 @@ use stdx::{format_to, trim_indent};
|
||||||
use syntax::{AstNode, NodeOrToken, SyntaxElement};
|
use syntax::{AstNode, NodeOrToken, SyntaxElement};
|
||||||
use test_utils::assert_eq_text;
|
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
|
/// Lots of basic item definitions
|
||||||
const BASE_ITEMS_FIXTURE: &str = r#"
|
const BASE_ITEMS_FIXTURE: &str = r#"
|
||||||
|
@ -63,8 +66,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
||||||
enable_imports_on_the_fly: true,
|
enable_imports_on_the_fly: true,
|
||||||
enable_self_on_the_fly: true,
|
enable_self_on_the_fly: true,
|
||||||
enable_private_editable: true,
|
enable_private_editable: true,
|
||||||
add_call_parenthesis: true,
|
callable: Some(CallableSnippets::FillArguments),
|
||||||
add_call_argument_snippets: true,
|
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
insert_use: InsertUseConfig {
|
insert_use: InsertUseConfig {
|
||||||
granularity: ImportGranularity::Crate,
|
granularity: ImportGranularity::Crate,
|
||||||
|
|
|
@ -102,8 +102,8 @@ pub use ide_assists::{
|
||||||
Assist, AssistConfig, AssistId, AssistKind, AssistResolveStrategy, SingleResolve,
|
Assist, AssistConfig, AssistId, AssistKind, AssistResolveStrategy, SingleResolve,
|
||||||
};
|
};
|
||||||
pub use ide_completion::{
|
pub use ide_completion::{
|
||||||
CompletionConfig, CompletionItem, CompletionItemKind, CompletionRelevance, Snippet,
|
CallableSnippets, CompletionConfig, CompletionItem, CompletionItemKind, CompletionRelevance,
|
||||||
SnippetScope,
|
Snippet, SnippetScope,
|
||||||
};
|
};
|
||||||
pub use ide_db::{
|
pub use ide_db::{
|
||||||
base_db::{
|
base_db::{
|
||||||
|
|
|
@ -11,8 +11,9 @@ use std::{ffi::OsString, fmt, iter, path::PathBuf};
|
||||||
|
|
||||||
use flycheck::FlycheckConfig;
|
use flycheck::FlycheckConfig;
|
||||||
use ide::{
|
use ide::{
|
||||||
AssistConfig, CompletionConfig, DiagnosticsConfig, ExprFillDefaultMode, HighlightRelatedConfig,
|
AssistConfig, CallableSnippets, CompletionConfig, DiagnosticsConfig, ExprFillDefaultMode,
|
||||||
HoverConfig, HoverDocFormat, InlayHintsConfig, JoinLinesConfig, Snippet, SnippetScope,
|
HighlightRelatedConfig, HoverConfig, HoverDocFormat, InlayHintsConfig, JoinLinesConfig,
|
||||||
|
Snippet, SnippetScope,
|
||||||
};
|
};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
imports::insert_use::{ImportGranularity, InsertUseConfig, PrefixKind},
|
imports::insert_use::{ImportGranularity, InsertUseConfig, PrefixKind},
|
||||||
|
@ -1029,14 +1030,10 @@ impl Config {
|
||||||
&& completion_item_edit_resolve(&self.caps),
|
&& completion_item_edit_resolve(&self.caps),
|
||||||
enable_self_on_the_fly: self.data.completion_autoself_enable,
|
enable_self_on_the_fly: self.data.completion_autoself_enable,
|
||||||
enable_private_editable: self.data.completion_privateEditable_enable,
|
enable_private_editable: self.data.completion_privateEditable_enable,
|
||||||
add_call_parenthesis: matches!(
|
callable: self.data.completion_callable_snippets.map(|it| match it {
|
||||||
self.data.completion_callable_snippets,
|
CallableCompletionDef::FillArguments => CallableSnippets::FillArguments,
|
||||||
Some(CallableCompletionDef::AddParentheses)
|
CallableCompletionDef::AddParentheses => CallableSnippets::AddParentheses,
|
||||||
),
|
}),
|
||||||
add_call_argument_snippets: matches!(
|
|
||||||
self.data.completion_callable_snippets,
|
|
||||||
Some(CallableCompletionDef::FillArguments)
|
|
||||||
),
|
|
||||||
insert_use: self.insert_use_config(),
|
insert_use: self.insert_use_config(),
|
||||||
snippet_cap: SnippetCap::new(try_or_def!(
|
snippet_cap: SnippetCap::new(try_or_def!(
|
||||||
self.caps
|
self.caps
|
||||||
|
@ -1383,7 +1380,7 @@ enum ImportGranularityDef {
|
||||||
Module,
|
Module,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Copy, Clone)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
enum CallableCompletionDef {
|
enum CallableCompletionDef {
|
||||||
FillArguments,
|
FillArguments,
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use ide::{Change, CompletionConfig, FilePosition, TextSize};
|
use ide::{CallableSnippets, Change, CompletionConfig, FilePosition, TextSize};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
imports::insert_use::{ImportGranularity, InsertUseConfig},
|
imports::insert_use::{ImportGranularity, InsertUseConfig},
|
||||||
SnippetCap,
|
SnippetCap,
|
||||||
|
@ -135,8 +135,7 @@ fn integrated_completion_benchmark() {
|
||||||
enable_imports_on_the_fly: true,
|
enable_imports_on_the_fly: true,
|
||||||
enable_self_on_the_fly: true,
|
enable_self_on_the_fly: true,
|
||||||
enable_private_editable: true,
|
enable_private_editable: true,
|
||||||
add_call_parenthesis: true,
|
callable: Some(CallableSnippets::FillArguments),
|
||||||
add_call_argument_snippets: true,
|
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
insert_use: InsertUseConfig {
|
insert_use: InsertUseConfig {
|
||||||
granularity: ImportGranularity::Crate,
|
granularity: ImportGranularity::Crate,
|
||||||
|
@ -173,8 +172,7 @@ fn integrated_completion_benchmark() {
|
||||||
enable_imports_on_the_fly: true,
|
enable_imports_on_the_fly: true,
|
||||||
enable_self_on_the_fly: true,
|
enable_self_on_the_fly: true,
|
||||||
enable_private_editable: true,
|
enable_private_editable: true,
|
||||||
add_call_parenthesis: true,
|
callable: Some(CallableSnippets::FillArguments),
|
||||||
add_call_argument_snippets: true,
|
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
insert_use: InsertUseConfig {
|
insert_use: InsertUseConfig {
|
||||||
granularity: ImportGranularity::Crate,
|
granularity: ImportGranularity::Crate,
|
||||||
|
|
Loading…
Reference in a new issue