diff options
author | Aleksey Kladov <[email protected]> | 2020-03-10 17:39:17 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-03-10 17:40:22 +0000 |
commit | 2347c03dcd717fbc0648c1e4e3d64a886217de5d (patch) | |
tree | c778877ddc5e17ee7adca15324fe3f5a417f062a /crates/ra_ide/src/completion | |
parent | 6b9d66bbee865bd4337366f1540f8e5aa8d82c18 (diff) |
Introduce CompletionOptions
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r-- | crates/ra_ide/src/completion/complete_postfix.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/completion_context.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/completion_item.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 11 |
4 files changed, 14 insertions, 14 deletions
diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs index 65ecea125..6d000548d 100644 --- a/crates/ra_ide/src/completion/complete_postfix.rs +++ b/crates/ra_ide/src/completion/complete_postfix.rs | |||
@@ -12,7 +12,7 @@ use crate::{ | |||
12 | }; | 12 | }; |
13 | 13 | ||
14 | pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | 14 | pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { |
15 | if !ctx.db.feature_flags.get("completion.enable-postfix") { | 15 | if !ctx.options.enable_postfix_completions { |
16 | return; | 16 | return; |
17 | } | 17 | } |
18 | 18 | ||
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 40535c09e..3646fb8dc 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs | |||
@@ -11,7 +11,7 @@ use ra_syntax::{ | |||
11 | }; | 11 | }; |
12 | use ra_text_edit::AtomTextEdit; | 12 | use ra_text_edit::AtomTextEdit; |
13 | 13 | ||
14 | use crate::FilePosition; | 14 | use crate::{completion::CompletionOptions, FilePosition}; |
15 | 15 | ||
16 | /// `CompletionContext` is created early during completion to figure out, where | 16 | /// `CompletionContext` is created early during completion to figure out, where |
17 | /// exactly is the cursor, syntax-wise. | 17 | /// exactly is the cursor, syntax-wise. |
@@ -19,6 +19,7 @@ use crate::FilePosition; | |||
19 | pub(crate) struct CompletionContext<'a> { | 19 | pub(crate) struct CompletionContext<'a> { |
20 | pub(super) sema: Semantics<'a, RootDatabase>, | 20 | pub(super) sema: Semantics<'a, RootDatabase>, |
21 | pub(super) db: &'a RootDatabase, | 21 | pub(super) db: &'a RootDatabase, |
22 | pub(super) options: &'a CompletionOptions, | ||
22 | pub(super) offset: TextUnit, | 23 | pub(super) offset: TextUnit, |
23 | /// The token before the cursor, in the original file. | 24 | /// The token before the cursor, in the original file. |
24 | pub(super) original_token: SyntaxToken, | 25 | pub(super) original_token: SyntaxToken, |
@@ -57,6 +58,7 @@ impl<'a> CompletionContext<'a> { | |||
57 | pub(super) fn new( | 58 | pub(super) fn new( |
58 | db: &'a RootDatabase, | 59 | db: &'a RootDatabase, |
59 | position: FilePosition, | 60 | position: FilePosition, |
61 | options: &'a CompletionOptions, | ||
60 | ) -> Option<CompletionContext<'a>> { | 62 | ) -> Option<CompletionContext<'a>> { |
61 | let sema = Semantics::new(db); | 63 | let sema = Semantics::new(db); |
62 | 64 | ||
@@ -80,6 +82,7 @@ impl<'a> CompletionContext<'a> { | |||
80 | let mut ctx = CompletionContext { | 82 | let mut ctx = CompletionContext { |
81 | sema, | 83 | sema, |
82 | db, | 84 | db, |
85 | options, | ||
83 | original_token, | 86 | original_token, |
84 | token, | 87 | token, |
85 | offset: position.offset, | 88 | offset: position.offset, |
diff --git a/crates/ra_ide/src/completion/completion_item.rs b/crates/ra_ide/src/completion/completion_item.rs index 19bbb2517..1d14e9636 100644 --- a/crates/ra_ide/src/completion/completion_item.rs +++ b/crates/ra_ide/src/completion/completion_item.rs | |||
@@ -321,14 +321,18 @@ impl Into<Vec<CompletionItem>> for Completions { | |||
321 | 321 | ||
322 | #[cfg(test)] | 322 | #[cfg(test)] |
323 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { | 323 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { |
324 | use crate::completion::completions; | 324 | use crate::{ |
325 | use crate::mock_analysis::{analysis_and_position, single_file_with_position}; | 325 | completion::{completions, CompletionOptions}, |
326 | mock_analysis::{analysis_and_position, single_file_with_position}, | ||
327 | }; | ||
328 | |||
326 | let (analysis, position) = if code.contains("//-") { | 329 | let (analysis, position) = if code.contains("//-") { |
327 | analysis_and_position(code) | 330 | analysis_and_position(code) |
328 | } else { | 331 | } else { |
329 | single_file_with_position(code) | 332 | single_file_with_position(code) |
330 | }; | 333 | }; |
331 | let completions = completions(&analysis.db, position).unwrap(); | 334 | let options = CompletionOptions::default(); |
335 | let completions = completions(&analysis.db, position, &options).unwrap(); | ||
332 | let completion_items: Vec<CompletionItem> = completions.into(); | 336 | let completion_items: Vec<CompletionItem> = completions.into(); |
333 | let mut kind_completions: Vec<CompletionItem> = | 337 | let mut kind_completions: Vec<CompletionItem> = |
334 | completion_items.into_iter().filter(|c| c.completion_kind == kind).collect(); | 338 | completion_items.into_iter().filter(|c| c.completion_kind == kind).collect(); |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index aada4d025..25aff329e 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -212,21 +212,14 @@ impl Completions { | |||
212 | .detail(function_signature.to_string()); | 212 | .detail(function_signature.to_string()); |
213 | 213 | ||
214 | // If not an import, add parenthesis automatically. | 214 | // If not an import, add parenthesis automatically. |
215 | if ctx.use_item_syntax.is_none() | 215 | if ctx.use_item_syntax.is_none() && !ctx.is_call && ctx.options.add_call_parenthesis { |
216 | && !ctx.is_call | ||
217 | && ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis") | ||
218 | { | ||
219 | tested_by!(inserts_parens_for_function_calls); | 216 | tested_by!(inserts_parens_for_function_calls); |
220 | 217 | ||
221 | let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { | 218 | let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { |
222 | (format!("{}()$0", name), format!("{}()", name)) | 219 | (format!("{}()$0", name), format!("{}()", name)) |
223 | } else { | 220 | } else { |
224 | builder = builder.trigger_call_info(); | 221 | builder = builder.trigger_call_info(); |
225 | let snippet = if ctx | 222 | let snippet = if ctx.options.add_call_argument_snippets { |
226 | .db | ||
227 | .feature_flags | ||
228 | .get("completion.insertion.add-argument-snippets") | ||
229 | { | ||
230 | let to_skip = if has_self_param { 1 } else { 0 }; | 223 | let to_skip = if has_self_param { 1 } else { 0 }; |
231 | let function_params_snippet = join( | 224 | let function_params_snippet = join( |
232 | function_signature.parameter_names.iter().skip(to_skip).enumerate().map( | 225 | function_signature.parameter_names.iter().skip(to_skip).enumerate().map( |