mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
Pull completion options up to the rust-analyzer
This commit is contained in:
parent
2347c03dcd
commit
bf582e77d6
5 changed files with 31 additions and 23 deletions
|
@ -104,10 +104,7 @@ impl Completions {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add `<>` for generic types
|
// Add `<>` for generic types
|
||||||
if ctx.is_path_type
|
if ctx.is_path_type && !ctx.has_type_args && ctx.options.add_call_parenthesis {
|
||||||
&& !ctx.has_type_args
|
|
||||||
&& ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis")
|
|
||||||
{
|
|
||||||
let has_non_default_type_params = match resolution {
|
let has_non_default_type_params = match resolution {
|
||||||
ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(ctx.db),
|
ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(ctx.db),
|
||||||
ScopeDef::ModuleDef(TypeAlias(it)) => it.has_non_default_type_params(ctx.db),
|
ScopeDef::ModuleDef(TypeAlias(it)) => it.has_non_default_type_params(ctx.db),
|
||||||
|
|
|
@ -450,17 +450,12 @@ impl Analysis {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes completions at the given position.
|
/// Computes completions at the given position.
|
||||||
pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> {
|
pub fn completions(
|
||||||
let opts = CompletionOptions {
|
&self,
|
||||||
enable_postfix_completions: self.feature_flags().get("completion.enable-postfix"),
|
position: FilePosition,
|
||||||
add_call_parenthesis: self
|
options: &CompletionOptions,
|
||||||
.feature_flags()
|
) -> Cancelable<Option<Vec<CompletionItem>>> {
|
||||||
.get("completion.insertion.add-call-parenthesis"),
|
self.with_db(|db| completion::completions(db, position, options).map(Into::into))
|
||||||
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))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes assists (aka code actions aka intentions) for the given
|
/// Computes assists (aka code actions aka intentions) for the given
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
use rustc_hash::FxHashMap;
|
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
|
/// Feature flags hold fine-grained toggles for all *user-visible* features of
|
||||||
/// rust-analyzer.
|
/// rust-analyzer.
|
||||||
///
|
///
|
||||||
|
|
|
@ -12,7 +12,7 @@ use ra_db::{
|
||||||
salsa::{Database, Durability},
|
salsa::{Database, Durability},
|
||||||
FileId, SourceDatabaseExt,
|
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};
|
use crate::cli::{load_cargo::load_cargo, Verbosity};
|
||||||
|
|
||||||
|
@ -94,17 +94,19 @@ pub fn analysis_bench(verbosity: Verbosity, path: &Path, what: BenchWhat) -> Res
|
||||||
.analysis()
|
.analysis()
|
||||||
.file_line_index(file_id)?
|
.file_line_index(file_id)?
|
||||||
.offset(LineCol { line: pos.line - 1, col_utf16: pos.column });
|
.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 {
|
if is_completion {
|
||||||
let res =
|
let options = CompletionOptions::default();
|
||||||
do_work(&mut host, file_id, |analysis| analysis.completions(file_postion));
|
let res = do_work(&mut host, file_id, |analysis| {
|
||||||
|
analysis.completions(file_position, &options)
|
||||||
|
});
|
||||||
if verbosity.is_verbose() {
|
if verbosity.is_verbose() {
|
||||||
println!("\n{:#?}", res);
|
println!("\n{:#?}", res);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let res =
|
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() {
|
if verbosity.is_verbose() {
|
||||||
println!("\n{:#?}", res);
|
println!("\n{:#?}", res);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ use lsp_types::{
|
||||||
TextEdit, WorkspaceEdit,
|
TextEdit, WorkspaceEdit,
|
||||||
};
|
};
|
||||||
use ra_ide::{
|
use ra_ide::{
|
||||||
Assist, AssistId, FileId, FilePosition, FileRange, Query, RangeInfo, Runnable, RunnableKind,
|
Assist, AssistId, CompletionOptions, FileId, FilePosition, FileRange, Query, RangeInfo,
|
||||||
SearchScope,
|
Runnable, RunnableKind, SearchScope,
|
||||||
};
|
};
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
|
use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit};
|
||||||
|
@ -424,7 +424,17 @@ pub fn handle_completion(
|
||||||
return Ok(None);
|
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),
|
None => return Ok(None),
|
||||||
Some(items) => items,
|
Some(items) => items,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue