diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 25aff329edf..3dc56e4a3d8 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -104,10 +104,7 @@ impl Completions { }; // Add `<>` for generic types - if ctx.is_path_type - && !ctx.has_type_args - && ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis") - { + if ctx.is_path_type && !ctx.has_type_args && ctx.options.add_call_parenthesis { let has_non_default_type_params = match resolution { ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(ctx.db), ScopeDef::ModuleDef(TypeAlias(it)) => it.has_non_default_type_params(ctx.db), diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 0d91ea74978..d888bb7454c 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -450,17 +450,12 @@ impl Analysis { } /// Computes completions at the given position. - pub fn completions(&self, position: FilePosition) -> Cancelable>> { - let opts = CompletionOptions { - enable_postfix_completions: self.feature_flags().get("completion.enable-postfix"), - add_call_parenthesis: self - .feature_flags() - .get("completion.insertion.add-call-parenthesis"), - add_call_argument_snippets: self - .feature_flags() - .get("completion.insertion.add-argument-snippets"), - }; - self.with_db(|db| completion::completions(db, position, &opts).map(Into::into)) + pub fn completions( + &self, + position: FilePosition, + options: &CompletionOptions, + ) -> Cancelable>> { + self.with_db(|db| completion::completions(db, position, options).map(Into::into)) } /// Computes assists (aka code actions aka intentions) for the given diff --git a/crates/ra_ide_db/src/feature_flags.rs b/crates/ra_ide_db/src/feature_flags.rs index 9684150727d..dbb3f50a095 100644 --- a/crates/ra_ide_db/src/feature_flags.rs +++ b/crates/ra_ide_db/src/feature_flags.rs @@ -2,6 +2,10 @@ use rustc_hash::FxHashMap; +// FIXME: looks like a much better design is to pass options to each call, +// rather than to have a global ambient feature flags -- that way, the clients +// can issue two successive calls with different options. + /// Feature flags hold fine-grained toggles for all *user-visible* features of /// rust-analyzer. /// diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs index 91855e59252..28a23934f15 100644 --- a/crates/rust-analyzer/src/cli/analysis_bench.rs +++ b/crates/rust-analyzer/src/cli/analysis_bench.rs @@ -12,7 +12,7 @@ use ra_db::{ salsa::{Database, Durability}, FileId, SourceDatabaseExt, }; -use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; +use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionOptions, FilePosition, LineCol}; use crate::cli::{load_cargo::load_cargo, Verbosity}; @@ -94,17 +94,19 @@ pub fn analysis_bench(verbosity: Verbosity, path: &Path, what: BenchWhat) -> Res .analysis() .file_line_index(file_id)? .offset(LineCol { line: pos.line - 1, col_utf16: pos.column }); - let file_postion = FilePosition { file_id, offset }; + let file_position = FilePosition { file_id, offset }; if is_completion { - let res = - do_work(&mut host, file_id, |analysis| analysis.completions(file_postion)); + let options = CompletionOptions::default(); + let res = do_work(&mut host, file_id, |analysis| { + analysis.completions(file_position, &options) + }); if verbosity.is_verbose() { println!("\n{:#?}", res); } } else { let res = - do_work(&mut host, file_id, |analysis| analysis.goto_definition(file_postion)); + do_work(&mut host, file_id, |analysis| analysis.goto_definition(file_position)); if verbosity.is_verbose() { println!("\n{:#?}", res); } diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index 8dc6e8dc05d..155f677a6dc 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs @@ -20,8 +20,8 @@ use lsp_types::{ TextEdit, WorkspaceEdit, }; use ra_ide::{ - Assist, AssistId, FileId, FilePosition, FileRange, Query, RangeInfo, Runnable, RunnableKind, - SearchScope, + Assist, AssistId, CompletionOptions, FileId, FilePosition, FileRange, Query, RangeInfo, + Runnable, RunnableKind, SearchScope, }; use ra_prof::profile; use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; @@ -424,7 +424,17 @@ pub fn handle_completion( return Ok(None); } - let items = match world.analysis().completions(position)? { + let options = CompletionOptions { + enable_postfix_completions: world.feature_flags().get("completion.enable-postfix"), + add_call_parenthesis: world + .feature_flags() + .get("completion.insertion.add-call-parenthesis"), + add_call_argument_snippets: world + .feature_flags() + .get("completion.insertion.add-argument-snippets"), + }; + + let items = match world.analysis().completions(position, &options)? { None => return Ok(None), Some(items) => items, };