Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions crates/ide-completion/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-completion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-completion/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions crates/ide-completion/src/render/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -288,7 +289,7 @@ fn params(
mod tests {
use crate::{
tests::{check_edit, check_edit_with_config, TEST_CONFIG},
CompletionConfig,
CallableSnippets, CompletionConfig,
};

#[test]
Expand Down Expand Up @@ -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) {}
Expand Down
8 changes: 5 additions & 3 deletions crates/ide-completion/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
19 changes: 8 additions & 11 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1383,7 +1380,7 @@ enum ImportGranularityDef {
Module,
}

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Copy, Clone)]
#[serde(rename_all = "snake_case")]
enum CallableCompletionDef {
FillArguments,
Expand Down
8 changes: 3 additions & 5 deletions crates/rust-analyzer/src/integrated_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down