diff options
Diffstat (limited to 'crates')
29 files changed, 440 insertions, 130 deletions
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index b7e8855fb..7f5e1469e 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -516,9 +516,31 @@ pub(crate) fn inherent_impl_substs( | |||
516 | let self_ty_with_vars = | 516 | let self_ty_with_vars = |
517 | Canonical { num_vars: vars.len() + self_ty.num_vars, value: self_ty_with_vars }; | 517 | Canonical { num_vars: vars.len() + self_ty.num_vars, value: self_ty_with_vars }; |
518 | let substs = super::infer::unify(&self_ty_with_vars, self_ty); | 518 | let substs = super::infer::unify(&self_ty_with_vars, self_ty); |
519 | // we only want the substs for the vars we added, not the ones from self_ty | 519 | // We only want the substs for the vars we added, not the ones from self_ty. |
520 | let result = substs.map(|s| s.suffix(vars.len())); | 520 | // Also, if any of the vars we added are still in there, we replace them by |
521 | result | 521 | // Unknown. I think this can only really happen if self_ty contained |
522 | // Unknown, and in that case we want the result to contain Unknown in those | ||
523 | // places again. | ||
524 | substs.map(|s| fallback_bound_vars(s.suffix(vars.len()), self_ty.num_vars)) | ||
525 | } | ||
526 | |||
527 | /// This replaces any 'free' Bound vars in `s` (i.e. those with indices past | ||
528 | /// num_vars_to_keep) by `Ty::Unknown`. | ||
529 | fn fallback_bound_vars(s: Substs, num_vars_to_keep: usize) -> Substs { | ||
530 | s.fold_binders( | ||
531 | &mut |ty, binders| { | ||
532 | if let Ty::Bound(idx) = &ty { | ||
533 | if *idx >= binders as u32 { | ||
534 | Ty::Unknown | ||
535 | } else { | ||
536 | ty | ||
537 | } | ||
538 | } else { | ||
539 | ty | ||
540 | } | ||
541 | }, | ||
542 | num_vars_to_keep, | ||
543 | ) | ||
522 | } | 544 | } |
523 | 545 | ||
524 | fn transform_receiver_ty( | 546 | fn transform_receiver_ty( |
diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs index c378c2c62..93e53c921 100644 --- a/crates/ra_ide/src/completion.rs +++ b/crates/ra_ide/src/completion.rs | |||
@@ -16,11 +16,11 @@ mod complete_scope; | |||
16 | mod complete_postfix; | 16 | mod complete_postfix; |
17 | mod complete_macro_in_item_position; | 17 | mod complete_macro_in_item_position; |
18 | mod complete_trait_impl; | 18 | mod complete_trait_impl; |
19 | #[cfg(test)] | ||
20 | mod test_utils; | ||
19 | 21 | ||
20 | use ra_ide_db::RootDatabase; | 22 | use ra_ide_db::RootDatabase; |
21 | 23 | ||
22 | #[cfg(test)] | ||
23 | use crate::completion::completion_item::do_completion; | ||
24 | use crate::{ | 24 | use crate::{ |
25 | completion::{ | 25 | completion::{ |
26 | completion_context::CompletionContext, | 26 | completion_context::CompletionContext, |
@@ -33,6 +33,23 @@ pub use crate::completion::completion_item::{ | |||
33 | CompletionItem, CompletionItemKind, InsertTextFormat, | 33 | CompletionItem, CompletionItemKind, InsertTextFormat, |
34 | }; | 34 | }; |
35 | 35 | ||
36 | #[derive(Clone, Debug, PartialEq, Eq)] | ||
37 | pub struct CompletionOptions { | ||
38 | pub enable_postfix_completions: bool, | ||
39 | pub add_call_parenthesis: bool, | ||
40 | pub add_call_argument_snippets: bool, | ||
41 | } | ||
42 | |||
43 | impl Default for CompletionOptions { | ||
44 | fn default() -> Self { | ||
45 | CompletionOptions { | ||
46 | enable_postfix_completions: true, | ||
47 | add_call_parenthesis: true, | ||
48 | add_call_argument_snippets: true, | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
36 | /// Main entry point for completion. We run completion as a two-phase process. | 53 | /// Main entry point for completion. We run completion as a two-phase process. |
37 | /// | 54 | /// |
38 | /// First, we look at the position and collect a so-called `CompletionContext. | 55 | /// First, we look at the position and collect a so-called `CompletionContext. |
@@ -55,8 +72,12 @@ pub use crate::completion::completion_item::{ | |||
55 | /// `foo` *should* be present among the completion variants. Filtering by | 72 | /// `foo` *should* be present among the completion variants. Filtering by |
56 | /// identifier prefix/fuzzy match should be done higher in the stack, together | 73 | /// identifier prefix/fuzzy match should be done higher in the stack, together |
57 | /// with ordering of completions (currently this is done by the client). | 74 | /// with ordering of completions (currently this is done by the client). |
58 | pub(crate) fn completions(db: &RootDatabase, position: FilePosition) -> Option<Completions> { | 75 | pub(crate) fn completions( |
59 | let ctx = CompletionContext::new(db, position)?; | 76 | db: &RootDatabase, |
77 | position: FilePosition, | ||
78 | opts: &CompletionOptions, | ||
79 | ) -> Option<Completions> { | ||
80 | let ctx = CompletionContext::new(db, position, opts)?; | ||
60 | 81 | ||
61 | let mut acc = Completions::default(); | 82 | let mut acc = Completions::default(); |
62 | 83 | ||
diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs index f275305e2..81e5037aa 100644 --- a/crates/ra_ide/src/completion/complete_dot.rs +++ b/crates/ra_ide/src/completion/complete_dot.rs | |||
@@ -70,7 +70,7 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: &T | |||
70 | 70 | ||
71 | #[cfg(test)] | 71 | #[cfg(test)] |
72 | mod tests { | 72 | mod tests { |
73 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 73 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
74 | use insta::assert_debug_snapshot; | 74 | use insta::assert_debug_snapshot; |
75 | 75 | ||
76 | fn do_ref_completion(code: &str) -> Vec<CompletionItem> { | 76 | fn do_ref_completion(code: &str) -> Vec<CompletionItem> { |
@@ -718,4 +718,35 @@ mod tests { | |||
718 | "### | 718 | "### |
719 | ); | 719 | ); |
720 | } | 720 | } |
721 | |||
722 | #[test] | ||
723 | fn test_method_completion_3547() { | ||
724 | assert_debug_snapshot!( | ||
725 | do_ref_completion( | ||
726 | r" | ||
727 | struct HashSet<T> {} | ||
728 | impl<T> HashSet<T> { | ||
729 | pub fn the_method(&self) {} | ||
730 | } | ||
731 | fn foo() { | ||
732 | let s: HashSet<_>; | ||
733 | s.<|> | ||
734 | } | ||
735 | ", | ||
736 | ), | ||
737 | @r###" | ||
738 | [ | ||
739 | CompletionItem { | ||
740 | label: "the_method()", | ||
741 | source_range: [201; 201), | ||
742 | delete: [201; 201), | ||
743 | insert: "the_method()$0", | ||
744 | kind: Method, | ||
745 | lookup: "the_method", | ||
746 | detail: "pub fn the_method(&self)", | ||
747 | }, | ||
748 | ] | ||
749 | "### | ||
750 | ); | ||
751 | } | ||
721 | } | 752 | } |
diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index 502458706..9226ac055 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs | |||
@@ -52,7 +52,7 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) | |||
52 | 52 | ||
53 | #[cfg(test)] | 53 | #[cfg(test)] |
54 | mod tests { | 54 | mod tests { |
55 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 55 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
56 | use insta::assert_debug_snapshot; | 56 | use insta::assert_debug_snapshot; |
57 | 57 | ||
58 | fn do_magic_completion(code: &str) -> Vec<CompletionItem> { | 58 | fn do_magic_completion(code: &str) -> Vec<CompletionItem> { |
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs index e1c0ffb1f..1e053ea4a 100644 --- a/crates/ra_ide/src/completion/complete_keyword.rs +++ b/crates/ra_ide/src/completion/complete_keyword.rs | |||
@@ -117,7 +117,7 @@ fn complete_return( | |||
117 | 117 | ||
118 | #[cfg(test)] | 118 | #[cfg(test)] |
119 | mod tests { | 119 | mod tests { |
120 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 120 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
121 | use insta::assert_debug_snapshot; | 121 | use insta::assert_debug_snapshot; |
122 | 122 | ||
123 | fn do_keyword_completion(code: &str) -> Vec<CompletionItem> { | 123 | fn do_keyword_completion(code: &str) -> Vec<CompletionItem> { |
diff --git a/crates/ra_ide/src/completion/complete_macro_in_item_position.rs b/crates/ra_ide/src/completion/complete_macro_in_item_position.rs index 1866d9e6c..270e96df0 100644 --- a/crates/ra_ide/src/completion/complete_macro_in_item_position.rs +++ b/crates/ra_ide/src/completion/complete_macro_in_item_position.rs | |||
@@ -15,9 +15,10 @@ pub(super) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &Compl | |||
15 | 15 | ||
16 | #[cfg(test)] | 16 | #[cfg(test)] |
17 | mod tests { | 17 | mod tests { |
18 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | ||
19 | use insta::assert_debug_snapshot; | 18 | use insta::assert_debug_snapshot; |
20 | 19 | ||
20 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | ||
21 | |||
21 | fn do_reference_completion(code: &str) -> Vec<CompletionItem> { | 22 | fn do_reference_completion(code: &str) -> Vec<CompletionItem> { |
22 | do_completion(code, CompletionKind::Reference) | 23 | do_completion(code, CompletionKind::Reference) |
23 | } | 24 | } |
diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs index 3c4a70561..d588ee364 100644 --- a/crates/ra_ide/src/completion/complete_path.rs +++ b/crates/ra_ide/src/completion/complete_path.rs | |||
@@ -103,7 +103,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
103 | mod tests { | 103 | mod tests { |
104 | use test_utils::covers; | 104 | use test_utils::covers; |
105 | 105 | ||
106 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 106 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
107 | use insta::assert_debug_snapshot; | 107 | use insta::assert_debug_snapshot; |
108 | 108 | ||
109 | fn do_reference_completion(code: &str) -> Vec<CompletionItem> { | 109 | fn do_reference_completion(code: &str) -> Vec<CompletionItem> { |
diff --git a/crates/ra_ide/src/completion/complete_pattern.rs b/crates/ra_ide/src/completion/complete_pattern.rs index fa8aeceda..6a1a66ef1 100644 --- a/crates/ra_ide/src/completion/complete_pattern.rs +++ b/crates/ra_ide/src/completion/complete_pattern.rs | |||
@@ -27,7 +27,7 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { | |||
27 | 27 | ||
28 | #[cfg(test)] | 28 | #[cfg(test)] |
29 | mod tests { | 29 | mod tests { |
30 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 30 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
31 | use insta::assert_debug_snapshot; | 31 | use insta::assert_debug_snapshot; |
32 | 32 | ||
33 | fn complete(code: &str) -> Vec<CompletionItem> { | 33 | fn complete(code: &str) -> Vec<CompletionItem> { |
diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs index 65ecea125..0ba382165 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 | ||
@@ -81,7 +81,7 @@ fn postfix_snippet(ctx: &CompletionContext, label: &str, detail: &str, snippet: | |||
81 | mod tests { | 81 | mod tests { |
82 | use insta::assert_debug_snapshot; | 82 | use insta::assert_debug_snapshot; |
83 | 83 | ||
84 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 84 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
85 | 85 | ||
86 | fn do_postfix_completion(code: &str) -> Vec<CompletionItem> { | 86 | fn do_postfix_completion(code: &str) -> Vec<CompletionItem> { |
87 | do_completion(code, CompletionKind::Postfix) | 87 | do_completion(code, CompletionKind::Postfix) |
diff --git a/crates/ra_ide/src/completion/complete_record_literal.rs b/crates/ra_ide/src/completion/complete_record_literal.rs index be6e4194f..83ed1d52c 100644 --- a/crates/ra_ide/src/completion/complete_record_literal.rs +++ b/crates/ra_ide/src/completion/complete_record_literal.rs | |||
@@ -18,7 +18,7 @@ pub(super) fn complete_record_literal(acc: &mut Completions, ctx: &CompletionCon | |||
18 | 18 | ||
19 | #[cfg(test)] | 19 | #[cfg(test)] |
20 | mod tests { | 20 | mod tests { |
21 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 21 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
22 | use insta::assert_debug_snapshot; | 22 | use insta::assert_debug_snapshot; |
23 | 23 | ||
24 | fn complete(code: &str) -> Vec<CompletionItem> { | 24 | fn complete(code: &str) -> Vec<CompletionItem> { |
diff --git a/crates/ra_ide/src/completion/complete_record_pattern.rs b/crates/ra_ide/src/completion/complete_record_pattern.rs index 687c57d3e..962376428 100644 --- a/crates/ra_ide/src/completion/complete_record_pattern.rs +++ b/crates/ra_ide/src/completion/complete_record_pattern.rs | |||
@@ -17,7 +17,7 @@ pub(super) fn complete_record_pattern(acc: &mut Completions, ctx: &CompletionCon | |||
17 | 17 | ||
18 | #[cfg(test)] | 18 | #[cfg(test)] |
19 | mod tests { | 19 | mod tests { |
20 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 20 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
21 | use insta::assert_debug_snapshot; | 21 | use insta::assert_debug_snapshot; |
22 | 22 | ||
23 | fn complete(code: &str) -> Vec<CompletionItem> { | 23 | fn complete(code: &str) -> Vec<CompletionItem> { |
diff --git a/crates/ra_ide/src/completion/complete_scope.rs b/crates/ra_ide/src/completion/complete_scope.rs index eb3c8cf1b..bd4adf23a 100644 --- a/crates/ra_ide/src/completion/complete_scope.rs +++ b/crates/ra_ide/src/completion/complete_scope.rs | |||
@@ -14,10 +14,10 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { | |||
14 | mod tests { | 14 | mod tests { |
15 | use insta::assert_debug_snapshot; | 15 | use insta::assert_debug_snapshot; |
16 | 16 | ||
17 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 17 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
18 | 18 | ||
19 | fn do_reference_completion(code: &str) -> Vec<CompletionItem> { | 19 | fn do_reference_completion(ra_fixture: &str) -> Vec<CompletionItem> { |
20 | do_completion(code, CompletionKind::Reference) | 20 | do_completion(ra_fixture, CompletionKind::Reference) |
21 | } | 21 | } |
22 | 22 | ||
23 | #[test] | 23 | #[test] |
diff --git a/crates/ra_ide/src/completion/complete_snippet.rs b/crates/ra_ide/src/completion/complete_snippet.rs index 731b4fd82..f731e9b9a 100644 --- a/crates/ra_ide/src/completion/complete_snippet.rs +++ b/crates/ra_ide/src/completion/complete_snippet.rs | |||
@@ -42,7 +42,7 @@ fn ${1:feature}() { | |||
42 | 42 | ||
43 | #[cfg(test)] | 43 | #[cfg(test)] |
44 | mod tests { | 44 | mod tests { |
45 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 45 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
46 | use insta::assert_debug_snapshot; | 46 | use insta::assert_debug_snapshot; |
47 | 47 | ||
48 | fn do_snippet_completion(code: &str) -> Vec<CompletionItem> { | 48 | fn do_snippet_completion(code: &str) -> Vec<CompletionItem> { |
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 2bf654a57..7fefa2c7a 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs | |||
@@ -217,7 +217,7 @@ fn make_const_compl_syntax(const_: &ast::ConstDef) -> String { | |||
217 | 217 | ||
218 | #[cfg(test)] | 218 | #[cfg(test)] |
219 | mod tests { | 219 | mod tests { |
220 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 220 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
221 | use insta::assert_debug_snapshot; | 221 | use insta::assert_debug_snapshot; |
222 | 222 | ||
223 | fn complete(code: &str) -> Vec<CompletionItem> { | 223 | fn complete(code: &str) -> Vec<CompletionItem> { |
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..ef0eb43b2 100644 --- a/crates/ra_ide/src/completion/completion_item.rs +++ b/crates/ra_ide/src/completion/completion_item.rs | |||
@@ -13,7 +13,7 @@ pub struct CompletionItem { | |||
13 | /// Used only internally in tests, to check only specific kind of | 13 | /// Used only internally in tests, to check only specific kind of |
14 | /// completion (postfix, keyword, reference, etc). | 14 | /// completion (postfix, keyword, reference, etc). |
15 | #[allow(unused)] | 15 | #[allow(unused)] |
16 | completion_kind: CompletionKind, | 16 | pub(crate) completion_kind: CompletionKind, |
17 | /// Label in the completion pop up which identifies completion. | 17 | /// Label in the completion pop up which identifies completion. |
18 | label: String, | 18 | label: String, |
19 | /// Range of identifier that is being completed. | 19 | /// Range of identifier that is being completed. |
@@ -318,20 +318,3 @@ impl Into<Vec<CompletionItem>> for Completions { | |||
318 | self.buf | 318 | self.buf |
319 | } | 319 | } |
320 | } | 320 | } |
321 | |||
322 | #[cfg(test)] | ||
323 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { | ||
324 | use crate::completion::completions; | ||
325 | use crate::mock_analysis::{analysis_and_position, single_file_with_position}; | ||
326 | let (analysis, position) = if code.contains("//-") { | ||
327 | analysis_and_position(code) | ||
328 | } else { | ||
329 | single_file_with_position(code) | ||
330 | }; | ||
331 | let completions = completions(&analysis.db, position).unwrap(); | ||
332 | let completion_items: Vec<CompletionItem> = completions.into(); | ||
333 | let mut kind_completions: Vec<CompletionItem> = | ||
334 | completion_items.into_iter().filter(|c| c.completion_kind == kind).collect(); | ||
335 | kind_completions.sort_by_key(|c| c.label.clone()); | ||
336 | kind_completions | ||
337 | } | ||
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index aada4d025..5213def20 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -104,10 +104,7 @@ impl Completions { | |||
104 | }; | 104 | }; |
105 | 105 | ||
106 | // Add `<>` for generic types | 106 | // Add `<>` for generic types |
107 | if ctx.is_path_type | 107 | if ctx.is_path_type && !ctx.has_type_args && ctx.options.add_call_parenthesis { |
108 | && !ctx.has_type_args | ||
109 | && ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis") | ||
110 | { | ||
111 | let has_non_default_type_params = match resolution { | 108 | let has_non_default_type_params = match resolution { |
112 | ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(ctx.db), | 109 | ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(ctx.db), |
113 | ScopeDef::ModuleDef(TypeAlias(it)) => it.has_non_default_type_params(ctx.db), | 110 | ScopeDef::ModuleDef(TypeAlias(it)) => it.has_non_default_type_params(ctx.db), |
@@ -212,21 +209,14 @@ impl Completions { | |||
212 | .detail(function_signature.to_string()); | 209 | .detail(function_signature.to_string()); |
213 | 210 | ||
214 | // If not an import, add parenthesis automatically. | 211 | // If not an import, add parenthesis automatically. |
215 | if ctx.use_item_syntax.is_none() | 212 | 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); | 213 | tested_by!(inserts_parens_for_function_calls); |
220 | 214 | ||
221 | let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { | 215 | let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { |
222 | (format!("{}()$0", name), format!("{}()", name)) | 216 | (format!("{}()$0", name), format!("{}()", name)) |
223 | } else { | 217 | } else { |
224 | builder = builder.trigger_call_info(); | 218 | builder = builder.trigger_call_info(); |
225 | let snippet = if ctx | 219 | 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 }; | 220 | let to_skip = if has_self_param { 1 } else { 0 }; |
231 | let function_params_snippet = join( | 221 | let function_params_snippet = join( |
232 | function_signature.parameter_names.iter().skip(to_skip).enumerate().map( | 222 | function_signature.parameter_names.iter().skip(to_skip).enumerate().map( |
@@ -317,12 +307,22 @@ mod tests { | |||
317 | use insta::assert_debug_snapshot; | 307 | use insta::assert_debug_snapshot; |
318 | use test_utils::covers; | 308 | use test_utils::covers; |
319 | 309 | ||
320 | use crate::completion::{do_completion, CompletionItem, CompletionKind}; | 310 | use crate::completion::{ |
311 | test_utils::{do_completion, do_completion_with_options}, | ||
312 | CompletionItem, CompletionKind, CompletionOptions, | ||
313 | }; | ||
321 | 314 | ||
322 | fn do_reference_completion(ra_fixture: &str) -> Vec<CompletionItem> { | 315 | fn do_reference_completion(ra_fixture: &str) -> Vec<CompletionItem> { |
323 | do_completion(ra_fixture, CompletionKind::Reference) | 316 | do_completion(ra_fixture, CompletionKind::Reference) |
324 | } | 317 | } |
325 | 318 | ||
319 | fn do_reference_completion_with_options( | ||
320 | ra_fixture: &str, | ||
321 | options: CompletionOptions, | ||
322 | ) -> Vec<CompletionItem> { | ||
323 | do_completion_with_options(ra_fixture, CompletionKind::Reference, &options) | ||
324 | } | ||
325 | |||
326 | #[test] | 326 | #[test] |
327 | fn enum_detail_includes_names_for_record() { | 327 | fn enum_detail_includes_names_for_record() { |
328 | assert_debug_snapshot!( | 328 | assert_debug_snapshot!( |
@@ -543,7 +543,7 @@ mod tests { | |||
543 | } | 543 | } |
544 | 544 | ||
545 | #[test] | 545 | #[test] |
546 | fn parens_for_method_call() { | 546 | fn arg_snippets_for_method_call() { |
547 | assert_debug_snapshot!( | 547 | assert_debug_snapshot!( |
548 | do_reference_completion( | 548 | do_reference_completion( |
549 | r" | 549 | r" |
@@ -573,6 +573,40 @@ mod tests { | |||
573 | } | 573 | } |
574 | 574 | ||
575 | #[test] | 575 | #[test] |
576 | fn no_arg_snippets_for_method_call() { | ||
577 | assert_debug_snapshot!( | ||
578 | do_reference_completion_with_options( | ||
579 | r" | ||
580 | struct S {} | ||
581 | impl S { | ||
582 | fn foo(&self, x: i32) {} | ||
583 | } | ||
584 | fn bar(s: &S) { | ||
585 | s.f<|> | ||
586 | } | ||
587 | ", | ||
588 | CompletionOptions { | ||
589 | add_call_argument_snippets: false, | ||
590 | .. Default::default() | ||
591 | } | ||
592 | ), | ||
593 | @r###" | ||
594 | [ | ||
595 | CompletionItem { | ||
596 | label: "foo(…)", | ||
597 | source_range: [171; 172), | ||
598 | delete: [171; 172), | ||
599 | insert: "foo($0)", | ||
600 | kind: Method, | ||
601 | lookup: "foo", | ||
602 | detail: "fn foo(&self, x: i32)", | ||
603 | }, | ||
604 | ] | ||
605 | "### | ||
606 | ) | ||
607 | } | ||
608 | |||
609 | #[test] | ||
576 | fn dont_render_function_parens_in_use_item() { | 610 | fn dont_render_function_parens_in_use_item() { |
577 | assert_debug_snapshot!( | 611 | assert_debug_snapshot!( |
578 | do_reference_completion( | 612 | do_reference_completion( |
diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs new file mode 100644 index 000000000..136857315 --- /dev/null +++ b/crates/ra_ide/src/completion/test_utils.rs | |||
@@ -0,0 +1,29 @@ | |||
1 | //! Runs completion for testing purposes. | ||
2 | |||
3 | use crate::{ | ||
4 | completion::{completion_item::CompletionKind, CompletionOptions}, | ||
5 | mock_analysis::{analysis_and_position, single_file_with_position}, | ||
6 | CompletionItem, | ||
7 | }; | ||
8 | |||
9 | pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> { | ||
10 | do_completion_with_options(code, kind, &CompletionOptions::default()) | ||
11 | } | ||
12 | |||
13 | pub(crate) fn do_completion_with_options( | ||
14 | code: &str, | ||
15 | kind: CompletionKind, | ||
16 | options: &CompletionOptions, | ||
17 | ) -> Vec<CompletionItem> { | ||
18 | let (analysis, position) = if code.contains("//-") { | ||
19 | analysis_and_position(code) | ||
20 | } else { | ||
21 | single_file_with_position(code) | ||
22 | }; | ||
23 | let completions = analysis.completions(position, options).unwrap().unwrap(); | ||
24 | let completion_items: Vec<CompletionItem> = completions.into(); | ||
25 | let mut kind_completions: Vec<CompletionItem> = | ||
26 | completion_items.into_iter().filter(|c| c.completion_kind == kind).collect(); | ||
27 | kind_completions.sort_by_key(|c| c.label().to_owned()); | ||
28 | kind_completions | ||
29 | } | ||
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 39981ed3b..015fae195 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -62,7 +62,7 @@ use crate::display::ToNav; | |||
62 | pub use crate::{ | 62 | pub use crate::{ |
63 | assists::{Assist, AssistId}, | 63 | assists::{Assist, AssistId}, |
64 | call_hierarchy::CallItem, | 64 | call_hierarchy::CallItem, |
65 | completion::{CompletionItem, CompletionItemKind, InsertTextFormat}, | 65 | completion::{CompletionItem, CompletionItemKind, CompletionOptions, InsertTextFormat}, |
66 | diagnostics::Severity, | 66 | diagnostics::Severity, |
67 | display::{file_structure, FunctionSignature, NavigationTarget, StructureNode}, | 67 | display::{file_structure, FunctionSignature, NavigationTarget, StructureNode}, |
68 | expand_macro::ExpandedMacro, | 68 | expand_macro::ExpandedMacro, |
@@ -84,7 +84,6 @@ pub use ra_db::{ | |||
84 | }; | 84 | }; |
85 | pub use ra_ide_db::{ | 85 | pub use ra_ide_db::{ |
86 | change::{AnalysisChange, LibraryData}, | 86 | change::{AnalysisChange, LibraryData}, |
87 | feature_flags::FeatureFlags, | ||
88 | line_index::{LineCol, LineIndex}, | 87 | line_index::{LineCol, LineIndex}, |
89 | line_index_utils::translate_offset_with_edit, | 88 | line_index_utils::translate_offset_with_edit, |
90 | search::SearchScope, | 89 | search::SearchScope, |
@@ -131,13 +130,13 @@ pub struct AnalysisHost { | |||
131 | 130 | ||
132 | impl Default for AnalysisHost { | 131 | impl Default for AnalysisHost { |
133 | fn default() -> AnalysisHost { | 132 | fn default() -> AnalysisHost { |
134 | AnalysisHost::new(None, FeatureFlags::default()) | 133 | AnalysisHost::new(None) |
135 | } | 134 | } |
136 | } | 135 | } |
137 | 136 | ||
138 | impl AnalysisHost { | 137 | impl AnalysisHost { |
139 | pub fn new(lru_capcity: Option<usize>, feature_flags: FeatureFlags) -> AnalysisHost { | 138 | pub fn new(lru_capacity: Option<usize>) -> AnalysisHost { |
140 | AnalysisHost { db: RootDatabase::new(lru_capcity, feature_flags) } | 139 | AnalysisHost { db: RootDatabase::new(lru_capacity) } |
141 | } | 140 | } |
142 | /// Returns a snapshot of the current state, which you can query for | 141 | /// Returns a snapshot of the current state, which you can query for |
143 | /// semantic information. | 142 | /// semantic information. |
@@ -145,10 +144,6 @@ impl AnalysisHost { | |||
145 | Analysis { db: self.db.snapshot() } | 144 | Analysis { db: self.db.snapshot() } |
146 | } | 145 | } |
147 | 146 | ||
148 | pub fn feature_flags(&self) -> &FeatureFlags { | ||
149 | &self.db.feature_flags | ||
150 | } | ||
151 | |||
152 | /// Applies changes to the current state of the world. If there are | 147 | /// Applies changes to the current state of the world. If there are |
153 | /// outstanding snapshots, they will be canceled. | 148 | /// outstanding snapshots, they will be canceled. |
154 | pub fn apply_change(&mut self, change: AnalysisChange) { | 149 | pub fn apply_change(&mut self, change: AnalysisChange) { |
@@ -225,11 +220,6 @@ impl Analysis { | |||
225 | (host.analysis(), file_id) | 220 | (host.analysis(), file_id) |
226 | } | 221 | } |
227 | 222 | ||
228 | /// Features for Analysis. | ||
229 | pub fn feature_flags(&self) -> &FeatureFlags { | ||
230 | &self.db.feature_flags | ||
231 | } | ||
232 | |||
233 | /// Debug info about the current state of the analysis. | 223 | /// Debug info about the current state of the analysis. |
234 | pub fn status(&self) -> Cancelable<String> { | 224 | pub fn status(&self) -> Cancelable<String> { |
235 | self.with_db(|db| status::status(&*db)) | 225 | self.with_db(|db| status::status(&*db)) |
@@ -451,8 +441,12 @@ impl Analysis { | |||
451 | } | 441 | } |
452 | 442 | ||
453 | /// Computes completions at the given position. | 443 | /// Computes completions at the given position. |
454 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { | 444 | pub fn completions( |
455 | self.with_db(|db| completion::completions(db, position).map(Into::into)) | 445 | &self, |
446 | position: FilePosition, | ||
447 | options: &CompletionOptions, | ||
448 | ) -> Cancelable<Option<Vec<CompletionItem>>> { | ||
449 | self.with_db(|db| completion::completions(db, position, options).map(Into::into)) | ||
456 | } | 450 | } |
457 | 451 | ||
458 | /// Computes assists (aka code actions aka intentions) for the given | 452 | /// Computes assists (aka code actions aka intentions) for the given |
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 5b4bcf434..7d1190af9 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs | |||
@@ -9,7 +9,8 @@ use ra_syntax::{ | |||
9 | use ra_text_edit::TextEdit; | 9 | use ra_text_edit::TextEdit; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | FileId, FilePosition, FileSystemEdit, RangeInfo, SourceChange, SourceFileEdit, TextRange, | 12 | FilePosition, FileSystemEdit, RangeInfo, Reference, ReferenceKind, SourceChange, |
13 | SourceFileEdit, TextRange, | ||
13 | }; | 14 | }; |
14 | 15 | ||
15 | use super::find_all_refs; | 16 | use super::find_all_refs; |
@@ -46,12 +47,29 @@ fn find_name_and_module_at_offset( | |||
46 | Some((ast_name, ast_module)) | 47 | Some((ast_name, ast_module)) |
47 | } | 48 | } |
48 | 49 | ||
49 | fn source_edit_from_file_id_range( | 50 | fn source_edit_from_reference(reference: Reference, new_name: &str) -> SourceFileEdit { |
50 | file_id: FileId, | 51 | let mut replacement_text = String::new(); |
51 | range: TextRange, | 52 | let file_id = reference.file_range.file_id; |
52 | new_name: &str, | 53 | let range = match reference.kind { |
53 | ) -> SourceFileEdit { | 54 | ReferenceKind::StructFieldShorthandForField => { |
54 | SourceFileEdit { file_id, edit: TextEdit::replace(range, new_name.into()) } | 55 | replacement_text.push_str(new_name); |
56 | replacement_text.push_str(": "); | ||
57 | TextRange::from_to( | ||
58 | reference.file_range.range.start(), | ||
59 | reference.file_range.range.start(), | ||
60 | ) | ||
61 | } | ||
62 | ReferenceKind::StructFieldShorthandForLocal => { | ||
63 | replacement_text.push_str(": "); | ||
64 | replacement_text.push_str(new_name); | ||
65 | TextRange::from_to(reference.file_range.range.end(), reference.file_range.range.end()) | ||
66 | } | ||
67 | _ => { | ||
68 | replacement_text.push_str(new_name); | ||
69 | reference.file_range.range | ||
70 | } | ||
71 | }; | ||
72 | SourceFileEdit { file_id, edit: TextEdit::replace(range, replacement_text) } | ||
55 | } | 73 | } |
56 | 74 | ||
57 | fn rename_mod( | 75 | fn rename_mod( |
@@ -99,13 +117,10 @@ fn rename_mod( | |||
99 | source_file_edits.push(edit); | 117 | source_file_edits.push(edit); |
100 | 118 | ||
101 | if let Some(RangeInfo { range: _, info: refs }) = find_all_refs(sema.db, position, None) { | 119 | if let Some(RangeInfo { range: _, info: refs }) = find_all_refs(sema.db, position, None) { |
102 | let ref_edits = refs.references.into_iter().map(|reference| { | 120 | let ref_edits = refs |
103 | source_edit_from_file_id_range( | 121 | .references |
104 | reference.file_range.file_id, | 122 | .into_iter() |
105 | reference.file_range.range, | 123 | .map(|reference| source_edit_from_reference(reference, new_name)); |
106 | new_name, | ||
107 | ) | ||
108 | }); | ||
109 | source_file_edits.extend(ref_edits); | 124 | source_file_edits.extend(ref_edits); |
110 | } | 125 | } |
111 | 126 | ||
@@ -121,13 +136,7 @@ fn rename_reference( | |||
121 | 136 | ||
122 | let edit = refs | 137 | let edit = refs |
123 | .into_iter() | 138 | .into_iter() |
124 | .map(|reference| { | 139 | .map(|reference| source_edit_from_reference(reference, new_name)) |
125 | source_edit_from_file_id_range( | ||
126 | reference.file_range.file_id, | ||
127 | reference.file_range.range, | ||
128 | new_name, | ||
129 | ) | ||
130 | }) | ||
131 | .collect::<Vec<_>>(); | 140 | .collect::<Vec<_>>(); |
132 | 141 | ||
133 | if edit.is_empty() { | 142 | if edit.is_empty() { |
@@ -286,6 +295,163 @@ mod tests { | |||
286 | } | 295 | } |
287 | 296 | ||
288 | #[test] | 297 | #[test] |
298 | fn test_rename_struct_field() { | ||
299 | test_rename( | ||
300 | r#" | ||
301 | struct Foo { | ||
302 | i<|>: i32, | ||
303 | } | ||
304 | |||
305 | impl Foo { | ||
306 | fn new(i: i32) -> Self { | ||
307 | Self { i: i } | ||
308 | } | ||
309 | } | ||
310 | "#, | ||
311 | "j", | ||
312 | r#" | ||
313 | struct Foo { | ||
314 | j: i32, | ||
315 | } | ||
316 | |||
317 | impl Foo { | ||
318 | fn new(i: i32) -> Self { | ||
319 | Self { j: i } | ||
320 | } | ||
321 | } | ||
322 | "#, | ||
323 | ); | ||
324 | } | ||
325 | |||
326 | #[test] | ||
327 | fn test_rename_struct_field_for_shorthand() { | ||
328 | test_rename( | ||
329 | r#" | ||
330 | struct Foo { | ||
331 | i<|>: i32, | ||
332 | } | ||
333 | |||
334 | impl Foo { | ||
335 | fn new(i: i32) -> Self { | ||
336 | Self { i } | ||
337 | } | ||
338 | } | ||
339 | "#, | ||
340 | "j", | ||
341 | r#" | ||
342 | struct Foo { | ||
343 | j: i32, | ||
344 | } | ||
345 | |||
346 | impl Foo { | ||
347 | fn new(i: i32) -> Self { | ||
348 | Self { j: i } | ||
349 | } | ||
350 | } | ||
351 | "#, | ||
352 | ); | ||
353 | } | ||
354 | |||
355 | #[test] | ||
356 | fn test_rename_local_for_field_shorthand() { | ||
357 | test_rename( | ||
358 | r#" | ||
359 | struct Foo { | ||
360 | i: i32, | ||
361 | } | ||
362 | |||
363 | impl Foo { | ||
364 | fn new(i<|>: i32) -> Self { | ||
365 | Self { i } | ||
366 | } | ||
367 | } | ||
368 | "#, | ||
369 | "j", | ||
370 | r#" | ||
371 | struct Foo { | ||
372 | i: i32, | ||
373 | } | ||
374 | |||
375 | impl Foo { | ||
376 | fn new(j: i32) -> Self { | ||
377 | Self { i: j } | ||
378 | } | ||
379 | } | ||
380 | "#, | ||
381 | ); | ||
382 | } | ||
383 | |||
384 | #[test] | ||
385 | fn test_field_shorthand_correct_struct() { | ||
386 | test_rename( | ||
387 | r#" | ||
388 | struct Foo { | ||
389 | i<|>: i32, | ||
390 | } | ||
391 | |||
392 | struct Bar { | ||
393 | i: i32, | ||
394 | } | ||
395 | |||
396 | impl Bar { | ||
397 | fn new(i: i32) -> Self { | ||
398 | Self { i } | ||
399 | } | ||
400 | } | ||
401 | "#, | ||
402 | "j", | ||
403 | r#" | ||
404 | struct Foo { | ||
405 | j: i32, | ||
406 | } | ||
407 | |||
408 | struct Bar { | ||
409 | i: i32, | ||
410 | } | ||
411 | |||
412 | impl Bar { | ||
413 | fn new(i: i32) -> Self { | ||
414 | Self { i } | ||
415 | } | ||
416 | } | ||
417 | "#, | ||
418 | ); | ||
419 | } | ||
420 | |||
421 | #[test] | ||
422 | fn test_shadow_local_for_struct_shorthand() { | ||
423 | test_rename( | ||
424 | r#" | ||
425 | struct Foo { | ||
426 | i: i32, | ||
427 | } | ||
428 | |||
429 | fn baz(i<|>: i32) -> Self { | ||
430 | let x = Foo { i }; | ||
431 | { | ||
432 | let i = 0; | ||
433 | Foo { i } | ||
434 | } | ||
435 | } | ||
436 | "#, | ||
437 | "j", | ||
438 | r#" | ||
439 | struct Foo { | ||
440 | i: i32, | ||
441 | } | ||
442 | |||
443 | fn baz(j: i32) -> Self { | ||
444 | let x = Foo { i: j }; | ||
445 | { | ||
446 | let i = 0; | ||
447 | Foo { i } | ||
448 | } | ||
449 | } | ||
450 | "#, | ||
451 | ); | ||
452 | } | ||
453 | |||
454 | #[test] | ||
289 | fn test_rename_mod() { | 455 | fn test_rename_mod() { |
290 | let (analysis, position) = analysis_and_position( | 456 | let (analysis, position) = analysis_and_position( |
291 | " | 457 | " |
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index 74408d3d7..fc1b19def 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -5,7 +5,6 @@ | |||
5 | pub mod marks; | 5 | pub mod marks; |
6 | pub mod line_index; | 6 | pub mod line_index; |
7 | pub mod line_index_utils; | 7 | pub mod line_index_utils; |
8 | pub mod feature_flags; | ||
9 | pub mod symbol_index; | 8 | pub mod symbol_index; |
10 | pub mod change; | 9 | pub mod change; |
11 | pub mod defs; | 10 | pub mod defs; |
@@ -22,7 +21,7 @@ use ra_db::{ | |||
22 | }; | 21 | }; |
23 | use rustc_hash::FxHashMap; | 22 | use rustc_hash::FxHashMap; |
24 | 23 | ||
25 | use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase}; | 24 | use crate::{line_index::LineIndex, symbol_index::SymbolsDatabase}; |
26 | 25 | ||
27 | #[salsa::database( | 26 | #[salsa::database( |
28 | ra_db::SourceDatabaseStorage, | 27 | ra_db::SourceDatabaseStorage, |
@@ -37,7 +36,6 @@ use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::Sy | |||
37 | #[derive(Debug)] | 36 | #[derive(Debug)] |
38 | pub struct RootDatabase { | 37 | pub struct RootDatabase { |
39 | runtime: salsa::Runtime<RootDatabase>, | 38 | runtime: salsa::Runtime<RootDatabase>, |
40 | pub feature_flags: Arc<FeatureFlags>, | ||
41 | pub(crate) debug_data: Arc<DebugData>, | 39 | pub(crate) debug_data: Arc<DebugData>, |
42 | pub last_gc: crate::wasm_shims::Instant, | 40 | pub last_gc: crate::wasm_shims::Instant, |
43 | pub last_gc_check: crate::wasm_shims::Instant, | 41 | pub last_gc_check: crate::wasm_shims::Instant, |
@@ -89,17 +87,16 @@ impl salsa::Database for RootDatabase { | |||
89 | 87 | ||
90 | impl Default for RootDatabase { | 88 | impl Default for RootDatabase { |
91 | fn default() -> RootDatabase { | 89 | fn default() -> RootDatabase { |
92 | RootDatabase::new(None, FeatureFlags::default()) | 90 | RootDatabase::new(None) |
93 | } | 91 | } |
94 | } | 92 | } |
95 | 93 | ||
96 | impl RootDatabase { | 94 | impl RootDatabase { |
97 | pub fn new(lru_capacity: Option<usize>, feature_flags: FeatureFlags) -> RootDatabase { | 95 | pub fn new(lru_capacity: Option<usize>) -> RootDatabase { |
98 | let mut db = RootDatabase { | 96 | let mut db = RootDatabase { |
99 | runtime: salsa::Runtime::default(), | 97 | runtime: salsa::Runtime::default(), |
100 | last_gc: crate::wasm_shims::Instant::now(), | 98 | last_gc: crate::wasm_shims::Instant::now(), |
101 | last_gc_check: crate::wasm_shims::Instant::now(), | 99 | last_gc_check: crate::wasm_shims::Instant::now(), |
102 | feature_flags: Arc::new(feature_flags), | ||
103 | debug_data: Default::default(), | 100 | debug_data: Default::default(), |
104 | }; | 101 | }; |
105 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); | 102 | db.set_crate_graph_with_durability(Default::default(), Durability::HIGH); |
@@ -119,7 +116,6 @@ impl salsa::ParallelDatabase for RootDatabase { | |||
119 | runtime: self.runtime.snapshot(self), | 116 | runtime: self.runtime.snapshot(self), |
120 | last_gc: self.last_gc, | 117 | last_gc: self.last_gc, |
121 | last_gc_check: self.last_gc_check, | 118 | last_gc_check: self.last_gc_check, |
122 | feature_flags: Arc::clone(&self.feature_flags), | ||
123 | debug_data: Arc::clone(&self.debug_data), | 119 | debug_data: Arc::clone(&self.debug_data), |
124 | }) | 120 | }) |
125 | } | 121 | } |
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs index 6f198df04..cf78d3e41 100644 --- a/crates/ra_ide_db/src/search.rs +++ b/crates/ra_ide_db/src/search.rs | |||
@@ -17,7 +17,7 @@ use rustc_hash::FxHashMap; | |||
17 | use test_utils::tested_by; | 17 | use test_utils::tested_by; |
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | defs::{classify_name_ref, Definition}, | 20 | defs::{classify_name_ref, Definition, NameRefClass}, |
21 | RootDatabase, | 21 | RootDatabase, |
22 | }; | 22 | }; |
23 | 23 | ||
@@ -30,6 +30,8 @@ pub struct Reference { | |||
30 | 30 | ||
31 | #[derive(Debug, Clone, PartialEq)] | 31 | #[derive(Debug, Clone, PartialEq)] |
32 | pub enum ReferenceKind { | 32 | pub enum ReferenceKind { |
33 | StructFieldShorthandForField, | ||
34 | StructFieldShorthandForLocal, | ||
33 | StructLiteral, | 35 | StructLiteral, |
34 | Other, | 36 | Other, |
35 | } | 37 | } |
@@ -237,9 +239,8 @@ impl Definition { | |||
237 | // FIXME: reuse sb | 239 | // FIXME: reuse sb |
238 | // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098 | 240 | // See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098 |
239 | 241 | ||
240 | if let Some(d) = classify_name_ref(&sema, &name_ref) { | 242 | match classify_name_ref(&sema, &name_ref) { |
241 | let d = d.definition(); | 243 | Some(NameRefClass::Definition(def)) if &def == self => { |
242 | if &d == self { | ||
243 | let kind = if is_record_lit_name_ref(&name_ref) | 244 | let kind = if is_record_lit_name_ref(&name_ref) |
244 | || is_call_expr_name_ref(&name_ref) | 245 | || is_call_expr_name_ref(&name_ref) |
245 | { | 246 | { |
@@ -252,9 +253,26 @@ impl Definition { | |||
252 | refs.push(Reference { | 253 | refs.push(Reference { |
253 | file_range, | 254 | file_range, |
254 | kind, | 255 | kind, |
255 | access: reference_access(&d, &name_ref), | 256 | access: reference_access(&def, &name_ref), |
256 | }); | 257 | }); |
257 | } | 258 | } |
259 | Some(NameRefClass::FieldShorthand { local, field }) => { | ||
260 | match self { | ||
261 | Definition::StructField(_) if &field == self => refs.push(Reference { | ||
262 | file_range: sema.original_range(name_ref.syntax()), | ||
263 | kind: ReferenceKind::StructFieldShorthandForField, | ||
264 | access: reference_access(&field, &name_ref), | ||
265 | }), | ||
266 | Definition::Local(l) if &local == l => refs.push(Reference { | ||
267 | file_range: sema.original_range(name_ref.syntax()), | ||
268 | kind: ReferenceKind::StructFieldShorthandForLocal, | ||
269 | access: reference_access(&Definition::Local(local), &name_ref), | ||
270 | }), | ||
271 | |||
272 | _ => {} // not a usage | ||
273 | }; | ||
274 | } | ||
275 | _ => {} // not a usage | ||
258 | } | 276 | } |
259 | } | 277 | } |
260 | } | 278 | } |
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs index 91855e592..28a23934f 100644 --- a/crates/rust-analyzer/src/cli/analysis_bench.rs +++ b/crates/rust-analyzer/src/cli/analysis_bench.rs | |||
@@ -12,7 +12,7 @@ use ra_db::{ | |||
12 | salsa::{Database, Durability}, | 12 | salsa::{Database, Durability}, |
13 | FileId, SourceDatabaseExt, | 13 | FileId, SourceDatabaseExt, |
14 | }; | 14 | }; |
15 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FilePosition, LineCol}; | 15 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CompletionOptions, FilePosition, LineCol}; |
16 | 16 | ||
17 | use crate::cli::{load_cargo::load_cargo, Verbosity}; | 17 | use crate::cli::{load_cargo::load_cargo, Verbosity}; |
18 | 18 | ||
@@ -94,17 +94,19 @@ pub fn analysis_bench(verbosity: Verbosity, path: &Path, what: BenchWhat) -> Res | |||
94 | .analysis() | 94 | .analysis() |
95 | .file_line_index(file_id)? | 95 | .file_line_index(file_id)? |
96 | .offset(LineCol { line: pos.line - 1, col_utf16: pos.column }); | 96 | .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 }; |
98 | 98 | ||
99 | if is_completion { | 99 | if is_completion { |
100 | let res = | 100 | let options = CompletionOptions::default(); |
101 | do_work(&mut host, file_id, |analysis| analysis.completions(file_postion)); | 101 | let res = do_work(&mut host, file_id, |analysis| { |
102 | analysis.completions(file_position, &options) | ||
103 | }); | ||
102 | if verbosity.is_verbose() { | 104 | if verbosity.is_verbose() { |
103 | println!("\n{:#?}", res); | 105 | println!("\n{:#?}", res); |
104 | } | 106 | } |
105 | } else { | 107 | } else { |
106 | let res = | 108 | 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)); |
108 | if verbosity.is_verbose() { | 110 | if verbosity.is_verbose() { |
109 | println!("\n{:#?}", res); | 111 | println!("\n{:#?}", res); |
110 | } | 112 | } |
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index 403f353f1..2ce69c9b3 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs | |||
@@ -6,7 +6,7 @@ use std::path::Path; | |||
6 | use anyhow::Result; | 6 | use anyhow::Result; |
7 | use crossbeam_channel::{unbounded, Receiver}; | 7 | use crossbeam_channel::{unbounded, Receiver}; |
8 | use ra_db::{CrateGraph, FileId, SourceRootId}; | 8 | use ra_db::{CrateGraph, FileId, SourceRootId}; |
9 | use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags}; | 9 | use ra_ide::{AnalysisChange, AnalysisHost}; |
10 | use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; | 10 | use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; |
11 | use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; | 11 | use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; |
12 | use rustc_hash::{FxHashMap, FxHashSet}; | 12 | use rustc_hash::{FxHashMap, FxHashSet}; |
@@ -85,7 +85,7 @@ pub(crate) fn load( | |||
85 | receiver: Receiver<VfsTask>, | 85 | receiver: Receiver<VfsTask>, |
86 | ) -> AnalysisHost { | 86 | ) -> AnalysisHost { |
87 | let lru_cap = std::env::var("RA_LRU_CAP").ok().and_then(|it| it.parse::<usize>().ok()); | 87 | let lru_cap = std::env::var("RA_LRU_CAP").ok().and_then(|it| it.parse::<usize>().ok()); |
88 | let mut host = AnalysisHost::new(lru_cap, FeatureFlags::default()); | 88 | let mut host = AnalysisHost::new(lru_cap); |
89 | let mut analysis_change = AnalysisChange::new(); | 89 | let mut analysis_change = AnalysisChange::new(); |
90 | analysis_change.set_crate_graph(crate_graph); | 90 | analysis_change.set_crate_graph(crate_graph); |
91 | 91 | ||
diff --git a/crates/ra_ide_db/src/feature_flags.rs b/crates/rust-analyzer/src/feature_flags.rs index 968415072..dbb3f50a0 100644 --- a/crates/ra_ide_db/src/feature_flags.rs +++ b/crates/rust-analyzer/src/feature_flags.rs | |||
@@ -2,6 +2,10 @@ | |||
2 | 2 | ||
3 | use rustc_hash::FxHashMap; | 3 | use rustc_hash::FxHashMap; |
4 | 4 | ||
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 | |||
5 | /// Feature flags hold fine-grained toggles for all *user-visible* features of | 9 | /// Feature flags hold fine-grained toggles for all *user-visible* features of |
6 | /// rust-analyzer. | 10 | /// rust-analyzer. |
7 | /// | 11 | /// |
diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs index a0f968823..e50e47b19 100644 --- a/crates/rust-analyzer/src/lib.rs +++ b/crates/rust-analyzer/src/lib.rs | |||
@@ -37,6 +37,7 @@ mod config; | |||
37 | mod world; | 37 | mod world; |
38 | mod diagnostics; | 38 | mod diagnostics; |
39 | mod semantic_tokens; | 39 | mod semantic_tokens; |
40 | mod feature_flags; | ||
40 | 41 | ||
41 | use serde::de::DeserializeOwned; | 42 | use serde::de::DeserializeOwned; |
42 | 43 | ||
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 6d123f629..4f7aac754 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -18,7 +18,7 @@ use crossbeam_channel::{select, unbounded, RecvError, Sender}; | |||
18 | use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; | 18 | use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; |
19 | use lsp_types::{ClientCapabilities, NumberOrString}; | 19 | use lsp_types::{ClientCapabilities, NumberOrString}; |
20 | use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckTask}; | 20 | use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckTask}; |
21 | use ra_ide::{Canceled, FeatureFlags, FileId, LibraryData, SourceRootId}; | 21 | use ra_ide::{Canceled, FileId, LibraryData, SourceRootId}; |
22 | use ra_prof::profile; | 22 | use ra_prof::profile; |
23 | use ra_vfs::{VfsFile, VfsTask, Watch}; | 23 | use ra_vfs::{VfsFile, VfsTask, Watch}; |
24 | use relative_path::RelativePathBuf; | 24 | use relative_path::RelativePathBuf; |
@@ -28,6 +28,7 @@ use threadpool::ThreadPool; | |||
28 | 28 | ||
29 | use crate::{ | 29 | use crate::{ |
30 | diagnostics::DiagnosticTask, | 30 | diagnostics::DiagnosticTask, |
31 | feature_flags::FeatureFlags, | ||
31 | main_loop::{ | 32 | main_loop::{ |
32 | pending_requests::{PendingRequest, PendingRequests}, | 33 | pending_requests::{PendingRequest, PendingRequests}, |
33 | subscriptions::Subscriptions, | 34 | subscriptions::Subscriptions, |
@@ -424,7 +425,7 @@ fn loop_turn( | |||
424 | { | 425 | { |
425 | loop_state.workspace_loaded = true; | 426 | loop_state.workspace_loaded = true; |
426 | let n_packages: usize = world_state.workspaces.iter().map(|it| it.n_packages()).sum(); | 427 | let n_packages: usize = world_state.workspaces.iter().map(|it| it.n_packages()).sum(); |
427 | if world_state.feature_flags().get("notifications.workspace-loaded") { | 428 | if world_state.feature_flags.get("notifications.workspace-loaded") { |
428 | let msg = format!("workspace loaded, {} rust packages", n_packages); | 429 | let msg = format!("workspace loaded, {} rust packages", n_packages); |
429 | show_message(req::MessageType::Info, msg, &connection.sender); | 430 | show_message(req::MessageType::Info, msg, &connection.sender); |
430 | } | 431 | } |
@@ -840,7 +841,7 @@ fn update_file_notifications_on_threadpool( | |||
840 | subscriptions: Vec<FileId>, | 841 | subscriptions: Vec<FileId>, |
841 | ) { | 842 | ) { |
842 | log::trace!("updating notifications for {:?}", subscriptions); | 843 | log::trace!("updating notifications for {:?}", subscriptions); |
843 | let publish_diagnostics = world.feature_flags().get("lsp.diagnostics"); | 844 | let publish_diagnostics = world.feature_flags.get("lsp.diagnostics"); |
844 | pool.execute(move || { | 845 | pool.execute(move || { |
845 | for file_id in subscriptions { | 846 | for file_id in subscriptions { |
846 | if publish_diagnostics { | 847 | if publish_diagnostics { |
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index 8dc6e8dc0..fcb40432d 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs | |||
@@ -20,8 +20,8 @@ use lsp_types::{ | |||
20 | TextEdit, WorkspaceEdit, | 20 | TextEdit, WorkspaceEdit, |
21 | }; | 21 | }; |
22 | use ra_ide::{ | 22 | use ra_ide::{ |
23 | Assist, AssistId, FileId, FilePosition, FileRange, Query, RangeInfo, Runnable, RunnableKind, | 23 | Assist, AssistId, CompletionOptions, FileId, FilePosition, FileRange, Query, RangeInfo, |
24 | SearchScope, | 24 | Runnable, RunnableKind, SearchScope, |
25 | }; | 25 | }; |
26 | use ra_prof::profile; | 26 | use ra_prof::profile; |
27 | use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; | 27 | use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; |
@@ -424,7 +424,15 @@ pub fn handle_completion( | |||
424 | return Ok(None); | 424 | return Ok(None); |
425 | } | 425 | } |
426 | 426 | ||
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.feature_flags.get("completion.insertion.add-call-parenthesis"), | ||
430 | add_call_argument_snippets: world | ||
431 | .feature_flags | ||
432 | .get("completion.insertion.add-argument-snippets"), | ||
433 | }; | ||
434 | |||
435 | let items = match world.analysis().completions(position, &options)? { | ||
428 | None => return Ok(None), | 436 | None => return Ok(None), |
429 | Some(items) => items, | 437 | Some(items) => items, |
430 | }; | 438 | }; |
@@ -461,7 +469,7 @@ pub fn handle_signature_help( | |||
461 | let _p = profile("handle_signature_help"); | 469 | let _p = profile("handle_signature_help"); |
462 | let position = params.try_conv_with(&world)?; | 470 | let position = params.try_conv_with(&world)?; |
463 | if let Some(call_info) = world.analysis().call_info(position)? { | 471 | if let Some(call_info) = world.analysis().call_info(position)? { |
464 | let concise = !world.analysis().feature_flags().get("call-info.full"); | 472 | let concise = !world.feature_flags.get("call-info.full"); |
465 | let mut active_parameter = call_info.active_parameter.map(|it| it as i64); | 473 | let mut active_parameter = call_info.active_parameter.map(|it| it as i64); |
466 | if concise && call_info.signature.has_self_param { | 474 | if concise && call_info.signature.has_self_param { |
467 | active_parameter = active_parameter.map(|it| it.saturating_sub(1)); | 475 | active_parameter = active_parameter.map(|it| it.saturating_sub(1)); |
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index b64140b74..9ef368529 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs | |||
@@ -13,8 +13,7 @@ use lsp_types::Url; | |||
13 | use parking_lot::RwLock; | 13 | use parking_lot::RwLock; |
14 | use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher}; | 14 | use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher}; |
15 | use ra_ide::{ | 15 | use ra_ide::{ |
16 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FeatureFlags, FileId, LibraryData, | 16 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId, |
17 | SourceRootId, | ||
18 | }; | 17 | }; |
19 | use ra_project_model::{get_rustc_cfg_options, ProjectWorkspace}; | 18 | use ra_project_model::{get_rustc_cfg_options, ProjectWorkspace}; |
20 | use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch}; | 19 | use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch}; |
@@ -22,6 +21,7 @@ use relative_path::RelativePathBuf; | |||
22 | 21 | ||
23 | use crate::{ | 22 | use crate::{ |
24 | diagnostics::{CheckFixes, DiagnosticCollection}, | 23 | diagnostics::{CheckFixes, DiagnosticCollection}, |
24 | feature_flags::FeatureFlags, | ||
25 | main_loop::pending_requests::{CompletedRequest, LatestRequests}, | 25 | main_loop::pending_requests::{CompletedRequest, LatestRequests}, |
26 | vfs_glob::{Glob, RustPackageFilterBuilder}, | 26 | vfs_glob::{Glob, RustPackageFilterBuilder}, |
27 | LspError, Result, | 27 | LspError, Result, |
@@ -47,6 +47,7 @@ pub struct Options { | |||
47 | #[derive(Debug)] | 47 | #[derive(Debug)] |
48 | pub struct WorldState { | 48 | pub struct WorldState { |
49 | pub options: Options, | 49 | pub options: Options, |
50 | pub feature_flags: Arc<FeatureFlags>, | ||
50 | //FIXME: this belongs to `LoopState` rather than to `WorldState` | 51 | //FIXME: this belongs to `LoopState` rather than to `WorldState` |
51 | pub roots_to_scan: usize, | 52 | pub roots_to_scan: usize, |
52 | pub roots: Vec<PathBuf>, | 53 | pub roots: Vec<PathBuf>, |
@@ -62,6 +63,7 @@ pub struct WorldState { | |||
62 | /// An immutable snapshot of the world's state at a point in time. | 63 | /// An immutable snapshot of the world's state at a point in time. |
63 | pub struct WorldSnapshot { | 64 | pub struct WorldSnapshot { |
64 | pub options: Options, | 65 | pub options: Options, |
66 | pub feature_flags: Arc<FeatureFlags>, | ||
65 | pub workspaces: Arc<Vec<ProjectWorkspace>>, | 67 | pub workspaces: Arc<Vec<ProjectWorkspace>>, |
66 | pub analysis: Analysis, | 68 | pub analysis: Analysis, |
67 | pub latest_requests: Arc<RwLock<LatestRequests>>, | 69 | pub latest_requests: Arc<RwLock<LatestRequests>>, |
@@ -176,10 +178,11 @@ impl WorldState { | |||
176 | CheckWatcher::dummy() | 178 | CheckWatcher::dummy() |
177 | }); | 179 | }); |
178 | 180 | ||
179 | let mut analysis_host = AnalysisHost::new(lru_capacity, feature_flags); | 181 | let mut analysis_host = AnalysisHost::new(lru_capacity); |
180 | analysis_host.apply_change(change); | 182 | analysis_host.apply_change(change); |
181 | WorldState { | 183 | WorldState { |
182 | options, | 184 | options, |
185 | feature_flags: Arc::new(feature_flags), | ||
183 | roots_to_scan, | 186 | roots_to_scan, |
184 | roots: folder_roots, | 187 | roots: folder_roots, |
185 | workspaces: Arc::new(workspaces), | 188 | workspaces: Arc::new(workspaces), |
@@ -246,6 +249,7 @@ impl WorldState { | |||
246 | pub fn snapshot(&self) -> WorldSnapshot { | 249 | pub fn snapshot(&self) -> WorldSnapshot { |
247 | WorldSnapshot { | 250 | WorldSnapshot { |
248 | options: self.options.clone(), | 251 | options: self.options.clone(), |
252 | feature_flags: Arc::clone(&self.feature_flags), | ||
249 | workspaces: Arc::clone(&self.workspaces), | 253 | workspaces: Arc::clone(&self.workspaces), |
250 | analysis: self.analysis_host.analysis(), | 254 | analysis: self.analysis_host.analysis(), |
251 | vfs: Arc::clone(&self.vfs), | 255 | vfs: Arc::clone(&self.vfs), |
@@ -265,10 +269,6 @@ impl WorldState { | |||
265 | pub fn complete_request(&mut self, request: CompletedRequest) { | 269 | pub fn complete_request(&mut self, request: CompletedRequest) { |
266 | self.latest_requests.write().record(request) | 270 | self.latest_requests.write().record(request) |
267 | } | 271 | } |
268 | |||
269 | pub fn feature_flags(&self) -> &FeatureFlags { | ||
270 | self.analysis_host.feature_flags() | ||
271 | } | ||
272 | } | 272 | } |
273 | 273 | ||
274 | impl WorldSnapshot { | 274 | impl WorldSnapshot { |
@@ -336,8 +336,4 @@ impl WorldSnapshot { | |||
336 | let path = self.vfs.read().file2path(VfsFile(file_id.0)); | 336 | let path = self.vfs.read().file2path(VfsFile(file_id.0)); |
337 | self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path)) | 337 | self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path)) |
338 | } | 338 | } |
339 | |||
340 | pub fn feature_flags(&self) -> &FeatureFlags { | ||
341 | self.analysis.feature_flags() | ||
342 | } | ||
343 | } | 339 | } |