Pull completion options up to the rust-analyzer

This commit is contained in:
Aleksey Kladov 2020-03-10 18:47:09 +01:00
parent 2347c03dcd
commit bf582e77d6
5 changed files with 31 additions and 23 deletions

View File

@ -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),

View File

@ -450,17 +450,12 @@ impl Analysis {
}
/// Computes completions at the given position.
pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> {
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<Option<Vec<CompletionItem>>> {
self.with_db(|db| completion::completions(db, position, options).map(Into::into))
}
/// Computes assists (aka code actions aka intentions) for the given

View File

@ -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.
///

View File

@ -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);
}

View File

@ -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,
};