mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Add config setting for self-on-the-fly
This commit is contained in:
parent
4507382f2e
commit
fb7105a580
10 changed files with 27 additions and 2 deletions
|
@ -30,7 +30,7 @@ pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
|
fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
if !ctx.is_trivial_path {
|
if !ctx.is_trivial_path || !ctx.config.enable_self_on_the_fly {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ctx.scope.process_all_names(&mut |name, def| {
|
ctx.scope.process_all_names(&mut |name, def| {
|
||||||
|
|
|
@ -10,6 +10,7 @@ use ide_db::helpers::{insert_use::InsertUseConfig, SnippetCap};
|
||||||
pub struct CompletionConfig {
|
pub struct CompletionConfig {
|
||||||
pub enable_postfix_completions: bool,
|
pub enable_postfix_completions: bool,
|
||||||
pub enable_imports_on_the_fly: bool,
|
pub enable_imports_on_the_fly: bool,
|
||||||
|
pub enable_self_on_the_fly: bool,
|
||||||
pub add_call_parenthesis: bool,
|
pub add_call_parenthesis: bool,
|
||||||
pub add_call_argument_snippets: bool,
|
pub add_call_argument_snippets: bool,
|
||||||
pub snippet_cap: Option<SnippetCap>,
|
pub snippet_cap: Option<SnippetCap>,
|
||||||
|
|
|
@ -139,7 +139,7 @@ impl<'a> Render<'a> {
|
||||||
let mut item = CompletionItem::new(
|
let mut item = CompletionItem::new(
|
||||||
CompletionKind::Reference,
|
CompletionKind::Reference,
|
||||||
self.ctx.source_range(),
|
self.ctx.source_range(),
|
||||||
receiver.map_or_else(|| name.to_string(), |receiver| format!("{}.{}", receiver, name)),
|
receiver.map_or_else(|| name.clone(), |receiver| format!("{}.{}", receiver, name)),
|
||||||
);
|
);
|
||||||
item.kind(SymbolKind::Field)
|
item.kind(SymbolKind::Field)
|
||||||
.detail(ty.display(self.ctx.db()).to_string())
|
.detail(ty.display(self.ctx.db()).to_string())
|
||||||
|
|
|
@ -19,6 +19,7 @@ use crate::{item::CompletionKind, CompletionConfig, CompletionItem};
|
||||||
pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
||||||
enable_postfix_completions: true,
|
enable_postfix_completions: true,
|
||||||
enable_imports_on_the_fly: true,
|
enable_imports_on_the_fly: true,
|
||||||
|
enable_self_on_the_fly: true,
|
||||||
add_call_parenthesis: true,
|
add_call_parenthesis: true,
|
||||||
add_call_argument_snippets: true,
|
add_call_argument_snippets: true,
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
|
|
|
@ -100,6 +100,9 @@ config_data! {
|
||||||
/// Toggles the additional completions that automatically add imports when completed.
|
/// Toggles the additional completions that automatically add imports when completed.
|
||||||
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
|
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
|
||||||
completion_autoimport_enable: bool = "true",
|
completion_autoimport_enable: bool = "true",
|
||||||
|
/// Toggles the additional completions that automatically show method calls and field accesses
|
||||||
|
/// with `self` prefixed to them when inside a method.
|
||||||
|
completion_autoself_enable: bool = "true",
|
||||||
|
|
||||||
/// Whether to show native rust-analyzer diagnostics.
|
/// Whether to show native rust-analyzer diagnostics.
|
||||||
diagnostics_enable: bool = "true",
|
diagnostics_enable: bool = "true",
|
||||||
|
@ -666,6 +669,7 @@ impl Config {
|
||||||
enable_postfix_completions: self.data.completion_postfix_enable,
|
enable_postfix_completions: self.data.completion_postfix_enable,
|
||||||
enable_imports_on_the_fly: self.data.completion_autoimport_enable
|
enable_imports_on_the_fly: self.data.completion_autoimport_enable
|
||||||
&& completion_item_edit_resolve(&self.caps),
|
&& completion_item_edit_resolve(&self.caps),
|
||||||
|
enable_self_on_the_fly: self.data.completion_autoself_enable,
|
||||||
add_call_parenthesis: self.data.completion_addCallParenthesis,
|
add_call_parenthesis: self.data.completion_addCallParenthesis,
|
||||||
add_call_argument_snippets: self.data.completion_addCallArgumentSnippets,
|
add_call_argument_snippets: self.data.completion_addCallArgumentSnippets,
|
||||||
insert_use: self.insert_use_config(),
|
insert_use: self.insert_use_config(),
|
||||||
|
|
|
@ -132,6 +132,7 @@ fn integrated_completion_benchmark() {
|
||||||
let config = CompletionConfig {
|
let config = CompletionConfig {
|
||||||
enable_postfix_completions: true,
|
enable_postfix_completions: true,
|
||||||
enable_imports_on_the_fly: true,
|
enable_imports_on_the_fly: true,
|
||||||
|
enable_self_on_the_fly: true,
|
||||||
add_call_parenthesis: true,
|
add_call_parenthesis: true,
|
||||||
add_call_argument_snippets: true,
|
add_call_argument_snippets: true,
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
|
@ -166,6 +167,7 @@ fn integrated_completion_benchmark() {
|
||||||
let config = CompletionConfig {
|
let config = CompletionConfig {
|
||||||
enable_postfix_completions: true,
|
enable_postfix_completions: true,
|
||||||
enable_imports_on_the_fly: true,
|
enable_imports_on_the_fly: true,
|
||||||
|
enable_self_on_the_fly: true,
|
||||||
add_call_parenthesis: true,
|
add_call_parenthesis: true,
|
||||||
add_call_argument_snippets: true,
|
add_call_argument_snippets: true,
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
|
|
|
@ -1178,6 +1178,7 @@ mod tests {
|
||||||
&ide::CompletionConfig {
|
&ide::CompletionConfig {
|
||||||
enable_postfix_completions: true,
|
enable_postfix_completions: true,
|
||||||
enable_imports_on_the_fly: true,
|
enable_imports_on_the_fly: true,
|
||||||
|
enable_self_on_the_fly: true,
|
||||||
add_call_parenthesis: true,
|
add_call_parenthesis: true,
|
||||||
add_call_argument_snippets: true,
|
add_call_argument_snippets: true,
|
||||||
snippet_cap: SnippetCap::new(true),
|
snippet_cap: SnippetCap::new(true),
|
||||||
|
|
|
@ -447,3 +447,8 @@ This is cheap enough to enable in production.
|
||||||
|
|
||||||
Similarly, we save live object counting (`RA_COUNT=1`).
|
Similarly, we save live object counting (`RA_COUNT=1`).
|
||||||
It is not cheap enough to enable in prod, and this is a bug which should be fixed.
|
It is not cheap enough to enable in prod, and this is a bug which should be fixed.
|
||||||
|
|
||||||
|
### Configurability
|
||||||
|
|
||||||
|
rust-analyzer strives to be as configurable as possible while offering reasonable defaults where no configuration exists yet.
|
||||||
|
There will always be features that some people find more annoying than helpful, so giving the users the ability to tweak or disable these is a big part of offering a good user experience.
|
||||||
|
|
|
@ -136,6 +136,12 @@ Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
|
||||||
Toggles the additional completions that automatically add imports when completed.
|
Toggles the additional completions that automatically add imports when completed.
|
||||||
Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
|
Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
|
||||||
--
|
--
|
||||||
|
[[rust-analyzer.completion.autoself.enable]]rust-analyzer.completion.autoself.enable (default: `true`)::
|
||||||
|
+
|
||||||
|
--
|
||||||
|
Toggles the additional completions that automatically show method calls and field accesses
|
||||||
|
with `self` prefixed to them when inside a method.
|
||||||
|
--
|
||||||
[[rust-analyzer.diagnostics.enable]]rust-analyzer.diagnostics.enable (default: `true`)::
|
[[rust-analyzer.diagnostics.enable]]rust-analyzer.diagnostics.enable (default: `true`)::
|
||||||
+
|
+
|
||||||
--
|
--
|
||||||
|
|
|
@ -572,6 +572,11 @@
|
||||||
"default": true,
|
"default": true,
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"rust-analyzer.completion.autoself.enable": {
|
||||||
|
"markdownDescription": "Toggles the additional completions that automatically show method calls and field accesses\nwith `self` prefixed to them when inside a method.",
|
||||||
|
"default": true,
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"rust-analyzer.diagnostics.enable": {
|
"rust-analyzer.diagnostics.enable": {
|
||||||
"markdownDescription": "Whether to show native rust-analyzer diagnostics.",
|
"markdownDescription": "Whether to show native rust-analyzer diagnostics.",
|
||||||
"default": true,
|
"default": true,
|
||||||
|
|
Loading…
Reference in a new issue