aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/completion_context.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_context.rs')
-rw-r--r--crates/ra_ide_api/src/completion/completion_context.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs
index e9ad06965..64cbc0f98 100644
--- a/crates/ra_ide_api/src/completion/completion_context.rs
+++ b/crates/ra_ide_api/src/completion/completion_context.rs
@@ -38,8 +38,11 @@ pub(crate) struct CompletionContext<'a> {
38 pub(super) is_new_item: bool, 38 pub(super) is_new_item: bool,
39 /// The receiver if this is a field or method access, i.e. writing something.<|> 39 /// The receiver if this is a field or method access, i.e. writing something.<|>
40 pub(super) dot_receiver: Option<ast::Expr>, 40 pub(super) dot_receiver: Option<ast::Expr>,
41 pub(super) dot_receiver_is_ambiguous_float_literal: bool,
41 /// If this is a call (method or function) in particular, i.e. the () are already there. 42 /// If this is a call (method or function) in particular, i.e. the () are already there.
42 pub(super) is_call: bool, 43 pub(super) is_call: bool,
44 pub(super) is_path_type: bool,
45 pub(super) has_type_args: bool,
43} 46}
44 47
45impl<'a> CompletionContext<'a> { 48impl<'a> CompletionContext<'a> {
@@ -76,6 +79,9 @@ impl<'a> CompletionContext<'a> {
76 is_new_item: false, 79 is_new_item: false,
77 dot_receiver: None, 80 dot_receiver: None,
78 is_call: false, 81 is_call: false,
82 is_path_type: false,
83 has_type_args: false,
84 dot_receiver_is_ambiguous_float_literal: false,
79 }; 85 };
80 ctx.fill(&original_parse, position.offset); 86 ctx.fill(&original_parse, position.offset);
81 Some(ctx) 87 Some(ctx)
@@ -176,6 +182,9 @@ impl<'a> CompletionContext<'a> {
176 .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast)) 182 .and_then(|it| it.syntax().parent().and_then(ast::CallExpr::cast))
177 .is_some(); 183 .is_some();
178 184
185 self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some();
186 self.has_type_args = segment.type_arg_list().is_some();
187
179 if let Some(mut path) = hir::Path::from_ast(path.clone()) { 188 if let Some(mut path) = hir::Path::from_ast(path.clone()) {
180 if !path.is_ident() { 189 if !path.is_ident() {
181 path.segments.pop().unwrap(); 190 path.segments.pop().unwrap();
@@ -228,6 +237,16 @@ impl<'a> CompletionContext<'a> {
228 .expr() 237 .expr()
229 .map(|e| e.syntax().text_range()) 238 .map(|e| e.syntax().text_range())
230 .and_then(|r| find_node_with_range(original_file.syntax(), r)); 239 .and_then(|r| find_node_with_range(original_file.syntax(), r));
240 self.dot_receiver_is_ambiguous_float_literal = if let Some(ast::Expr::Literal(l)) =
241 &self.dot_receiver
242 {
243 match l.kind() {
244 ast::LiteralKind::FloatNumber { suffix: _ } => l.token().text().ends_with('.'),
245 _ => false,
246 }
247 } else {
248 false
249 }
231 } 250 }
232 if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) { 251 if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) {
233 // As above 252 // As above