From 2a582b78a5f9c1fa908fe5f4c9ff4ab2966adb2e Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 8 Apr 2020 17:48:16 -0400 Subject: Add more heuristics for hiding obvious param hints This will now hide "value", "pat", "rhs" and "other" These words were selected from the std because they are used in common functions with only a single param and are obvious by their use. I think it would be good to also hide "bytes" if the type is `[u8; n]` but I'm not sure how to get the param type signature It will also hide the hint if the passed param starts or end with the param_name --- crates/ra_ide/src/inlay_hints.rs | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 4b133b19b..6a4fe15fd 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -1,4 +1,4 @@ -//! FIXME: write short doc here +//! This module defines multiple types of inlay hints and their visibility use hir::{Adt, HirDisplay, Semantics, Type}; use ra_ide_db::RootDatabase; @@ -236,7 +236,10 @@ fn should_show_param_hint( argument: &ast::Expr, ) -> bool { let argument_string = argument.syntax().to_string(); - if param_name.is_empty() || argument_string.ends_with(param_name) { + if param_name.is_empty() + || argument_string.ends_with(¶m_name) + || argument_string.starts_with(¶m_name) + { return false; } @@ -245,8 +248,15 @@ fn should_show_param_hint( } else { fn_signature.parameters.len() }; + // avoid displaying hints for common functions like map, filter, etc. - if parameters_len == 1 && (param_name.len() == 1 || param_name == "predicate") { + // or other obvious words used in std + // TODO ignore "bytes" if the type is [u8; n] + let is_obvious_param_name = match param_name { + "predicate" | "value" | "pat" | "rhs" | "other" => true, + _ => false, + }; + if parameters_len == 1 && (param_name.len() == 1 || is_obvious_param_name) { return false; } @@ -1059,9 +1069,17 @@ impl Test { self } + fn field(self, value: i32) -> Self { + self + } + fn no_hints_expected(&self, _: i32, test_var: i32) {} } +struct Param {} + +fn different_order(param: Param) {} + fn main() { let container: TestVarContainer = TestVarContainer { test_var: 42 }; let test: Test = Test {}; @@ -1069,11 +1087,19 @@ fn main() { map(22); filter(33); - let test_processed: Test = test.map(1).filter(2); + let test_processed: Test = test.map(1).filter(2).field(3); let test_var: i32 = 55; test_processed.no_hints_expected(22, test_var); test_processed.no_hints_expected(33, container.test_var); + + let param_begin: Param = Param {}; + different_order(param_begin); + + let a: f64 = 7.0; + let b: f64 = 4.0; + let _: f64 = a.div_euclid(b); + let _: f64 = a.abs_sub(b); }"#, ); -- cgit v1.2.3 From a2dc18f71acf83dd2946622603d3da00b456d42a Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 8 Apr 2020 18:11:24 -0400 Subject: remove TODO --- crates/ra_ide/src/inlay_hints.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 6a4fe15fd..a86e18fbb 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -251,7 +251,6 @@ fn should_show_param_hint( // avoid displaying hints for common functions like map, filter, etc. // or other obvious words used in std - // TODO ignore "bytes" if the type is [u8; n] let is_obvious_param_name = match param_name { "predicate" | "value" | "pat" | "rhs" | "other" => true, _ => false, -- cgit v1.2.3 From de6db0632228ae61f7ec1f87eaf520ccd4e46925 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 8 Apr 2020 19:07:21 -0400 Subject: ignore `&mut ` and `&` when checking params --- crates/ra_ide/src/inlay_hints.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index a86e18fbb..6b8b5813d 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -235,7 +235,15 @@ fn should_show_param_hint( param_name: &str, argument: &ast::Expr, ) -> bool { - let argument_string = argument.syntax().to_string(); + let argument_string = { + let arg_string = argument.syntax().to_string(); + let arg_split: Vec = arg_string.chars().collect(); + match arg_split.as_slice() { + ['&', 'm', 'u', 't', ' ', arg_name @ ..] => arg_name.into_iter().collect::(), + ['&', arg_name @ ..] => arg_name.into_iter().collect::(), + _ => arg_string, + } + }; if param_name.is_empty() || argument_string.ends_with(¶m_name) || argument_string.starts_with(¶m_name) @@ -1077,7 +1085,8 @@ impl Test { struct Param {} -fn different_order(param: Param) {} +fn different_order(param: &Param) {} +fn different_order_mut(param: &mut Param) {} fn main() { let container: TestVarContainer = TestVarContainer { test_var: 42 }; @@ -1093,7 +1102,8 @@ fn main() { test_processed.no_hints_expected(33, container.test_var); let param_begin: Param = Param {}; - different_order(param_begin); + different_order(¶m_begin); + different_order(&mut param_begin); let a: f64 = 7.0; let b: f64 = 4.0; -- cgit v1.2.3 From cba694c60276f7543ee9ed1dddf3fe93209f527f Mon Sep 17 00:00:00 2001 From: IceSentry Date: Wed, 8 Apr 2020 19:26:47 -0400 Subject: better `&mut ` and `&` matching --- crates/ra_ide/src/inlay_hints.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 6b8b5813d..1da61e4c4 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -236,13 +236,13 @@ fn should_show_param_hint( argument: &ast::Expr, ) -> bool { let argument_string = { - let arg_string = argument.syntax().to_string(); - let arg_split: Vec = arg_string.chars().collect(); - match arg_split.as_slice() { - ['&', 'm', 'u', 't', ' ', arg_name @ ..] => arg_name.into_iter().collect::(), - ['&', arg_name @ ..] => arg_name.into_iter().collect::(), - _ => arg_string, + let mut arg_string = argument.syntax().to_string(); + if arg_string.get(0..5) == Some("&mut ") { + arg_string = arg_string[5..].to_string(); + } else if arg_string.get(0..1) == Some("&") { + arg_string = arg_string[1..].to_string(); } + arg_string }; if param_name.is_empty() || argument_string.ends_with(¶m_name) -- cgit v1.2.3 From ae416f3c6e90a8d2b2f9d1713d2db4ddce12df65 Mon Sep 17 00:00:00 2001 From: IceSentry Date: Thu, 9 Apr 2020 10:35:07 -0400 Subject: clean up param hint checking --- crates/ra_ide/src/inlay_hints.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 1da61e4c4..b1661d238 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -235,19 +235,7 @@ fn should_show_param_hint( param_name: &str, argument: &ast::Expr, ) -> bool { - let argument_string = { - let mut arg_string = argument.syntax().to_string(); - if arg_string.get(0..5) == Some("&mut ") { - arg_string = arg_string[5..].to_string(); - } else if arg_string.get(0..1) == Some("&") { - arg_string = arg_string[1..].to_string(); - } - arg_string - }; - if param_name.is_empty() - || argument_string.ends_with(¶m_name) - || argument_string.starts_with(¶m_name) - { + if param_name.is_empty() || is_argument_similar_to_param(argument, param_name) { return false; } @@ -259,15 +247,27 @@ fn should_show_param_hint( // avoid displaying hints for common functions like map, filter, etc. // or other obvious words used in std + if parameters_len == 1 && is_obvious_param(param_name) { + return false; + } + true +} + +fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool { + let argument_string = if let ast::Expr::RefExpr(ref_expr) = argument { + ref_expr.syntax().last_token().expect("RefExpr should have a last_token").to_string() + } else { + argument.syntax().to_string() + }; + argument_string.starts_with(¶m_name) || argument_string.ends_with(¶m_name) +} + +fn is_obvious_param(param_name: &str) -> bool { let is_obvious_param_name = match param_name { "predicate" | "value" | "pat" | "rhs" | "other" => true, _ => false, }; - if parameters_len == 1 && (param_name.len() == 1 || is_obvious_param_name) { - return false; - } - - true + param_name.len() == 1 || is_obvious_param_name } fn get_fn_signature(sema: &Semantics, expr: &ast::Expr) -> Option { -- cgit v1.2.3 From ebc61709c86a9bfceafecc0b6ed9cc4f4624e0fe Mon Sep 17 00:00:00 2001 From: IceSentry Date: Thu, 9 Apr 2020 12:26:49 -0400 Subject: use .expr() to remove ref --- crates/ra_ide/src/inlay_hints.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index b1661d238..da9f55a69 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -254,14 +254,19 @@ fn should_show_param_hint( } fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool { - let argument_string = if let ast::Expr::RefExpr(ref_expr) = argument { - ref_expr.syntax().last_token().expect("RefExpr should have a last_token").to_string() - } else { - argument.syntax().to_string() - }; + let argument_string = remove_ref(argument.clone()).syntax().to_string(); argument_string.starts_with(¶m_name) || argument_string.ends_with(¶m_name) } +fn remove_ref(expr: ast::Expr) -> ast::Expr { + if let ast::Expr::RefExpr(ref_expr) = &expr { + if let Some(inner) = ref_expr.expr() { + return inner; + } + } + expr +} + fn is_obvious_param(param_name: &str) -> bool { let is_obvious_param_name = match param_name { "predicate" | "value" | "pat" | "rhs" | "other" => true, -- cgit v1.2.3 From 2bfb65db93e48d8f9e8ecac0b2ea837c081a4db5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 18:40:43 +0200 Subject: Be consistent about token accesors --- crates/ra_ide/src/completion/completion_context.rs | 5 ++++- crates/ra_ide/src/references.rs | 2 +- crates/ra_ide/src/typing.rs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index f833d2a9a..0e34d85db 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -190,7 +190,10 @@ impl<'a> CompletionContext<'a> { if let Some(name) = find_node_at_offset::(&file_with_fake_ident, offset) { if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { self.is_pat_binding_or_const = true; - if bind_pat.has_at() || bind_pat.is_ref() || bind_pat.is_mutable() { + if bind_pat.at_token().is_some() + || bind_pat.ref_kw_token().is_some() + || bind_pat.mut_kw_token().is_some() + { self.is_pat_binding_or_const = false; } if bind_pat.syntax().parent().and_then(ast::RecordFieldPatList::cast).is_some() { diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 746cc86ba..ad6fd50aa 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -152,7 +152,7 @@ fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Optio if stmt.initializer().is_some() { let pat = stmt.pat()?; if let ast::Pat::BindPat(it) = pat { - if it.is_mutable() { + if it.mut_kw_token().is_some() { return Some(ReferenceAccess::Write); } } diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index cb2cd2479..71d2bcb04 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs @@ -63,7 +63,7 @@ fn on_char_typed_inner( fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option { assert_eq!(file.syntax().text().char_at(offset), Some('=')); let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; - if let_stmt.has_semi() { + if let_stmt.semi_token().is_some() { return None; } if let Some(expr) = let_stmt.initializer() { -- cgit v1.2.3 From 81aab500c677420e4911371e13876faaf211219c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Thu, 9 Apr 2020 13:47:48 +0300 Subject: Hide parameter hints for single-argument functions with the same name --- crates/ra_ide/src/inlay_hints.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index da9f55a69..45b9f7802 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -235,7 +235,10 @@ fn should_show_param_hint( param_name: &str, argument: &ast::Expr, ) -> bool { - if param_name.is_empty() || is_argument_similar_to_param(argument, param_name) { + if param_name.is_empty() + || is_argument_similar_to_param(argument, param_name) + || Some(param_name) == fn_signature.name.as_ref().map(String::as_str) + { return false; } @@ -247,10 +250,7 @@ fn should_show_param_hint( // avoid displaying hints for common functions like map, filter, etc. // or other obvious words used in std - if parameters_len == 1 && is_obvious_param(param_name) { - return false; - } - true + parameters_len != 1 || !is_obvious_param(param_name) } fn is_argument_similar_to_param(argument: &ast::Expr, param_name: &str) -> bool { @@ -1086,6 +1086,8 @@ impl Test { } fn no_hints_expected(&self, _: i32, test_var: i32) {} + + fn frob(&self, frob: bool) {} } struct Param {} @@ -1093,6 +1095,8 @@ struct Param {} fn different_order(param: &Param) {} fn different_order_mut(param: &mut Param) {} +fn twiddle(twiddle: bool) {} + fn main() { let container: TestVarContainer = TestVarContainer { test_var: 42 }; let test: Test = Test {}; @@ -1105,6 +1109,9 @@ fn main() { let test_var: i32 = 55; test_processed.no_hints_expected(22, test_var); test_processed.no_hints_expected(33, container.test_var); + test_processed.frob(false); + + twiddle(true); let param_begin: Param = Param {}; different_order(¶m_begin); -- cgit v1.2.3 From 0ed27c388adca887cda3d8141efaf974e90a5958 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 23:02:10 +0200 Subject: Drop needless trait --- crates/ra_ide/src/completion/complete_fn_param.rs | 30 ++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index 62ae5ccb4..f84b559fc 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs @@ -1,6 +1,9 @@ //! FIXME: write short doc here -use ra_syntax::{ast, match_ast, AstNode}; +use ra_syntax::{ + ast::{self, ModuleItemOwner}, + match_ast, AstNode, +}; use rustc_hash::FxHashMap; use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; @@ -16,11 +19,19 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) let mut params = FxHashMap::default(); for node in ctx.token.parent().ancestors() { - match_ast! { + let items = match_ast! { match node { - ast::SourceFile(it) => process(it, &mut params), - ast::ItemList(it) => process(it, &mut params), - _ => (), + ast::SourceFile(it) => it.items(), + ast::ItemList(it) => it.items(), + _ => continue, + } + }; + for item in items { + if let ast::ModuleItem::FnDef(func) = item { + func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| { + let text = param.syntax().text().to_string(); + params.entry(text).or_insert((0, param)).0 += 1; + }) } } } @@ -39,15 +50,6 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) .lookup_by(lookup) .add_to(acc) }); - - fn process(node: N, params: &mut FxHashMap) { - node.functions().filter_map(|it| it.param_list()).flat_map(|it| it.params()).for_each( - |param| { - let text = param.syntax().text().to_string(); - params.entry(text).or_insert((0, param)).0 += 1; - }, - ) - } } #[cfg(test)] -- cgit v1.2.3 From 30084a56a5731343bd4cec727646a6c55900234f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 23:35:05 +0200 Subject: Simpler acessors for keywords --- crates/ra_ide/src/completion/completion_context.rs | 4 ++-- crates/ra_ide/src/references.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 0e34d85db..6637afaf7 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -191,8 +191,8 @@ impl<'a> CompletionContext<'a> { if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::BindPat::cast) { self.is_pat_binding_or_const = true; if bind_pat.at_token().is_some() - || bind_pat.ref_kw_token().is_some() - || bind_pat.mut_kw_token().is_some() + || bind_pat.ref_token().is_some() + || bind_pat.mut_token().is_some() { self.is_pat_binding_or_const = false; } diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index ad6fd50aa..7d0544ff4 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -152,7 +152,7 @@ fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Optio if stmt.initializer().is_some() { let pat = stmt.pat()?; if let ast::Pat::BindPat(it) = pat { - if it.mut_kw_token().is_some() { + if it.mut_token().is_some() { return Some(ReferenceAccess::Write); } } -- cgit v1.2.3 From c8b4c36f8161d34c8145a49965efee4514275989 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Apr 2020 10:11:05 +0200 Subject: Semicolon token --- crates/ra_ide/src/typing.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index 71d2bcb04..f55cd3bf5 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs @@ -63,7 +63,7 @@ fn on_char_typed_inner( fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option { assert_eq!(file.syntax().text().char_at(offset), Some('=')); let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; - if let_stmt.semi_token().is_some() { + if let_stmt.semicolon_token().is_some() { return None; } if let Some(expr) = let_stmt.initializer() { -- cgit v1.2.3 From 5c5bde47fb759440d007c90fd83021de538120b8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Apr 2020 17:06:57 +0200 Subject: Rename some tokens --- crates/ra_ide/src/completion/complete_trait_impl.rs | 4 ++-- crates/ra_ide/src/syntax_tree.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index ded1ff3bc..fab02945c 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -35,7 +35,7 @@ use hir::{self, Docs, HasSource}; use ra_assists::utils::get_missing_impl_items; use ra_syntax::{ ast::{self, edit, ImplDef}, - AstNode, SyntaxKind, SyntaxNode, TextRange, + AstNode, SyntaxKind, SyntaxNode, TextRange, T, }; use ra_text_edit::TextEdit; @@ -204,7 +204,7 @@ fn make_const_compl_syntax(const_: &ast::ConstDef) -> String { let end = const_ .syntax() .children_with_tokens() - .find(|s| s.kind() == SyntaxKind::SEMI || s.kind() == SyntaxKind::EQ) + .find(|s| s.kind() == T![;] || s.kind() == T![=]) .map_or(const_end, |f| f.text_range().start()); let len = end - start; diff --git a/crates/ra_ide/src/syntax_tree.rs b/crates/ra_ide/src/syntax_tree.rs index f58e436d1..5842ae2e8 100644 --- a/crates/ra_ide/src/syntax_tree.rs +++ b/crates/ra_ide/src/syntax_tree.rs @@ -165,7 +165,7 @@ SOURCE_FILE@[0; 60) PATH_SEGMENT@[16; 22) NAME_REF@[16; 22) IDENT@[16; 22) "assert" - EXCL@[22; 23) "!" + BANG@[22; 23) "!" TOKEN_TREE@[23; 57) L_PAREN@[23; 24) "(" STRING@[24; 52) "\"\n fn foo() {\n ..." @@ -173,7 +173,7 @@ SOURCE_FILE@[0; 60) WHITESPACE@[53; 54) " " STRING@[54; 56) "\"\"" R_PAREN@[56; 57) ")" - SEMI@[57; 58) ";" + SEMICOLON@[57; 58) ";" WHITESPACE@[58; 59) "\n" R_CURLY@[59; 60) "}" "# @@ -226,7 +226,7 @@ EXPR_STMT@[16; 58) PATH_SEGMENT@[16; 22) NAME_REF@[16; 22) IDENT@[16; 22) "assert" - EXCL@[22; 23) "!" + BANG@[22; 23) "!" TOKEN_TREE@[23; 57) L_PAREN@[23; 24) "(" STRING@[24; 52) "\"\n fn foo() {\n ..." @@ -234,7 +234,7 @@ EXPR_STMT@[16; 58) WHITESPACE@[53; 54) " " STRING@[54; 56) "\"\"" R_PAREN@[56; 57) ")" - SEMI@[57; 58) ";" + SEMICOLON@[57; 58) ";" "# .trim() ); -- cgit v1.2.3 From 7a39bc3ba29351feabcd4a16e12568a9e12818ca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 16:42:24 +0200 Subject: Make records grammar more orthogonal We used name [: expr] grammar before, now it is [name :] expr which makes things simpler --- crates/ra_ide/src/completion/complete_unqualified_path.rs | 2 +- crates/ra_ide/src/completion/completion_context.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index efde9bf73..0b0da6ee4 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs @@ -3,7 +3,7 @@ use crate::completion::{CompletionContext, Completions}; pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { - if !(ctx.is_trivial_path && !ctx.is_pat_binding_or_const) { + if !(ctx.is_trivial_path && !ctx.is_pat_binding_or_const && !ctx.record_lit_syntax.is_some()) { return; } diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 6637afaf7..14a4a14d7 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -227,7 +227,7 @@ impl<'a> CompletionContext<'a> { self.name_ref_syntax = find_node_at_offset(&original_file, name_ref.syntax().text_range().start()); let name_range = name_ref.syntax().text_range(); - if name_ref.syntax().parent().and_then(ast::RecordField::cast).is_some() { + if ast::RecordField::for_field_name(&name_ref).is_some() { self.record_lit_syntax = self.sema.find_node_at_offset_with_macros(&original_file, offset); } -- cgit v1.2.3