aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/completions')
-rw-r--r--crates/ide_completion/src/completions/dot.rs7
-rw-r--r--crates/ide_completion/src/completions/flyimport.rs6
-rw-r--r--crates/ide_completion/src/completions/keyword.rs2
-rw-r--r--crates/ide_completion/src/completions/postfix.rs17
4 files changed, 19 insertions, 13 deletions
diff --git a/crates/ide_completion/src/completions/dot.rs b/crates/ide_completion/src/completions/dot.rs
index 302c9ccbd..e0a7021fd 100644
--- a/crates/ide_completion/src/completions/dot.rs
+++ b/crates/ide_completion/src/completions/dot.rs
@@ -8,7 +8,7 @@ use crate::{context::CompletionContext, Completions};
8 8
9/// Complete dot accesses, i.e. fields or methods. 9/// Complete dot accesses, i.e. fields or methods.
10pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { 10pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
11 let dot_receiver = match &ctx.dot_receiver { 11 let dot_receiver = match ctx.dot_receiver() {
12 Some(expr) => expr, 12 Some(expr) => expr,
13 _ => return complete_undotted_self(acc, ctx), 13 _ => return complete_undotted_self(acc, ctx),
14 }; 14 };
@@ -30,7 +30,10 @@ pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
30} 30}
31 31
32fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) { 32fn complete_undotted_self(acc: &mut Completions, ctx: &CompletionContext) {
33 if !ctx.is_trivial_path || !ctx.config.enable_self_on_the_fly { 33 if !ctx.config.enable_self_on_the_fly {
34 return;
35 }
36 if !ctx.is_trivial_path || ctx.is_path_disallowed() {
34 return; 37 return;
35 } 38 }
36 ctx.scope.process_all_names(&mut |name, def| { 39 ctx.scope.process_all_names(&mut |name, def| {
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index df27e7a84..d72bf13d3 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -162,19 +162,19 @@ pub(crate) fn position_for_import<'a>(
162 Some(match import_candidate { 162 Some(match import_candidate {
163 Some(ImportCandidate::Path(_)) => ctx.name_ref_syntax.as_ref()?.syntax(), 163 Some(ImportCandidate::Path(_)) => ctx.name_ref_syntax.as_ref()?.syntax(),
164 Some(ImportCandidate::TraitAssocItem(_)) => ctx.path_qual.as_ref()?.syntax(), 164 Some(ImportCandidate::TraitAssocItem(_)) => ctx.path_qual.as_ref()?.syntax(),
165 Some(ImportCandidate::TraitMethod(_)) => ctx.dot_receiver.as_ref()?.syntax(), 165 Some(ImportCandidate::TraitMethod(_)) => ctx.dot_receiver()?.syntax(),
166 None => ctx 166 None => ctx
167 .name_ref_syntax 167 .name_ref_syntax
168 .as_ref() 168 .as_ref()
169 .map(|name_ref| name_ref.syntax()) 169 .map(|name_ref| name_ref.syntax())
170 .or_else(|| ctx.path_qual.as_ref().map(|path| path.syntax())) 170 .or_else(|| ctx.path_qual.as_ref().map(|path| path.syntax()))
171 .or_else(|| ctx.dot_receiver.as_ref().map(|expr| expr.syntax()))?, 171 .or_else(|| ctx.dot_receiver().map(|expr| expr.syntax()))?,
172 }) 172 })
173} 173}
174 174
175fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option<ImportAssets> { 175fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option<ImportAssets> {
176 let current_module = ctx.scope.module()?; 176 let current_module = ctx.scope.module()?;
177 if let Some(dot_receiver) = &ctx.dot_receiver { 177 if let Some(dot_receiver) = ctx.dot_receiver() {
178 ImportAssets::for_fuzzy_method_call( 178 ImportAssets::for_fuzzy_method_call(
179 current_module, 179 current_module,
180 ctx.sema.type_of_expr(dot_receiver)?, 180 ctx.sema.type_of_expr(dot_receiver)?,
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index 0d035c611..1a7a484a4 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -31,7 +31,7 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
31 } 31 }
32 32
33 // Suggest .await syntax for types that implement Future trait 33 // Suggest .await syntax for types that implement Future trait
34 if let Some(receiver) = &ctx.dot_receiver { 34 if let Some(receiver) = ctx.dot_receiver() {
35 if let Some(ty) = ctx.sema.type_of_expr(receiver) { 35 if let Some(ty) = ctx.sema.type_of_expr(receiver) {
36 if ty.impls_future(ctx.db) { 36 if ty.impls_future(ctx.db) {
37 let mut item = kw_completion("await"); 37 let mut item = kw_completion("await");
diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs
index 962aaf0df..86bbb58e2 100644
--- a/crates/ide_completion/src/completions/postfix.rs
+++ b/crates/ide_completion/src/completions/postfix.rs
@@ -14,6 +14,7 @@ use crate::{
14 completions::postfix::format_like::add_format_like_completions, 14 completions::postfix::format_like::add_format_like_completions,
15 context::CompletionContext, 15 context::CompletionContext,
16 item::{Builder, CompletionKind}, 16 item::{Builder, CompletionKind},
17 patterns::ImmediateLocation,
17 CompletionItem, CompletionItemKind, Completions, 18 CompletionItem, CompletionItemKind, Completions,
18}; 19};
19 20
@@ -22,13 +23,16 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
22 return; 23 return;
23 } 24 }
24 25
25 let dot_receiver = match &ctx.dot_receiver { 26 let (dot_receiver, receiver_is_ambiguous_float_literal) = match &ctx.completion_location {
26 Some(it) => it, 27 Some(ImmediateLocation::MethodCall { receiver: Some(it) }) => (it, false),
27 None => return, 28 Some(ImmediateLocation::FieldAccess {
29 receiver: Some(it),
30 receiver_is_ambiguous_float_literal,
31 }) => (it, *receiver_is_ambiguous_float_literal),
32 _ => return,
28 }; 33 };
29 34
30 let receiver_text = 35 let receiver_text = get_receiver_text(dot_receiver, receiver_is_ambiguous_float_literal);
31 get_receiver_text(dot_receiver, ctx.dot_receiver_is_ambiguous_float_literal);
32 36
33 let receiver_ty = match ctx.sema.type_of_expr(&dot_receiver) { 37 let receiver_ty = match ctx.sema.type_of_expr(&dot_receiver) {
34 Some(it) => it, 38 Some(it) => it,
@@ -123,8 +127,7 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
123 // The rest of the postfix completions create an expression that moves an argument, 127 // The rest of the postfix completions create an expression that moves an argument,
124 // so it's better to consider references now to avoid breaking the compilation 128 // so it's better to consider references now to avoid breaking the compilation
125 let dot_receiver = include_references(dot_receiver); 129 let dot_receiver = include_references(dot_receiver);
126 let receiver_text = 130 let receiver_text = get_receiver_text(&dot_receiver, receiver_is_ambiguous_float_literal);
127 get_receiver_text(&dot_receiver, ctx.dot_receiver_is_ambiguous_float_literal);
128 131
129 match try_enum { 132 match try_enum {
130 Some(try_enum) => match try_enum { 133 Some(try_enum) => match try_enum {