Skip to content

Commit bf582e7

Browse files
committed
Pull completion options up to the rust-analyzer
1 parent 2347c03 commit bf582e7

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

crates/ra_ide/src/completion/presentation.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ impl Completions {
104104
};
105105

106106
// Add `<>` for generic types
107-
if ctx.is_path_type
108-
&& !ctx.has_type_args
109-
&& ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis")
110-
{
107+
if ctx.is_path_type && !ctx.has_type_args && ctx.options.add_call_parenthesis {
111108
let has_non_default_type_params = match resolution {
112109
ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(ctx.db),
113110
ScopeDef::ModuleDef(TypeAlias(it)) => it.has_non_default_type_params(ctx.db),

crates/ra_ide/src/lib.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -450,17 +450,12 @@ impl Analysis {
450450
}
451451

452452
/// Computes completions at the given position.
453-
pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> {
454-
let opts = CompletionOptions {
455-
enable_postfix_completions: self.feature_flags().get("completion.enable-postfix"),
456-
add_call_parenthesis: self
457-
.feature_flags()
458-
.get("completion.insertion.add-call-parenthesis"),
459-
add_call_argument_snippets: self
460-
.feature_flags()
461-
.get("completion.insertion.add-argument-snippets"),
462-
};
463-
self.with_db(|db| completion::completions(db, position, &opts).map(Into::into))
453+
pub fn completions(
454+
&self,
455+
position: FilePosition,
456+
options: &CompletionOptions,
457+
) -> Cancelable<Option<Vec<CompletionItem>>> {
458+
self.with_db(|db| completion::completions(db, position, options).map(Into::into))
464459
}
465460

466461
/// Computes assists (aka code actions aka intentions) for the given

crates/ra_ide_db/src/feature_flags.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
33
use rustc_hash::FxHashMap;
44

5+
// FIXME: looks like a much better design is to pass options to each call,
6+
// rather than to have a global ambient feature flags -- that way, the clients
7+
// can issue two successive calls with different options.
8+
59
/// Feature flags hold fine-grained toggles for all *user-visible* features of
610
/// rust-analyzer.
711
///

crates/rust-analyzer/src/cli/analysis_bench.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use ra_db::{
1212
salsa::{Database, Durability},
1313
FileId, SourceDatabaseExt,
1414
};
15-
use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol};
15+
use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionOptions, FilePosition, LineCol};
1616

1717
use crate::cli::{load_cargo::load_cargo, Verbosity};
1818

@@ -94,17 +94,19 @@ pub fn analysis_bench(verbosity: Verbosity, path: &Path, what: BenchWhat) -> Res
9494
.analysis()
9595
.file_line_index(file_id)?
9696
.offset(LineCol { line: pos.line - 1, col_utf16: pos.column });
97-
let file_postion = FilePosition { file_id, offset };
97+
let file_position = FilePosition { file_id, offset };
9898

9999
if is_completion {
100-
let res =
101-
do_work(&mut host, file_id, |analysis| analysis.completions(file_postion));
100+
let options = CompletionOptions::default();
101+
let res = do_work(&mut host, file_id, |analysis| {
102+
analysis.completions(file_position, &options)
103+
});
102104
if verbosity.is_verbose() {
103105
println!("\n{:#?}", res);
104106
}
105107
} else {
106108
let res =
107-
do_work(&mut host, file_id, |analysis| analysis.goto_definition(file_postion));
109+
do_work(&mut host, file_id, |analysis| analysis.goto_definition(file_position));
108110
if verbosity.is_verbose() {
109111
println!("\n{:#?}", res);
110112
}

crates/rust-analyzer/src/main_loop/handlers.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use lsp_types::{
2020
TextEdit, WorkspaceEdit,
2121
};
2222
use ra_ide::{
23-
Assist, AssistId, FileId, FilePosition, FileRange, Query, RangeInfo, Runnable, RunnableKind,
24-
SearchScope,
23+
Assist, AssistId, CompletionOptions, FileId, FilePosition, FileRange, Query, RangeInfo,
24+
Runnable, RunnableKind, SearchScope,
2525
};
2626
use ra_prof::profile;
2727
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
@@ -424,7 +424,17 @@ pub fn handle_completion(
424424
return Ok(None);
425425
}
426426

427-
let items = match world.analysis().completions(position)? {
427+
let options = CompletionOptions {
428+
enable_postfix_completions: world.feature_flags().get("completion.enable-postfix"),
429+
add_call_parenthesis: world
430+
.feature_flags()
431+
.get("completion.insertion.add-call-parenthesis"),
432+
add_call_argument_snippets: world
433+
.feature_flags()
434+
.get("completion.insertion.add-argument-snippets"),
435+
};
436+
437+
let items = match world.analysis().completions(position, &options)? {
428438
None => return Ok(None),
429439
Some(items) => items,
430440
};

0 commit comments

Comments
 (0)