From bb1ae85ed0bdd854029435ac5a9f175e3f33e2e7 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 29 Jul 2020 00:37:34 +0300 Subject: Allow running more tests at once --- crates/ra_ide/src/runnables.rs | 164 +++++++++++++++++++++++++++-------------- 1 file changed, 110 insertions(+), 54 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 95a35a28d..45e0a7d85 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -220,15 +220,7 @@ fn runnable_mod( module: ast::Module, file_id: FileId, ) -> Option { - let has_test_function = module - .item_list()? - .items() - .filter_map(|it| match it { - ast::ModuleItem::FnDef(it) => Some(it), - _ => None, - }) - .any(|f| has_test_related_attribute(&f)); - if !has_test_function { + if !has_test_function_or_multiple_test_submodules(&module) { return None; } let module_def = sema.to_def(&module)?; @@ -246,6 +238,34 @@ fn runnable_mod( Some(Runnable { nav, kind: RunnableKind::TestMod { path }, cfg_exprs }) } +// We could create runnables for modules with number_of_test_submodules > 0, +// but that bloats the runnables for no real benefit, since all tests can be run by the submodule already +fn has_test_function_or_multiple_test_submodules(module: &ast::Module) -> bool { + if let Some(item_list) = module.item_list() { + let mut number_of_test_submodules = 0; + + for item in item_list.items() { + match item { + ast::ModuleItem::FnDef(f) => { + if has_test_related_attribute(&f) { + return true; + } + } + ast::ModuleItem::Module(submodule) => { + if has_test_function_or_multiple_test_submodules(&submodule) { + number_of_test_submodules += 1; + } + } + _ => (), + } + } + + number_of_test_submodules > 1 + } else { + false + } +} + #[cfg(test)] mod tests { use expect::{expect, Expect}; @@ -571,19 +591,33 @@ mod test_mod { } #[test] - fn test_runnables_one_depth_layer_module() { + fn only_modules_with_test_functions_or_more_than_one_test_submodule_have_runners() { check( r#" //- /lib.rs <|> -mod foo { - mod test_mod { - #[test] - fn test_foo1() {} +mod root_tests { + mod nested_tests_0 { + mod nested_tests_1 { + #[test] + fn nested_test_11() {} + + #[test] + fn nested_test_12() {} + } + + mod nested_tests_2 { + #[test] + fn nested_test_2() {} + } + + mod nested_tests_3 {} } + + mod nested_tests_4 {} } "#, - &[&TEST, &TEST], + &[&TEST, &TEST, &TEST, &TEST, &TEST, &TEST], expect![[r#" [ Runnable { @@ -591,18 +625,18 @@ mod foo { file_id: FileId( 1, ), - full_range: 15..77, + full_range: 22..323, focus_range: Some( - 19..27, + 26..40, ), - name: "test_mod", + name: "nested_tests_0", kind: MODULE, container_name: None, description: None, docs: None, }, kind: TestMod { - path: "foo::test_mod", + path: "root_tests::nested_tests_0", }, cfg_exprs: [], }, @@ -611,11 +645,31 @@ mod foo { file_id: FileId( 1, ), - full_range: 38..71, + full_range: 51..192, focus_range: Some( - 57..66, + 55..69, ), - name: "test_foo1", + name: "nested_tests_1", + kind: MODULE, + container_name: None, + description: None, + docs: None, + }, + kind: TestMod { + path: "root_tests::nested_tests_0::nested_tests_1", + }, + cfg_exprs: [], + }, + Runnable { + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 84..126, + focus_range: Some( + 107..121, + ), + name: "nested_test_11", kind: FN_DEF, container_name: None, description: None, @@ -623,7 +677,7 @@ mod foo { }, kind: Test { test_id: Path( - "foo::test_mod::test_foo1", + "root_tests::nested_tests_0::nested_tests_1::nested_test_11", ), attr: TestAttr { ignore: false, @@ -631,46 +685,48 @@ mod foo { }, cfg_exprs: [], }, - ] - "#]], - ); - } - - #[test] - fn test_runnables_multiple_depth_module() { - check( - r#" -//- /lib.rs -<|> -mod foo { - mod bar { - mod test_mod { - #[test] - fn test_foo1() {} - } - } -} -"#, - &[&TEST, &TEST], - expect![[r#" - [ Runnable { nav: NavigationTarget { file_id: FileId( 1, ), - full_range: 33..107, + full_range: 140..182, focus_range: Some( - 37..45, + 163..177, ), - name: "test_mod", + name: "nested_test_12", + kind: FN_DEF, + container_name: None, + description: None, + docs: None, + }, + kind: Test { + test_id: Path( + "root_tests::nested_tests_0::nested_tests_1::nested_test_12", + ), + attr: TestAttr { + ignore: false, + }, + }, + cfg_exprs: [], + }, + Runnable { + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 202..286, + focus_range: Some( + 206..220, + ), + name: "nested_tests_2", kind: MODULE, container_name: None, description: None, docs: None, }, kind: TestMod { - path: "foo::bar::test_mod", + path: "root_tests::nested_tests_0::nested_tests_2", }, cfg_exprs: [], }, @@ -679,11 +735,11 @@ mod foo { file_id: FileId( 1, ), - full_range: 60..97, + full_range: 235..276, focus_range: Some( - 83..92, + 258..271, ), - name: "test_foo1", + name: "nested_test_2", kind: FN_DEF, container_name: None, description: None, @@ -691,7 +747,7 @@ mod foo { }, kind: Test { test_id: Path( - "foo::bar::test_mod::test_foo1", + "root_tests::nested_tests_0::nested_tests_2::nested_test_2", ), attr: TestAttr { ignore: false, -- cgit v1.2.3 From cf55806257776baf7db6b02d260bdaa9e851c7d4 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Wed, 29 Jul 2020 11:44:01 +1000 Subject: SSR: Restrict to current selection if any The selection is also used to avoid unnecessary work, but only to the file level. Further restricting unnecessary work is left for later. --- crates/ra_ide/src/lib.rs | 3 ++- crates/ra_ide/src/ssr.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 4c4d9f6fa..0fede0d87 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -510,9 +510,10 @@ impl Analysis { query: &str, parse_only: bool, position: FilePosition, + selections: Vec, ) -> Cancelable> { self.with_db(|db| { - let edits = ssr::parse_search_replace(query, parse_only, db, position)?; + let edits = ssr::parse_search_replace(query, parse_only, db, position, selections)?; Ok(SourceChange::from(edits)) }) } diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 95d8f79b8..63010677a 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs @@ -1,4 +1,4 @@ -use ra_db::FilePosition; +use ra_db::{FilePosition, FileRange}; use ra_ide_db::RootDatabase; use crate::SourceFileEdit; @@ -24,6 +24,9 @@ use ra_ssr::{MatchFinder, SsrError, SsrRule}; // Method calls should generally be written in UFCS form. e.g. `foo::Bar::baz($s, $a)` will match // `$s.baz($a)`, provided the method call `baz` resolves to the method `foo::Bar::baz`. // +// The scope of the search / replace will be restricted to the current selection if any, otherwise +// it will apply to the whole workspace. +// // Placeholders may be given constraints by writing them as `${::...}`. // // Supported constraints: @@ -57,9 +60,10 @@ pub fn parse_search_replace( parse_only: bool, db: &RootDatabase, position: FilePosition, + selections: Vec, ) -> Result, SsrError> { let rule: SsrRule = rule.parse()?; - let mut match_finder = MatchFinder::in_context(db, position); + let mut match_finder = MatchFinder::in_context(db, position, selections); match_finder.add_rule(rule)?; if parse_only { return Ok(Vec::new()); -- cgit v1.2.3 From fcb6b166fbc506950dc2689adfa4d0b728d1a745 Mon Sep 17 00:00:00 2001 From: David Lattimore Date: Wed, 29 Jul 2020 19:20:40 +1000 Subject: SSR: Rename position and lookup_context to resolve_context --- crates/ra_ide/src/ssr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs index 63010677a..4348b43be 100644 --- a/crates/ra_ide/src/ssr.rs +++ b/crates/ra_ide/src/ssr.rs @@ -59,11 +59,11 @@ pub fn parse_search_replace( rule: &str, parse_only: bool, db: &RootDatabase, - position: FilePosition, + resolve_context: FilePosition, selections: Vec, ) -> Result, SsrError> { let rule: SsrRule = rule.parse()?; - let mut match_finder = MatchFinder::in_context(db, position, selections); + let mut match_finder = MatchFinder::in_context(db, resolve_context, selections); match_finder.add_rule(rule)?; if parse_only { return Ok(Vec::new()); -- cgit v1.2.3 From 76202a2c7371a6930db7b83af75c0f5a8ae1d061 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 29 Jul 2020 19:22:15 +0200 Subject: Rename NomialDef -> AdtDef --- crates/ra_ide/src/goto_implementation.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs index 3ee048f28..16a61d071 100644 --- a/crates/ra_ide/src/goto_implementation.rs +++ b/crates/ra_ide/src/goto_implementation.rs @@ -23,7 +23,7 @@ pub(crate) fn goto_implementation( let krate = sema.to_module_def(position.file_id)?.krate(); - if let Some(nominal_def) = find_node_at_offset::(&syntax, position.offset) { + if let Some(nominal_def) = find_node_at_offset::(&syntax, position.offset) { return Some(RangeInfo::new( nominal_def.syntax().text_range(), impls_for_def(&sema, &nominal_def, krate)?, @@ -40,13 +40,13 @@ pub(crate) fn goto_implementation( fn impls_for_def( sema: &Semantics, - node: &ast::NominalDef, + node: &ast::AdtDef, krate: Crate, ) -> Option> { let ty = match node { - ast::NominalDef::StructDef(def) => sema.to_def(def)?.ty(sema.db), - ast::NominalDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db), - ast::NominalDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db), + ast::AdtDef::StructDef(def) => sema.to_def(def)?.ty(sema.db), + ast::AdtDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db), + ast::AdtDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db), }; let impls = ImplDef::all_in_crate(sema.db, krate); -- cgit v1.2.3 From ba585309ec9ba6102038cd16c3fff107dfc1f56c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 29 Jul 2020 19:49:10 +0200 Subject: Replace rand with oorandom --- crates/ra_ide/Cargo.toml | 2 +- crates/ra_ide/src/syntax_highlighting/html.rs | 10 +++++----- crates/ra_ide/test_data/rainbow_highlighting.html | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index 6f8107491..f4181c4eb 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml @@ -17,7 +17,7 @@ indexmap = "1.3.2" itertools = "0.9.0" log = "0.4.8" rustc-hash = "1.1.0" -rand = { version = "0.7.3", features = ["small_rng"] } +oorandom = "11.1.2" stdx = { path = "../stdx" } diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs index 0be55bca9..a5e7d2867 100644 --- a/crates/ra_ide/src/syntax_highlighting/html.rs +++ b/crates/ra_ide/src/syntax_highlighting/html.rs @@ -1,5 +1,6 @@ //! Renders a bit of code as HTML. +use oorandom::Rand32; use ra_db::SourceDatabase; use ra_syntax::{AstNode, TextRange, TextSize}; @@ -9,13 +10,12 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo let parse = db.parse(file_id); fn rainbowify(seed: u64) -> String { - use rand::prelude::*; - let mut rng = SmallRng::seed_from_u64(seed); + let mut rng = Rand32::new(seed); format!( "hsl({h},{s}%,{l}%)", - h = rng.gen_range::(0, 361), - s = rng.gen_range::(42, 99), - l = rng.gen_range::(40, 91), + h = rng.rand_range(0..361), + s = rng.rand_range(42..99), + l = rng.rand_range(40..91), ) } diff --git a/crates/ra_ide/test_data/rainbow_highlighting.html b/crates/ra_ide/test_data/rainbow_highlighting.html index 08d83302c..401e87a73 100644 --- a/crates/ra_ide/test_data/rainbow_highlighting.html +++ b/crates/ra_ide/test_data/rainbow_highlighting.html @@ -36,14 +36,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
fn main() {
-    let hello = "hello";
-    let x = hello.to_string();
-    let y = hello.to_string();
+    let hello = "hello";
+    let x = hello.to_string();
+    let y = hello.to_string();
 
-    let x = "other color please!";
-    let y = x.to_string();
+    let x = "other color please!";
+    let y = x.to_string();
 }
 
 fn bar() {
-    let mut hello = "hello";
+    let mut hello = "hello";
 }
\ No newline at end of file -- cgit v1.2.3 From 6636f56e79b55f22b88094b7edaed6ec88880500 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 00:23:03 +0200 Subject: Rename ModuleItem -> Item --- crates/ra_ide/src/completion/complete_fn_param.rs | 2 +- crates/ra_ide/src/runnables.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index db2abb4f1..7a53083f5 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs @@ -28,7 +28,7 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) } }; for item in items { - if let ast::ModuleItem::FnDef(func) = item { + if let ast::Item::FnDef(func) = item { if Some(&func) == me.as_ref() { continue; } diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 45e0a7d85..f612835c2 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -246,12 +246,12 @@ fn has_test_function_or_multiple_test_submodules(module: &ast::Module) -> bool { for item in item_list.items() { match item { - ast::ModuleItem::FnDef(f) => { + ast::Item::FnDef(f) => { if has_test_related_attribute(&f) { return true; } } - ast::ModuleItem::Module(submodule) => { + ast::Item::Module(submodule) => { if has_test_function_or_multiple_test_submodules(&submodule) { number_of_test_submodules += 1; } -- cgit v1.2.3 From 2984da672e0c73d56501c6b6e4d19fd28152b5eb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 11:42:51 +0200 Subject: Split ItemList & AssocItemList --- crates/ra_ide/src/completion/complete_fn_param.rs | 38 ++++++++++++++--------- crates/ra_ide/src/completion/complete_keyword.rs | 36 ++++++++++----------- crates/ra_ide/src/completion/patterns.rs | 6 ++-- 3 files changed, 43 insertions(+), 37 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index 7a53083f5..d4b6112a5 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs @@ -18,26 +18,36 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) } let mut params = FxHashMap::default(); + let me = ctx.token.ancestors().find_map(ast::FnDef::cast); + let mut process_fn = |func: ast::FnDef| { + if Some(&func) == me.as_ref() { + return; + } + 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(param); + }) + }; + for node in ctx.token.parent().ancestors() { - let items = match_ast! { + match_ast! { match node { - ast::SourceFile(it) => it.items(), - ast::ItemList(it) => it.items(), + ast::SourceFile(it) => it.items().filter_map(|item| match item { + ast::Item::FnDef(it) => Some(it), + _ => None, + }).for_each(&mut process_fn), + ast::ItemList(it) => it.items().filter_map(|item| match item { + ast::Item::FnDef(it) => Some(it), + _ => None, + }).for_each(&mut process_fn), + ast::AssocItemList(it) => it.assoc_items().filter_map(|item| match item { + ast::AssocItem::FnDef(it) => Some(it), + _ => None, + }).for_each(&mut process_fn), _ => continue, } }; - for item in items { - if let ast::Item::FnDef(func) = item { - if Some(&func) == me.as_ref() { - continue; - } - 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(param); - }) - } - } } params diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs index fcdaeef49..1581b2d5d 100644 --- a/crates/ra_ide/src/completion/complete_keyword.rs +++ b/crates/ra_ide/src/completion/complete_keyword.rs @@ -66,27 +66,24 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte add_keyword(ctx, acc, "fn", "fn $0() {}") } - if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) - || ctx.block_expr_parent - { + if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { add_keyword(ctx, acc, "trait", "trait $0 {}"); add_keyword(ctx, acc, "impl", "impl $0 {}"); } return; } - if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent { + if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent + { add_keyword(ctx, acc, "fn", "fn $0() {}"); } - if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) - || ctx.block_expr_parent - { + if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { add_keyword(ctx, acc, "use", "use "); add_keyword(ctx, acc, "impl", "impl $0 {}"); add_keyword(ctx, acc, "trait", "trait $0 {}"); } - if ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent { + if ctx.has_item_list_or_source_file_parent { add_keyword(ctx, acc, "enum", "enum $0 {}"); add_keyword(ctx, acc, "struct", "struct $0"); add_keyword(ctx, acc, "union", "union $0 {}"); @@ -108,29 +105,28 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte add_keyword(ctx, acc, "else", "else {$0}"); add_keyword(ctx, acc, "else if", "else if $0 {}"); } - if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) - || ctx.block_expr_parent - { + if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { add_keyword(ctx, acc, "mod", "mod $0 {}"); } if ctx.bind_pat_parent || ctx.ref_pat_parent { add_keyword(ctx, acc, "mut", "mut "); } - if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent { + if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent + { add_keyword(ctx, acc, "const", "const "); add_keyword(ctx, acc, "type", "type "); } - if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) - || ctx.block_expr_parent - { + if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { add_keyword(ctx, acc, "static", "static "); }; - if (ctx.has_item_list_or_source_file_parent && !has_trait_or_impl_parent) - || ctx.block_expr_parent - { + if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { add_keyword(ctx, acc, "extern", "extern "); } - if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent || ctx.is_match_arm { + if ctx.has_item_list_or_source_file_parent + || has_trait_or_impl_parent + || ctx.block_expr_parent + || ctx.is_match_arm + { add_keyword(ctx, acc, "unsafe", "unsafe "); } if ctx.in_loop_body { @@ -142,7 +138,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte add_keyword(ctx, acc, "break", "break"); } } - if ctx.has_item_list_or_source_file_parent && !ctx.has_trait_parent { + if ctx.has_item_list_or_source_file_parent || ctx.has_impl_parent { add_keyword(ctx, acc, "pub", "pub ") } diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index b2fe13280..175209d8a 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -13,7 +13,7 @@ use crate::completion::test_utils::check_pattern_is_applicable; pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool { not_same_range_ancestor(element) - .filter(|it| it.kind() == ITEM_LIST) + .filter(|it| it.kind() == ASSOC_ITEM_LIST) .and_then(|it| it.parent()) .filter(|it| it.kind() == TRAIT_DEF) .is_some() @@ -25,7 +25,7 @@ fn test_has_trait_parent() { pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool { not_same_range_ancestor(element) - .filter(|it| it.kind() == ITEM_LIST) + .filter(|it| it.kind() == ASSOC_ITEM_LIST) .and_then(|it| it.parent()) .filter(|it| it.kind() == IMPL_DEF) .is_some() @@ -73,7 +73,7 @@ pub(crate) fn has_item_list_or_source_file_parent(element: SyntaxElement) -> boo #[test] fn test_has_item_list_or_source_file_parent() { check_pattern_is_applicable(r"i<|>", has_item_list_or_source_file_parent); - check_pattern_is_applicable(r"impl { f<|> }", has_item_list_or_source_file_parent); + check_pattern_is_applicable(r"mod foo { f<|> }", has_item_list_or_source_file_parent); } pub(crate) fn is_match_arm(element: SyntaxElement) -> bool { -- cgit v1.2.3 From b1332670c7c471a59f3da113b366e74ac194c38b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:12:04 +0200 Subject: Rename UseItem -> Use --- crates/ra_ide/src/completion/completion_context.rs | 4 ++-- crates/ra_ide/src/folding_ranges.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index c84d43d77..cc55f6dd6 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -36,7 +36,7 @@ pub(crate) struct CompletionContext<'a> { pub(super) expected_type: Option, pub(super) name_ref_syntax: Option, pub(super) function_syntax: Option, - pub(super) use_item_syntax: Option, + pub(super) use_item_syntax: Option, pub(super) record_lit_syntax: Option, pub(super) record_pat_syntax: Option, pub(super) record_field_syntax: Option, @@ -343,7 +343,7 @@ impl<'a> CompletionContext<'a> { } self.use_item_syntax = - self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::UseItem::cast); + self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::Use::cast); self.function_syntax = self .sema diff --git a/crates/ra_ide/src/folding_ranges.rs b/crates/ra_ide/src/folding_ranges.rs index 315808890..bad079146 100644 --- a/crates/ra_ide/src/folding_ranges.rs +++ b/crates/ra_ide/src/folding_ranges.rs @@ -58,7 +58,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { } NodeOrToken::Node(node) => { // Fold groups of imports - if node.kind() == USE_ITEM && !visited_imports.contains(&node) { + if node.kind() == USE && !visited_imports.contains(&node) { if let Some(range) = contiguous_range_for_group(&node, &mut visited_imports) { res.push(Fold { range, kind: FoldKind::Imports }) } @@ -83,7 +83,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { fn fold_kind(kind: SyntaxKind) -> Option { match kind { COMMENT => Some(FoldKind::Comment), - USE_ITEM => Some(FoldKind::Imports), + USE => Some(FoldKind::Imports), ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList), RECORD_FIELD_DEF_LIST | RECORD_FIELD_PAT_LIST -- cgit v1.2.3 From 1142112c70b705f59b7d559d9d72cdc831865158 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:51:08 +0200 Subject: Rename FnDef -> Fn --- crates/ra_ide/src/call_hierarchy.rs | 54 +++++++++++----------- crates/ra_ide/src/completion/complete_fn_param.rs | 10 ++-- crates/ra_ide/src/completion/complete_keyword.rs | 2 +- .../ra_ide/src/completion/complete_trait_impl.rs | 6 +-- crates/ra_ide/src/completion/completion_context.rs | 4 +- crates/ra_ide/src/completion/patterns.rs | 2 +- crates/ra_ide/src/display.rs | 2 +- crates/ra_ide/src/display/navigation_target.rs | 4 +- crates/ra_ide/src/display/short_label.rs | 2 +- crates/ra_ide/src/file_structure.rs | 12 ++--- crates/ra_ide/src/hover.rs | 2 +- crates/ra_ide/src/references.rs | 10 ++-- crates/ra_ide/src/references/rename.rs | 4 +- crates/ra_ide/src/runnables.rs | 40 ++++++++-------- crates/ra_ide/src/syntax_highlighting.rs | 4 +- crates/ra_ide/src/syntax_tree.rs | 14 +++--- 16 files changed, 86 insertions(+), 86 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs index c28af8ab3..1fcaf4a32 100644 --- a/crates/ra_ide/src/call_hierarchy.rs +++ b/crates/ra_ide/src/call_hierarchy.rs @@ -59,7 +59,7 @@ pub(crate) fn incoming_calls(db: &RootDatabase, position: FilePosition) -> Optio if let Some(nav) = syntax.ancestors().find_map(|node| { match_ast! { match node { - ast::FnDef(it) => { + ast::Fn(it) => { let def = sema.to_def(&it)?; Some(def.to_nav(sema.db)) }, @@ -181,8 +181,8 @@ fn caller() { call<|>ee(); } "#, - "callee FN_DEF FileId(1) 0..14 3..9", - &["caller FN_DEF FileId(1) 15..44 18..24 : [33..39]"], + "callee FN FileId(1) 0..14 3..9", + &["caller FN FileId(1) 15..44 18..24 : [33..39]"], &[], ); } @@ -197,8 +197,8 @@ fn caller() { callee(); } "#, - "callee FN_DEF FileId(1) 0..14 3..9", - &["caller FN_DEF FileId(1) 15..44 18..24 : [33..39]"], + "callee FN FileId(1) 0..14 3..9", + &["caller FN FileId(1) 15..44 18..24 : [33..39]"], &[], ); } @@ -214,8 +214,8 @@ fn caller() { callee(); } "#, - "callee FN_DEF FileId(1) 0..14 3..9", - &["caller FN_DEF FileId(1) 15..58 18..24 : [33..39, 47..53]"], + "callee FN FileId(1) 0..14 3..9", + &["caller FN FileId(1) 15..58 18..24 : [33..39, 47..53]"], &[], ); } @@ -234,10 +234,10 @@ fn caller2() { callee(); } "#, - "callee FN_DEF FileId(1) 0..14 3..9", + "callee FN FileId(1) 0..14 3..9", &[ - "caller1 FN_DEF FileId(1) 15..45 18..25 : [34..40]", - "caller2 FN_DEF FileId(1) 47..77 50..57 : [66..72]", + "caller1 FN FileId(1) 15..45 18..25 : [34..40]", + "caller2 FN FileId(1) 47..77 50..57 : [66..72]", ], &[], ); @@ -263,10 +263,10 @@ mod tests { } } "#, - "callee FN_DEF FileId(1) 0..14 3..9", + "callee FN FileId(1) 0..14 3..9", &[ - "caller1 FN_DEF FileId(1) 15..45 18..25 : [34..40]", - "test_caller FN_DEF FileId(1) 95..149 110..121 : [134..140]", + "caller1 FN FileId(1) 15..45 18..25 : [34..40]", + "test_caller FN FileId(1) 95..149 110..121 : [134..140]", ], &[], ); @@ -287,8 +287,8 @@ fn caller() { //- /foo/mod.rs pub fn callee() {} "#, - "callee FN_DEF FileId(2) 0..18 7..13", - &["caller FN_DEF FileId(1) 27..56 30..36 : [45..51]"], + "callee FN FileId(2) 0..18 7..13", + &["caller FN FileId(1) 27..56 30..36 : [45..51]"], &[], ); } @@ -304,9 +304,9 @@ fn call<|>er() { callee(); } "#, - "caller FN_DEF FileId(1) 15..58 18..24", + "caller FN FileId(1) 15..58 18..24", &[], - &["callee FN_DEF FileId(1) 0..14 3..9 : [33..39, 47..53]"], + &["callee FN FileId(1) 0..14 3..9 : [33..39, 47..53]"], ); } @@ -325,9 +325,9 @@ fn call<|>er() { //- /foo/mod.rs pub fn callee() {} "#, - "caller FN_DEF FileId(1) 27..56 30..36", + "caller FN FileId(1) 27..56 30..36", &[], - &["callee FN_DEF FileId(2) 0..18 7..13 : [45..51]"], + &["callee FN FileId(2) 0..18 7..13 : [45..51]"], ); } @@ -348,9 +348,9 @@ fn caller3() { } "#, - "caller2 FN_DEF FileId(1) 33..64 36..43", - &["caller1 FN_DEF FileId(1) 0..31 3..10 : [19..26]"], - &["caller3 FN_DEF FileId(1) 66..83 69..76 : [52..59]"], + "caller2 FN FileId(1) 33..64 36..43", + &["caller1 FN FileId(1) 0..31 3..10 : [19..26]"], + &["caller3 FN FileId(1) 66..83 69..76 : [52..59]"], ); } @@ -368,9 +368,9 @@ fn main() { a<|>() } "#, - "a FN_DEF FileId(1) 0..18 3..4", - &["main FN_DEF FileId(1) 31..52 34..38 : [47..48]"], - &["b FN_DEF FileId(1) 20..29 23..24 : [13..14]"], + "a FN FileId(1) 0..18 3..4", + &["main FN FileId(1) 31..52 34..38 : [47..48]"], + &["b FN FileId(1) 20..29 23..24 : [13..14]"], ); check_hierarchy( @@ -385,8 +385,8 @@ fn main() { a() } "#, - "b FN_DEF FileId(1) 20..29 23..24", - &["a FN_DEF FileId(1) 0..18 3..4 : [13..14]"], + "b FN FileId(1) 20..29 23..24", + &["a FN FileId(1) 0..18 3..4 : [13..14]"], &[], ); } diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index d4b6112a5..406334257 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs @@ -19,8 +19,8 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) let mut params = FxHashMap::default(); - let me = ctx.token.ancestors().find_map(ast::FnDef::cast); - let mut process_fn = |func: ast::FnDef| { + let me = ctx.token.ancestors().find_map(ast::Fn::cast); + let mut process_fn = |func: ast::Fn| { if Some(&func) == me.as_ref() { return; } @@ -34,15 +34,15 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) match_ast! { match node { ast::SourceFile(it) => it.items().filter_map(|item| match item { - ast::Item::FnDef(it) => Some(it), + ast::Item::Fn(it) => Some(it), _ => None, }).for_each(&mut process_fn), ast::ItemList(it) => it.items().filter_map(|item| match item { - ast::Item::FnDef(it) => Some(it), + ast::Item::Fn(it) => Some(it), _ => None, }).for_each(&mut process_fn), ast::AssocItemList(it) => it.assoc_items().filter_map(|item| match item { - ast::AssocItem::FnDef(it) => Some(it), + ast::AssocItem::Fn(it) => Some(it), _ => None, }).for_each(&mut process_fn), _ => continue, diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs index 1581b2d5d..b62064797 100644 --- a/crates/ra_ide/src/completion/complete_keyword.rs +++ b/crates/ra_ide/src/completion/complete_keyword.rs @@ -169,7 +169,7 @@ fn add_keyword(ctx: &CompletionContext, acc: &mut Completions, kw: &str, snippet fn complete_return( ctx: &CompletionContext, - fn_def: &ast::FnDef, + fn_def: &ast::Fn, can_be_stmt: bool, ) -> Option { let snip = match (can_be_stmt, fn_def.ret_type().is_some()) { diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index cf716540f..dbb9eecc6 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -2,7 +2,7 @@ //! //! This module adds the completion items related to implementing associated //! items within a `impl Trait for Struct` block. The current context node -//! must be within either a `FN_DEF`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node +//! must be within either a `FN`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node //! and an direct child of an `IMPL_DEF`. //! //! # Examples @@ -63,7 +63,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext } }), - SyntaxKind::FN_DEF => { + SyntaxKind::FN => { for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) .into_iter() .filter_map(|item| match item { @@ -106,7 +106,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { - SyntaxKind::FN_DEF + SyntaxKind::FN | SyntaxKind::TYPE_ALIAS_DEF | SyntaxKind::CONST_DEF | SyntaxKind::BLOCK_EXPR => Some((p, 2)), diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index cc55f6dd6..221d7847e 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -35,7 +35,7 @@ pub(crate) struct CompletionContext<'a> { pub(super) krate: Option, pub(super) expected_type: Option, pub(super) name_ref_syntax: Option, - pub(super) function_syntax: Option, + pub(super) function_syntax: Option, pub(super) use_item_syntax: Option, pub(super) record_lit_syntax: Option, pub(super) record_pat_syntax: Option, @@ -349,7 +349,7 @@ impl<'a> CompletionContext<'a> { .sema .ancestors_with_macros(self.token.parent()) .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) - .find_map(ast::FnDef::cast); + .find_map(ast::Fn::cast); self.record_field_syntax = self .sema diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index 175209d8a..b8408da4e 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -134,7 +134,7 @@ pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { NodeOrToken::Token(token) => token.parent(), }; for node in leaf.ancestors() { - if node.kind() == FN_DEF || node.kind() == LAMBDA_EXPR { + if node.kind() == FN || node.kind() == LAMBDA_EXPR { break; } let loop_body = match_ast! { diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index 6d4151dd8..e4effc66c 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs @@ -16,7 +16,7 @@ pub use navigation_target::NavigationTarget; pub(crate) use navigation_target::{ToNav, TryToNav}; pub(crate) use short_label::ShortLabel; -pub(crate) fn function_declaration(node: &ast::FnDef) -> String { +pub(crate) fn function_declaration(node: &ast::Fn) -> String { let mut buf = String::new(); if let Some(vis) = node.visibility() { format_to!(buf, "{} ", vis); diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index fd245705c..222cb3502 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -379,7 +379,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option match_ast! { match node { - ast::FnDef(it) => it.doc_comment_text(), + ast::Fn(it) => it.doc_comment_text(), ast::StructDef(it) => it.doc_comment_text(), ast::EnumDef(it) => it.doc_comment_text(), ast::TraitDef(it) => it.doc_comment_text(), @@ -404,7 +404,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> match_ast! { match node { - ast::FnDef(it) => it.short_label(), + ast::Fn(it) => it.short_label(), ast::StructDef(it) => it.short_label(), ast::EnumDef(it) => it.short_label(), ast::TraitDef(it) => it.short_label(), diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 5588130a1..63863943a 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -7,7 +7,7 @@ pub(crate) trait ShortLabel { fn short_label(&self) -> Option; } -impl ShortLabel for ast::FnDef { +impl ShortLabel for ast::Fn { fn short_label(&self) -> Option { Some(crate::display::function_declaration(self)) } diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 1f6a3febf..41603480e 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -111,7 +111,7 @@ fn structure_node(node: &SyntaxNode) -> Option { match_ast! { match node { - ast::FnDef(it) => { + ast::Fn(it) => { let mut detail = String::from("fn"); if let Some(type_param_list) = it.type_param_list() { collapse_ws(type_param_list.syntax(), &mut detail); @@ -271,7 +271,7 @@ fn very_obsolete() {} label: "bar1", navigation_range: 43..47, node_range: 40..52, - kind: FN_DEF, + kind: FN, detail: Some( "fn()", ), @@ -284,7 +284,7 @@ fn very_obsolete() {} label: "bar2", navigation_range: 60..64, node_range: 57..81, - kind: FN_DEF, + kind: FN, detail: Some( "fn(t: T) -> T", ), @@ -297,7 +297,7 @@ fn very_obsolete() {} label: "bar3", navigation_range: 89..93, node_range: 86..156, - kind: FN_DEF, + kind: FN, detail: Some( "fn(a: A, b: B) -> Vec< u32 >", ), @@ -417,7 +417,7 @@ fn very_obsolete() {} label: "obsolete", navigation_range: 428..436, node_range: 411..441, - kind: FN_DEF, + kind: FN, detail: Some( "fn()", ), @@ -428,7 +428,7 @@ fn very_obsolete() {} label: "very_obsolete", navigation_range: 481..494, node_range: 443..499, - kind: FN_DEF, + kind: FN, detail: Some( "fn()", ), diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index d067c339d..4ef7efd26 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -1361,7 +1361,7 @@ fn foo_<|>test() {} 11..19, ), name: "foo_test", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index fe1c074d1..8d3452a83 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -376,7 +376,7 @@ impl Foo { } "#, ); - check_result(refs, "f FN_DEF FileId(1) 27..43 30..31 Other", &[]); + check_result(refs, "f FN FileId(1) 27..43 30..31 Other", &[]); } #[test] @@ -514,7 +514,7 @@ pub(super) struct Foo<|> { let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); check_result( refs, - "quux FN_DEF FileId(1) 19..35 26..30 Other", + "quux FN FileId(1) 19..35 26..30 Other", &["FileId(2) 16..20 StructLiteral", "FileId(3) 16..20 StructLiteral"], ); @@ -522,7 +522,7 @@ pub(super) struct Foo<|> { analysis.find_all_refs(pos, Some(SearchScope::single_file(bar))).unwrap().unwrap(); check_result( refs, - "quux FN_DEF FileId(1) 19..35 26..30 Other", + "quux FN FileId(1) 19..35 26..30 Other", &["FileId(3) 16..20 StructLiteral"], ); } @@ -619,7 +619,7 @@ fn main() { ); check_result( refs, - "new FN_DEF FileId(1) 54..101 61..64 Other", + "new FN FileId(1) 54..101 61..64 Other", &["FileId(1) 146..149 StructLiteral"], ); } @@ -646,7 +646,7 @@ fn main() { let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); check_result( refs, - "f FN_DEF FileId(1) 26..35 29..30 Other", + "f FN FileId(1) 26..35 29..30 Other", &["FileId(2) 11..12 Other", "FileId(2) 28..29 StructLiteral"], ); } diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 8735ec53c..d8ffb8c84 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -149,7 +149,7 @@ fn rename_to_self( let source_file = sema.parse(position.file_id); let syn = source_file.syntax(); - let fn_def = find_node_at_offset::(syn, position.offset)?; + let fn_def = find_node_at_offset::(syn, position.offset)?; let params = fn_def.param_list()?; if params.self_param().is_some() { return None; // method already has self param @@ -221,7 +221,7 @@ fn rename_self_to_param( let syn = source_file.syntax(); let text = sema.db.file_text(position.file_id); - let fn_def = find_node_at_offset::(syn, position.offset)?; + let fn_def = find_node_at_offset::(syn, position.offset)?; let search_range = fn_def.syntax().text_range(); let mut edits: Vec = vec![]; diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index f612835c2..3b7162b84 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -102,7 +102,7 @@ pub(crate) fn runnable( ) -> Option { match_ast! { match item { - ast::FnDef(it) => runnable_fn(sema, it, file_id), + ast::Fn(it) => runnable_fn(sema, it, file_id), ast::Module(it) => runnable_mod(sema, it, file_id), _ => None, } @@ -111,7 +111,7 @@ pub(crate) fn runnable( fn runnable_fn( sema: &Semantics, - fn_def: ast::FnDef, + fn_def: ast::Fn, file_id: FileId, ) -> Option { let name_string = fn_def.name()?.text().to_string(); @@ -188,7 +188,7 @@ pub struct TestAttr { } impl TestAttr { - fn from_fn(fn_def: &ast::FnDef) -> TestAttr { + fn from_fn(fn_def: &ast::Fn) -> TestAttr { let ignore = fn_def .attrs() .filter_map(|attr| attr.simple_name()) @@ -203,7 +203,7 @@ impl TestAttr { /// /// It may produce false positives, for example, `#[wasm_bindgen_test]` requires a different command to run the test, /// but it's better than not to have the runnables for the tests at all. -fn has_test_related_attribute(fn_def: &ast::FnDef) -> bool { +fn has_test_related_attribute(fn_def: &ast::Fn) -> bool { fn_def .attrs() .filter_map(|attr| attr.path()) @@ -211,7 +211,7 @@ fn has_test_related_attribute(fn_def: &ast::FnDef) -> bool { .any(|attribute_text| attribute_text.contains("test")) } -fn has_doc_test(fn_def: &ast::FnDef) -> bool { +fn has_doc_test(fn_def: &ast::Fn) -> bool { fn_def.doc_comment_text().map_or(false, |comment| comment.contains("```")) } @@ -246,7 +246,7 @@ fn has_test_function_or_multiple_test_submodules(module: &ast::Module) -> bool { for item in item_list.items() { match item { - ast::Item::FnDef(f) => { + ast::Item::Fn(f) => { if has_test_related_attribute(&f) { return true; } @@ -320,7 +320,7 @@ fn bench() {} 4..8, ), name: "main", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -338,7 +338,7 @@ fn bench() {} 26..34, ), name: "test_foo", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -363,7 +363,7 @@ fn bench() {} 62..70, ), name: "test_foo", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -388,7 +388,7 @@ fn bench() {} 89..94, ), name: "bench", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -431,7 +431,7 @@ fn foo() {} 4..8, ), name: "main", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -447,7 +447,7 @@ fn foo() {} full_range: 15..57, focus_range: None, name: "foo", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -493,7 +493,7 @@ impl Data { 4..8, ), name: "main", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -509,7 +509,7 @@ impl Data { full_range: 44..98, focus_range: None, name: "foo", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -570,7 +570,7 @@ mod test_mod { 35..44, ), name: "test_foo1", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -670,7 +670,7 @@ mod root_tests { 107..121, ), name: "nested_test_11", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -695,7 +695,7 @@ mod root_tests { 163..177, ), name: "nested_test_12", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -740,7 +740,7 @@ mod root_tests { 258..271, ), name: "nested_test_2", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -783,7 +783,7 @@ fn test_foo1() {} 36..45, ), name: "test_foo1", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, @@ -831,7 +831,7 @@ fn test_foo1() {} 58..67, ), name: "test_foo1", - kind: FN_DEF, + kind: FN, container_name: None, description: None, docs: None, diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index d456d5d36..5198727d9 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -464,7 +464,7 @@ fn highlight_element( let db = sema.db; let mut binding_hash = None; let highlight: Highlight = match element.kind() { - FN_DEF => { + FN => { bindings_shadow_count.clear(); return None; } @@ -713,7 +713,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { TYPE_PARAM => HighlightTag::TypeParam, RECORD_FIELD_DEF => HighlightTag::Field, MODULE => HighlightTag::Module, - FN_DEF => HighlightTag::Function, + FN => HighlightTag::Function, CONST_DEF => HighlightTag::Constant, STATIC_DEF => HighlightTag::Static, ENUM_VARIANT => HighlightTag::EnumVariant, diff --git a/crates/ra_ide/src/syntax_tree.rs b/crates/ra_ide/src/syntax_tree.rs index f716a3861..07217e808 100644 --- a/crates/ra_ide/src/syntax_tree.rs +++ b/crates/ra_ide/src/syntax_tree.rs @@ -116,7 +116,7 @@ mod tests { syn.trim(), r#" SOURCE_FILE@0..11 - FN_DEF@0..11 + FN@0..11 FN_KW@0..2 "fn" WHITESPACE@2..3 " " NAME@3..6 @@ -148,7 +148,7 @@ fn test() { syn.trim(), r#" SOURCE_FILE@0..60 - FN_DEF@0..60 + FN@0..60 FN_KW@0..2 "fn" WHITESPACE@2..3 " " NAME@3..7 @@ -190,7 +190,7 @@ SOURCE_FILE@0..60 assert_eq_text!( syn.trim(), r#" -FN_DEF@0..11 +FN@0..11 FN_KW@0..2 "fn" WHITESPACE@2..3 " " NAME@3..6 @@ -258,7 +258,7 @@ fn bar() { syn.trim(), r#" SOURCE_FILE@0..12 - FN_DEF@0..12 + FN@0..12 FN_KW@0..2 "fn" WHITESPACE@2..3 " " NAME@3..6 @@ -292,7 +292,7 @@ fn bar() { syn.trim(), r#" SOURCE_FILE@0..12 - FN_DEF@0..12 + FN@0..12 FN_KW@0..2 "fn" WHITESPACE@2..3 " " NAME@3..6 @@ -325,7 +325,7 @@ fn bar() { syn.trim(), r#" SOURCE_FILE@0..25 - FN_DEF@0..12 + FN@0..12 FN_KW@0..2 "fn" WHITESPACE@2..3 " " NAME@3..6 @@ -339,7 +339,7 @@ SOURCE_FILE@0..25 WHITESPACE@10..11 "\n" R_CURLY@11..12 "}" WHITESPACE@12..13 "\n" - FN_DEF@13..25 + FN@13..25 FN_KW@13..15 "fn" WHITESPACE@15..16 " " NAME@16..19 -- cgit v1.2.3 From eb2f8063444b11257111f4f8ade990ec810e0361 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 15:25:46 +0200 Subject: Rename TypeAliasDef -> TypeAlias --- crates/ra_ide/src/completion/complete_trait_impl.rs | 6 +++--- crates/ra_ide/src/display.rs | 2 +- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- crates/ra_ide/src/display/short_label.rs | 2 +- crates/ra_ide/src/file_structure.rs | 4 ++-- crates/ra_ide/src/syntax_highlighting.rs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index dbb9eecc6..7d9050a6b 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -2,7 +2,7 @@ //! //! This module adds the completion items related to implementing associated //! items within a `impl Trait for Struct` block. The current context node -//! must be within either a `FN`, `TYPE_ALIAS_DEF`, or `CONST_DEF` node +//! must be within either a `FN`, `TYPE_ALIAS`, or `CONST_DEF` node //! and an direct child of an `IMPL_DEF`. //! //! # Examples @@ -75,7 +75,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext } } - SyntaxKind::TYPE_ALIAS_DEF => { + SyntaxKind::TYPE_ALIAS => { for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) .into_iter() .filter_map(|item| match item { @@ -107,7 +107,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { SyntaxKind::FN - | SyntaxKind::TYPE_ALIAS_DEF + | SyntaxKind::TYPE_ALIAS | SyntaxKind::CONST_DEF | SyntaxKind::BLOCK_EXPR => Some((p, 2)), SyntaxKind::NAME_REF => Some((p, 5)), diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index e4effc66c..6d93726bf 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs @@ -65,7 +65,7 @@ pub(crate) fn const_label(node: &ast::ConstDef) -> String { label.trim().to_owned() } -pub(crate) fn type_label(node: &ast::TypeAliasDef) -> String { +pub(crate) fn type_label(node: &ast::TypeAlias) -> String { let label: String = node .syntax() .children_with_tokens() diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 222cb3502..4f19c7ed4 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -384,7 +384,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option ast::EnumDef(it) => it.doc_comment_text(), ast::TraitDef(it) => it.doc_comment_text(), ast::Module(it) => it.doc_comment_text(), - ast::TypeAliasDef(it) => it.doc_comment_text(), + ast::TypeAlias(it) => it.doc_comment_text(), ast::ConstDef(it) => it.doc_comment_text(), ast::StaticDef(it) => it.doc_comment_text(), ast::RecordFieldDef(it) => it.doc_comment_text(), @@ -409,7 +409,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> ast::EnumDef(it) => it.short_label(), ast::TraitDef(it) => it.short_label(), ast::Module(it) => it.short_label(), - ast::TypeAliasDef(it) => it.short_label(), + ast::TypeAlias(it) => it.short_label(), ast::ConstDef(it) => it.short_label(), ast::StaticDef(it) => it.short_label(), ast::RecordFieldDef(it) => it.short_label(), diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 63863943a..e2c95be06 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -47,7 +47,7 @@ impl ShortLabel for ast::Module { } } -impl ShortLabel for ast::TypeAliasDef { +impl ShortLabel for ast::TypeAlias { fn short_label(&self) -> Option { short_label_from_node(self, "type ") } diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 41603480e..8ef977761 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -132,7 +132,7 @@ fn structure_node(node: &SyntaxNode) -> Option { ast::EnumVariant(it) => decl(it), ast::TraitDef(it) => decl(it), ast::Module(it) => decl(it), - ast::TypeAliasDef(it) => { + ast::TypeAlias(it) => { let ty = it.type_ref(); decl_with_type_ref(it, ty) }, @@ -339,7 +339,7 @@ fn very_obsolete() {} label: "T", navigation_range: 186..187, node_range: 181..193, - kind: TYPE_ALIAS_DEF, + kind: TYPE_ALIAS, detail: Some( "()", ), diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 5198727d9..8d52fb6e4 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -709,7 +709,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { ENUM_DEF => HighlightTag::Enum, UNION_DEF => HighlightTag::Union, TRAIT_DEF => HighlightTag::Trait, - TYPE_ALIAS_DEF => HighlightTag::TypeAlias, + TYPE_ALIAS => HighlightTag::TypeAlias, TYPE_PARAM => HighlightTag::TypeParam, RECORD_FIELD_DEF => HighlightTag::Field, MODULE => HighlightTag::Module, -- cgit v1.2.3 From 28ef4c375a9f56d69daf885504aea3df7012bb81 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 15:36:21 +0200 Subject: Rename TypeParamList -> GenericParamList --- crates/ra_ide/src/display.rs | 4 ++-- crates/ra_ide/src/extend_selection.rs | 2 +- crates/ra_ide/src/file_structure.rs | 4 ++-- crates/ra_ide/src/references.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index 6d93726bf..e81e8436f 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs @@ -5,7 +5,7 @@ mod navigation_target; mod short_label; use ra_syntax::{ - ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner}, + ast::{self, AstNode, AttrsOwner, GenericParamsOwner, NameOwner}, SyntaxKind::{ATTR, COMMENT}, }; @@ -37,7 +37,7 @@ pub(crate) fn function_declaration(node: &ast::Fn) -> String { if let Some(name) = node.name() { format_to!(buf, "fn {}", name) } - if let Some(type_params) = node.type_param_list() { + if let Some(type_params) = node.generic_param_list() { format_to!(buf, "{}", type_params); } if let Some(param_list) = node.param_list() { diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index 8a6b3ea99..b1c4561c1 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -44,7 +44,7 @@ fn try_extend_selection( RECORD_FIELD_LIST, ENUM_VARIANT_LIST, USE_TREE_LIST, - TYPE_PARAM_LIST, + GENERIC_PARAM_LIST, TYPE_ARG_LIST, TYPE_BOUND_LIST, PARAM_LIST, diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 8ef977761..05ccc0b73 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -1,5 +1,5 @@ use ra_syntax::{ - ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, + ast::{self, AttrsOwner, GenericParamsOwner, NameOwner, TypeAscriptionOwner}, match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, WalkEvent, }; @@ -113,7 +113,7 @@ fn structure_node(node: &SyntaxNode) -> Option { match node { ast::Fn(it) => { let mut detail = String::from("fn"); - if let Some(type_param_list) = it.type_param_list() { + if let Some(type_param_list) = it.generic_param_list() { collapse_ws(type_param_list.syntax(), &mut detail); } if let Some(param_list) = it.param_list() { diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 8d3452a83..94d03a07f 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -175,7 +175,7 @@ fn get_struct_def_name_for_struct_literal_search( return name.syntax().ancestors().find_map(ast::StructDef::cast).and_then(|l| l.name()); } if sema - .find_node_at_offset_with_descend::( + .find_node_at_offset_with_descend::( &syntax, left.text_range().start(), ) -- cgit v1.2.3 From 6f8aa75329d0a4e588e58b8f22f7932bf3d3a706 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 16:21:30 +0200 Subject: Rename RecordLit -> RecordExpr --- crates/ra_ide/src/completion/completion_context.rs | 8 ++++---- crates/ra_ide/src/diagnostics.rs | 6 +++--- crates/ra_ide/src/extend_selection.rs | 2 +- crates/ra_ide/src/folding_ranges.rs | 2 +- crates/ra_ide/src/inlay_hints.rs | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 221d7847e..c8704eb3e 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -37,9 +37,9 @@ pub(crate) struct CompletionContext<'a> { pub(super) name_ref_syntax: Option, pub(super) function_syntax: Option, pub(super) use_item_syntax: Option, - pub(super) record_lit_syntax: Option, + pub(super) record_lit_syntax: Option, pub(super) record_pat_syntax: Option, - pub(super) record_field_syntax: Option, + pub(super) record_field_syntax: Option, pub(super) impl_def: Option, /// FIXME: `ActiveParameter` is string-based, which is very very wrong pub(super) active_parameter: Option, @@ -316,7 +316,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 ast::RecordField::for_field_name(&name_ref).is_some() { + if ast::RecordExprField::for_field_name(&name_ref).is_some() { self.record_lit_syntax = self.sema.find_node_at_offset_with_macros(&original_file, offset); } @@ -357,7 +357,7 @@ impl<'a> CompletionContext<'a> { .take_while(|it| { it.kind() != SOURCE_FILE && it.kind() != MODULE && it.kind() != CALL_EXPR }) - .find_map(ast::RecordField::cast); + .find_map(ast::RecordExprField::cast); let parent = match name_ref.syntax().parent() { Some(it) => it, diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 897177d05..efbb00d6d 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs @@ -146,7 +146,7 @@ fn missing_struct_field_fix( ) -> Option { let record_expr = sema.ast(d); - let record_lit = ast::RecordLit::cast(record_expr.syntax().parent()?.parent()?)?; + let record_lit = ast::RecordExpr::cast(record_expr.syntax().parent()?.parent()?)?; let def_id = sema.resolve_variant(record_lit)?; let module; let def_file_id; @@ -263,8 +263,8 @@ fn check_struct_shorthand_initialization( file_id: FileId, node: &SyntaxNode, ) -> Option<()> { - let record_lit = ast::RecordLit::cast(node.clone())?; - let record_field_list = record_lit.record_field_list()?; + let record_lit = ast::RecordExpr::cast(node.clone())?; + let record_field_list = record_lit.record_expr_field_list()?; for record_field in record_field_list.fields() { if let (Some(name_ref), Some(expr)) = (record_field.name_ref(), record_field.expr()) { let field_name = name_ref.syntax().text().to_string(); diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index b1c4561c1..597a7d82f 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -41,7 +41,7 @@ fn try_extend_selection( MATCH_ARM_LIST, RECORD_FIELD_DEF_LIST, TUPLE_FIELD_DEF_LIST, - RECORD_FIELD_LIST, + RECORD_EXPR_FIELD_LIST, ENUM_VARIANT_LIST, USE_TREE_LIST, GENERIC_PARAM_LIST, diff --git a/crates/ra_ide/src/folding_ranges.rs b/crates/ra_ide/src/folding_ranges.rs index bad079146..972505450 100644 --- a/crates/ra_ide/src/folding_ranges.rs +++ b/crates/ra_ide/src/folding_ranges.rs @@ -87,7 +87,7 @@ fn fold_kind(kind: SyntaxKind) -> Option { ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList), RECORD_FIELD_DEF_LIST | RECORD_FIELD_PAT_LIST - | RECORD_FIELD_LIST + | RECORD_EXPR_FIELD_LIST | ITEM_LIST | EXTERN_ITEM_LIST | USE_TREE_LIST diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index f2e4f7ee5..714ba6bd9 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -96,7 +96,7 @@ fn get_chaining_hints( return None; } - if matches!(expr, ast::Expr::RecordLit(_)) { + if matches!(expr, ast::Expr::RecordExpr(_)) { return None; } -- cgit v1.2.3 From 0a9e3ccc262fbcbd4cdaab30384f8cb71584544b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 16:49:13 +0200 Subject: Rename FieldDef -> Field --- crates/ra_ide/src/diagnostics.rs | 16 ++++++++-------- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- crates/ra_ide/src/display/short_label.rs | 2 +- crates/ra_ide/src/extend_selection.rs | 4 ++-- crates/ra_ide/src/file_structure.rs | 4 ++-- crates/ra_ide/src/folding_ranges.rs | 2 +- crates/ra_ide/src/references.rs | 4 ++-- crates/ra_ide/src/syntax_highlighting.rs | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index efbb00d6d..dd8a7ffd9 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs @@ -155,21 +155,21 @@ fn missing_struct_field_fix( module = s.module(sema.db); let source = s.source(sema.db); def_file_id = source.file_id; - let fields = source.value.field_def_list()?; - record_field_def_list(fields)? + let fields = source.value.field_list()?; + record_field_list(fields)? } VariantDef::Union(u) => { module = u.module(sema.db); let source = u.source(sema.db); def_file_id = source.file_id; - source.value.record_field_def_list()? + source.value.record_field_list()? } VariantDef::EnumVariant(e) => { module = e.module(sema.db); let source = e.source(sema.db); def_file_id = source.file_id; - let fields = source.value.field_def_list()?; - record_field_def_list(fields)? + let fields = source.value.field_list()?; + record_field_list(fields)? } }; let def_file_id = def_file_id.original_file(sema.db); @@ -205,10 +205,10 @@ fn missing_struct_field_fix( let fix = Fix::new("Create field", source_change.into()); return Some(fix); - fn record_field_def_list(field_def_list: ast::FieldDefList) -> Option { + fn record_field_list(field_def_list: ast::FieldList) -> Option { match field_def_list { - ast::FieldDefList::RecordFieldDefList(it) => Some(it), - ast::FieldDefList::TupleFieldDefList(_) => None, + ast::FieldList::RecordFieldList(it) => Some(it), + ast::FieldList::TupleFieldList(_) => None, } } } diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 4f19c7ed4..797d2d8e3 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -387,7 +387,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option ast::TypeAlias(it) => it.doc_comment_text(), ast::ConstDef(it) => it.doc_comment_text(), ast::StaticDef(it) => it.doc_comment_text(), - ast::RecordFieldDef(it) => it.doc_comment_text(), + ast::RecordField(it) => it.doc_comment_text(), ast::EnumVariant(it) => it.doc_comment_text(), ast::MacroCall(it) => it.doc_comment_text(), _ => None, @@ -412,7 +412,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> ast::TypeAlias(it) => it.short_label(), ast::ConstDef(it) => it.short_label(), ast::StaticDef(it) => it.short_label(), - ast::RecordFieldDef(it) => it.short_label(), + ast::RecordField(it) => it.short_label(), ast::EnumVariant(it) => it.short_label(), _ => None, } diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index e2c95be06..78a2598d6 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -65,7 +65,7 @@ impl ShortLabel for ast::StaticDef { } } -impl ShortLabel for ast::RecordFieldDef { +impl ShortLabel for ast::RecordField { fn short_label(&self) -> Option { short_label_from_ascribed_node(self, "") } diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index 597a7d82f..04a7f0ac4 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -39,8 +39,8 @@ fn try_extend_selection( let list_kinds = [ RECORD_FIELD_PAT_LIST, MATCH_ARM_LIST, - RECORD_FIELD_DEF_LIST, - TUPLE_FIELD_DEF_LIST, + RECORD_FIELD_LIST, + TUPLE_FIELD_LIST, RECORD_EXPR_FIELD_LIST, ENUM_VARIANT_LIST, USE_TREE_LIST, diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 05ccc0b73..a8fd1a2fd 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -136,7 +136,7 @@ fn structure_node(node: &SyntaxNode) -> Option { let ty = it.type_ref(); decl_with_type_ref(it, ty) }, - ast::RecordFieldDef(it) => decl_with_ascription(it), + ast::RecordField(it) => decl_with_ascription(it), ast::ConstDef(it) => decl_with_ascription(it), ast::StaticDef(it) => decl_with_ascription(it), ast::ImplDef(it) => { @@ -249,7 +249,7 @@ fn very_obsolete() {} label: "x", navigation_range: 18..19, node_range: 18..24, - kind: RECORD_FIELD_DEF, + kind: RECORD_FIELD, detail: Some( "i32", ), diff --git a/crates/ra_ide/src/folding_ranges.rs b/crates/ra_ide/src/folding_ranges.rs index 972505450..8dcce9f56 100644 --- a/crates/ra_ide/src/folding_ranges.rs +++ b/crates/ra_ide/src/folding_ranges.rs @@ -85,7 +85,7 @@ fn fold_kind(kind: SyntaxKind) -> Option { COMMENT => Some(FoldKind::Comment), USE => Some(FoldKind::Imports), ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList), - RECORD_FIELD_DEF_LIST + RECORD_FIELD_LIST | RECORD_FIELD_PAT_LIST | RECORD_EXPR_FIELD_LIST | ITEM_LIST diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 94d03a07f..d61ac271e 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -361,7 +361,7 @@ fn main(s: Foo) { ); check_result( refs, - "spam RECORD_FIELD_DEF FileId(1) 17..30 21..25 Other", + "spam RECORD_FIELD FileId(1) 17..30 21..25 Other", &["FileId(1) 67..71 Other Read"], ); } @@ -580,7 +580,7 @@ fn foo() { ); check_result( refs, - "f RECORD_FIELD_DEF FileId(1) 15..21 15..16 Other", + "f RECORD_FIELD FileId(1) 15..21 15..16 Other", &["FileId(1) 55..56 Other Read", "FileId(1) 68..69 Other Write"], ); } diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 8d52fb6e4..a04b9d893 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -711,7 +711,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { TRAIT_DEF => HighlightTag::Trait, TYPE_ALIAS => HighlightTag::TypeAlias, TYPE_PARAM => HighlightTag::TypeParam, - RECORD_FIELD_DEF => HighlightTag::Field, + RECORD_FIELD => HighlightTag::Field, MODULE => HighlightTag::Module, FN => HighlightTag::Function, CONST_DEF => HighlightTag::Constant, -- cgit v1.2.3 From 1ae4721c9cfea746fce59a816b1c266bf373d6cf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:36:46 +0200 Subject: Finalize union grammar --- crates/ra_ide/src/display/short_label.rs | 2 +- crates/ra_ide/src/file_structure.rs | 2 +- crates/ra_ide/src/goto_implementation.rs | 2 +- crates/ra_ide/src/syntax_highlighting.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 78a2598d6..730df1414 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -19,7 +19,7 @@ impl ShortLabel for ast::StructDef { } } -impl ShortLabel for ast::UnionDef { +impl ShortLabel for ast::Union { fn short_label(&self) -> Option { short_label_from_node(self, "union ") } diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index a8fd1a2fd..874cf72ef 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -127,7 +127,7 @@ fn structure_node(node: &SyntaxNode) -> Option { decl_with_detail(it, Some(detail)) }, ast::StructDef(it) => decl(it), - ast::UnionDef(it) => decl(it), + ast::Union(it) => decl(it), ast::EnumDef(it) => decl(it), ast::EnumVariant(it) => decl(it), ast::TraitDef(it) => decl(it), diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs index 16a61d071..e41a4a12b 100644 --- a/crates/ra_ide/src/goto_implementation.rs +++ b/crates/ra_ide/src/goto_implementation.rs @@ -46,7 +46,7 @@ fn impls_for_def( let ty = match node { ast::AdtDef::StructDef(def) => sema.to_def(def)?.ty(sema.db), ast::AdtDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db), - ast::AdtDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db), + ast::AdtDef::Union(def) => sema.to_def(def)?.ty(sema.db), }; let impls = ImplDef::all_in_crate(sema.db, krate); diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index a04b9d893..b0ab160ac 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -707,7 +707,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { let tag = match parent.kind() { STRUCT_DEF => HighlightTag::Struct, ENUM_DEF => HighlightTag::Enum, - UNION_DEF => HighlightTag::Union, + UNION => HighlightTag::Union, TRAIT_DEF => HighlightTag::Trait, TYPE_ALIAS => HighlightTag::TypeAlias, TYPE_PARAM => HighlightTag::TypeParam, -- cgit v1.2.3 From 216a5344c8ef3c3e430d2761dc8b1a7b60250a15 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:50:40 +0200 Subject: Rename StructDef -> Struct --- crates/ra_ide/src/display/navigation_target.rs | 4 +-- crates/ra_ide/src/display/short_label.rs | 2 +- crates/ra_ide/src/file_structure.rs | 4 +-- crates/ra_ide/src/goto_implementation.rs | 2 +- crates/ra_ide/src/hover.rs | 34 +++++++++++++------------- crates/ra_ide/src/references.rs | 16 ++++++------ crates/ra_ide/src/syntax_highlighting.rs | 2 +- 7 files changed, 32 insertions(+), 32 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 797d2d8e3..5686faaab 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -380,7 +380,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option match_ast! { match node { ast::Fn(it) => it.doc_comment_text(), - ast::StructDef(it) => it.doc_comment_text(), + ast::Struct(it) => it.doc_comment_text(), ast::EnumDef(it) => it.doc_comment_text(), ast::TraitDef(it) => it.doc_comment_text(), ast::Module(it) => it.doc_comment_text(), @@ -405,7 +405,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> match_ast! { match node { ast::Fn(it) => it.short_label(), - ast::StructDef(it) => it.short_label(), + ast::Struct(it) => it.short_label(), ast::EnumDef(it) => it.short_label(), ast::TraitDef(it) => it.short_label(), ast::Module(it) => it.short_label(), diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 730df1414..504b884c5 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -13,7 +13,7 @@ impl ShortLabel for ast::Fn { } } -impl ShortLabel for ast::StructDef { +impl ShortLabel for ast::Struct { fn short_label(&self) -> Option { short_label_from_node(self, "struct ") } diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 874cf72ef..6f198fcbc 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -126,7 +126,7 @@ fn structure_node(node: &SyntaxNode) -> Option { decl_with_detail(it, Some(detail)) }, - ast::StructDef(it) => decl(it), + ast::Struct(it) => decl(it), ast::Union(it) => decl(it), ast::EnumDef(it) => decl(it), ast::EnumVariant(it) => decl(it), @@ -238,7 +238,7 @@ fn very_obsolete() {} label: "Foo", navigation_range: 8..11, node_range: 1..26, - kind: STRUCT_DEF, + kind: STRUCT, detail: None, deprecated: false, }, diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs index e41a4a12b..699fad57d 100644 --- a/crates/ra_ide/src/goto_implementation.rs +++ b/crates/ra_ide/src/goto_implementation.rs @@ -44,7 +44,7 @@ fn impls_for_def( krate: Crate, ) -> Option> { let ty = match node { - ast::AdtDef::StructDef(def) => sema.to_def(def)?.ty(sema.db), + ast::AdtDef::Struct(def) => sema.to_def(def)?.ty(sema.db), ast::AdtDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db), ast::AdtDef::Union(def) => sema.to_def(def)?.ty(sema.db), }; diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 4ef7efd26..83228af2e 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -1443,7 +1443,7 @@ fn main() { let s<|>t = S{ f1:0 }; } 7..8, ), name: "S", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct S", @@ -1482,7 +1482,7 @@ fn main() { let s<|>t = S{ f1:Arg(0) }; } 24..25, ), name: "S", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct S", @@ -1501,7 +1501,7 @@ fn main() { let s<|>t = S{ f1:Arg(0) }; } 7..10, ), name: "Arg", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct Arg", @@ -1540,7 +1540,7 @@ fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; } 24..25, ), name: "S", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct S", @@ -1559,7 +1559,7 @@ fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; } 7..10, ), name: "Arg", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct Arg", @@ -1601,7 +1601,7 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); } 7..8, ), name: "A", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct A", @@ -1620,7 +1620,7 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); } 22..23, ), name: "B", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct B", @@ -1639,7 +1639,7 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); } 53..54, ), name: "C", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "pub struct C", @@ -1737,7 +1737,7 @@ fn main() { let s<|>t = foo(); } 23..24, ), name: "S", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct S", @@ -1877,7 +1877,7 @@ fn main() { let s<|>t = foo(); } 39..41, ), name: "S1", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct S1", @@ -1896,7 +1896,7 @@ fn main() { let s<|>t = foo(); } 52..54, ), name: "S2", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct S2", @@ -2011,7 +2011,7 @@ fn foo(ar<|>g: &impl Foo + Bar) {} 36..37, ), name: "S", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct S", @@ -2068,7 +2068,7 @@ fn foo(ar<|>g: &impl Foo) {} 23..24, ), name: "S", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct S", @@ -2111,7 +2111,7 @@ fn main() { let s<|>t = foo(); } 49..50, ), name: "B", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct B", @@ -2224,7 +2224,7 @@ fn foo(ar<|>g: &dyn Foo) {} 23..24, ), name: "S", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct S", @@ -2284,7 +2284,7 @@ fn foo(a<|>rg: &impl ImplTrait>>>) {} 50..51, ), name: "B", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct B", @@ -2322,7 +2322,7 @@ fn foo(a<|>rg: &impl ImplTrait>>>) {} 65..66, ), name: "S", - kind: STRUCT_DEF, + kind: STRUCT, container_name: None, description: Some( "struct S", diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index d61ac271e..2a62dab6c 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -172,7 +172,7 @@ fn get_struct_def_name_for_struct_literal_search( if let Some(name) = sema.find_node_at_offset_with_descend::(&syntax, left.text_range().start()) { - return name.syntax().ancestors().find_map(ast::StructDef::cast).and_then(|l| l.name()); + return name.syntax().ancestors().find_map(ast::Struct::cast).and_then(|l| l.name()); } if sema .find_node_at_offset_with_descend::( @@ -181,7 +181,7 @@ fn get_struct_def_name_for_struct_literal_search( ) .is_some() { - return left.ancestors().find_map(ast::StructDef::cast).and_then(|l| l.name()); + return left.ancestors().find_map(ast::Struct::cast).and_then(|l| l.name()); } } None @@ -212,7 +212,7 @@ fn main() { ); check_result( refs, - "Foo STRUCT_DEF FileId(1) 0..26 7..10 Other", + "Foo STRUCT FileId(1) 0..26 7..10 Other", &["FileId(1) 101..104 StructLiteral"], ); } @@ -230,7 +230,7 @@ struct Foo<|> {} ); check_result( refs, - "Foo STRUCT_DEF FileId(1) 0..13 7..10 Other", + "Foo STRUCT FileId(1) 0..13 7..10 Other", &["FileId(1) 41..44 Other", "FileId(1) 54..57 StructLiteral"], ); } @@ -248,7 +248,7 @@ struct Foo <|>{} ); check_result( refs, - "Foo STRUCT_DEF FileId(1) 0..16 7..10 Other", + "Foo STRUCT FileId(1) 0..16 7..10 Other", &["FileId(1) 64..67 StructLiteral"], ); } @@ -267,7 +267,7 @@ fn main() { ); check_result( refs, - "Foo STRUCT_DEF FileId(1) 0..16 7..10 Other", + "Foo STRUCT FileId(1) 0..16 7..10 Other", &["FileId(1) 54..57 StructLiteral"], ); } @@ -431,7 +431,7 @@ fn f() { let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); check_result( refs, - "Foo STRUCT_DEF FileId(2) 17..51 28..31 Other", + "Foo STRUCT FileId(2) 17..51 28..31 Other", &["FileId(1) 53..56 StructLiteral", "FileId(3) 79..82 StructLiteral"], ); } @@ -486,7 +486,7 @@ pub(super) struct Foo<|> { let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); check_result( refs, - "Foo STRUCT_DEF FileId(3) 0..41 18..21 Other", + "Foo STRUCT FileId(3) 0..41 18..21 Other", &["FileId(2) 20..23 Other", "FileId(2) 47..50 StructLiteral"], ); } diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index b0ab160ac..ba1fd6242 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -705,7 +705,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { }; let tag = match parent.kind() { - STRUCT_DEF => HighlightTag::Struct, + STRUCT => HighlightTag::Struct, ENUM_DEF => HighlightTag::Enum, UNION => HighlightTag::Union, TRAIT_DEF => HighlightTag::Trait, -- cgit v1.2.3 From 609680ef97dbf82c07b6b06e21aa366423892304 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:52:53 +0200 Subject: Rename EnumDef -> Enum --- crates/ra_ide/src/display/navigation_target.rs | 8 ++++---- crates/ra_ide/src/display/short_label.rs | 2 +- crates/ra_ide/src/file_structure.rs | 4 ++-- crates/ra_ide/src/goto_implementation.rs | 2 +- crates/ra_ide/src/syntax_highlighting.rs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 5686faaab..02fefd6bb 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -381,7 +381,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option match node { ast::Fn(it) => it.doc_comment_text(), ast::Struct(it) => it.doc_comment_text(), - ast::EnumDef(it) => it.doc_comment_text(), + ast::Enum(it) => it.doc_comment_text(), ast::TraitDef(it) => it.doc_comment_text(), ast::Module(it) => it.doc_comment_text(), ast::TypeAlias(it) => it.doc_comment_text(), @@ -406,7 +406,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> match node { ast::Fn(it) => it.short_label(), ast::Struct(it) => it.short_label(), - ast::EnumDef(it) => it.short_label(), + ast::Enum(it) => it.short_label(), ast::TraitDef(it) => it.short_label(), ast::Module(it) => it.short_label(), ast::TypeAlias(it) => it.short_label(), @@ -446,7 +446,7 @@ fn foo() { enum FooInner { } } 5..13, ), name: "FooInner", - kind: ENUM_DEF, + kind: ENUM, container_name: None, description: Some( "enum FooInner", @@ -462,7 +462,7 @@ fn foo() { enum FooInner { } } 34..42, ), name: "FooInner", - kind: ENUM_DEF, + kind: ENUM, container_name: Some( "foo", ), diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 504b884c5..5bf70937f 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -25,7 +25,7 @@ impl ShortLabel for ast::Union { } } -impl ShortLabel for ast::EnumDef { +impl ShortLabel for ast::Enum { fn short_label(&self) -> Option { short_label_from_node(self, "enum ") } diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 6f198fcbc..c909f96aa 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -128,7 +128,7 @@ fn structure_node(node: &SyntaxNode) -> Option { }, ast::Struct(it) => decl(it), ast::Union(it) => decl(it), - ast::EnumDef(it) => decl(it), + ast::Enum(it) => decl(it), ast::EnumVariant(it) => decl(it), ast::TraitDef(it) => decl(it), ast::Module(it) => decl(it), @@ -308,7 +308,7 @@ fn very_obsolete() {} label: "E", navigation_range: 165..166, node_range: 160..180, - kind: ENUM_DEF, + kind: ENUM, detail: None, deprecated: false, }, diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs index 699fad57d..e2f7e6373 100644 --- a/crates/ra_ide/src/goto_implementation.rs +++ b/crates/ra_ide/src/goto_implementation.rs @@ -45,7 +45,7 @@ fn impls_for_def( ) -> Option> { let ty = match node { ast::AdtDef::Struct(def) => sema.to_def(def)?.ty(sema.db), - ast::AdtDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db), + ast::AdtDef::Enum(def) => sema.to_def(def)?.ty(sema.db), ast::AdtDef::Union(def) => sema.to_def(def)?.ty(sema.db), }; diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index ba1fd6242..7e2833bd5 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -706,7 +706,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { let tag = match parent.kind() { STRUCT => HighlightTag::Struct, - ENUM_DEF => HighlightTag::Enum, + ENUM => HighlightTag::Enum, UNION => HighlightTag::Union, TRAIT_DEF => HighlightTag::Trait, TYPE_ALIAS => HighlightTag::TypeAlias, -- cgit v1.2.3 From 1766aae145c6925a33e427f2fe6ef2a56c301665 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:56:53 +0200 Subject: Rename EnumVariant -> Variant --- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- crates/ra_ide/src/display/short_label.rs | 2 +- crates/ra_ide/src/extend_selection.rs | 2 +- crates/ra_ide/src/file_structure.rs | 6 +++--- crates/ra_ide/src/folding_ranges.rs | 2 +- crates/ra_ide/src/references.rs | 2 +- crates/ra_ide/src/syntax_highlighting.rs | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 02fefd6bb..c30b91fe0 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -388,7 +388,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option ast::ConstDef(it) => it.doc_comment_text(), ast::StaticDef(it) => it.doc_comment_text(), ast::RecordField(it) => it.doc_comment_text(), - ast::EnumVariant(it) => it.doc_comment_text(), + ast::Variant(it) => it.doc_comment_text(), ast::MacroCall(it) => it.doc_comment_text(), _ => None, } @@ -413,7 +413,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> ast::ConstDef(it) => it.short_label(), ast::StaticDef(it) => it.short_label(), ast::RecordField(it) => it.short_label(), - ast::EnumVariant(it) => it.short_label(), + ast::Variant(it) => it.short_label(), _ => None, } } diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 5bf70937f..ddf1059ee 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -71,7 +71,7 @@ impl ShortLabel for ast::RecordField { } } -impl ShortLabel for ast::EnumVariant { +impl ShortLabel for ast::Variant { fn short_label(&self) -> Option { Some(self.name()?.text().to_string()) } diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index 04a7f0ac4..fc81b48cc 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -42,7 +42,7 @@ fn try_extend_selection( RECORD_FIELD_LIST, TUPLE_FIELD_LIST, RECORD_EXPR_FIELD_LIST, - ENUM_VARIANT_LIST, + VARIANT_LIST, USE_TREE_LIST, GENERIC_PARAM_LIST, TYPE_ARG_LIST, diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index c909f96aa..43202499d 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -129,7 +129,7 @@ fn structure_node(node: &SyntaxNode) -> Option { ast::Struct(it) => decl(it), ast::Union(it) => decl(it), ast::Enum(it) => decl(it), - ast::EnumVariant(it) => decl(it), + ast::Variant(it) => decl(it), ast::TraitDef(it) => decl(it), ast::Module(it) => decl(it), ast::TypeAlias(it) => { @@ -319,7 +319,7 @@ fn very_obsolete() {} label: "X", navigation_range: 169..170, node_range: 169..170, - kind: ENUM_VARIANT, + kind: VARIANT, detail: None, deprecated: false, }, @@ -330,7 +330,7 @@ fn very_obsolete() {} label: "Y", navigation_range: 172..173, node_range: 172..178, - kind: ENUM_VARIANT, + kind: VARIANT, detail: None, deprecated: false, }, diff --git a/crates/ra_ide/src/folding_ranges.rs b/crates/ra_ide/src/folding_ranges.rs index 8dcce9f56..5a6e17936 100644 --- a/crates/ra_ide/src/folding_ranges.rs +++ b/crates/ra_ide/src/folding_ranges.rs @@ -93,7 +93,7 @@ fn fold_kind(kind: SyntaxKind) -> Option { | USE_TREE_LIST | BLOCK_EXPR | MATCH_ARM_LIST - | ENUM_VARIANT_LIST + | VARIANT_LIST | TOKEN_TREE => Some(FoldKind::Block), _ => None, } diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 2a62dab6c..519e4bf1a 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -390,7 +390,7 @@ enum Foo { } "#, ); - check_result(refs, "B ENUM_VARIANT FileId(1) 22..23 22..23 Other", &[]); + check_result(refs, "B VARIANT FileId(1) 22..23 22..23 Other", &[]); } #[test] diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 7e2833bd5..ce890c816 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -716,7 +716,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { FN => HighlightTag::Function, CONST_DEF => HighlightTag::Constant, STATIC_DEF => HighlightTag::Static, - ENUM_VARIANT => HighlightTag::EnumVariant, + VARIANT => HighlightTag::EnumVariant, BIND_PAT => HighlightTag::Local, _ => default, }; -- cgit v1.2.3 From 3cd4112bdc924c132cb0eab9d064511a215421ec Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:02:20 +0200 Subject: Finalize const&static grammar --- crates/ra_ide/src/completion/complete_trait_impl.rs | 8 ++++---- crates/ra_ide/src/display.rs | 2 +- crates/ra_ide/src/display/navigation_target.rs | 8 ++++---- crates/ra_ide/src/display/short_label.rs | 4 ++-- crates/ra_ide/src/file_structure.rs | 8 ++++---- crates/ra_ide/src/syntax_highlighting.rs | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 7d9050a6b..88679f3bd 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -2,7 +2,7 @@ //! //! This module adds the completion items related to implementing associated //! items within a `impl Trait for Struct` block. The current context node -//! must be within either a `FN`, `TYPE_ALIAS`, or `CONST_DEF` node +//! must be within either a `FN`, `TYPE_ALIAS`, or `CONST` node //! and an direct child of an `IMPL_DEF`. //! //! # Examples @@ -87,7 +87,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext } } - SyntaxKind::CONST_DEF => { + SyntaxKind::CONST => { for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def) .into_iter() .filter_map(|item| match item { @@ -108,7 +108,7 @@ fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { SyntaxKind::FN | SyntaxKind::TYPE_ALIAS - | SyntaxKind::CONST_DEF + | SyntaxKind::CONST | SyntaxKind::BLOCK_EXPR => Some((p, 2)), SyntaxKind::NAME_REF => Some((p, 5)), _ => None, @@ -201,7 +201,7 @@ fn add_const_impl( } } -fn make_const_compl_syntax(const_: &ast::ConstDef) -> String { +fn make_const_compl_syntax(const_: &ast::Const) -> String { let const_ = edit::remove_attrs_and_docs(const_); let const_start = const_.syntax().text_range().start(); diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index e81e8436f..3efca0649 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs @@ -54,7 +54,7 @@ pub(crate) fn function_declaration(node: &ast::Fn) -> String { buf } -pub(crate) fn const_label(node: &ast::ConstDef) -> String { +pub(crate) fn const_label(node: &ast::Const) -> String { let label: String = node .syntax() .children_with_tokens() diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index c30b91fe0..9e2c01245 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -385,8 +385,8 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option ast::TraitDef(it) => it.doc_comment_text(), ast::Module(it) => it.doc_comment_text(), ast::TypeAlias(it) => it.doc_comment_text(), - ast::ConstDef(it) => it.doc_comment_text(), - ast::StaticDef(it) => it.doc_comment_text(), + ast::Const(it) => it.doc_comment_text(), + ast::Static(it) => it.doc_comment_text(), ast::RecordField(it) => it.doc_comment_text(), ast::Variant(it) => it.doc_comment_text(), ast::MacroCall(it) => it.doc_comment_text(), @@ -410,8 +410,8 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> ast::TraitDef(it) => it.short_label(), ast::Module(it) => it.short_label(), ast::TypeAlias(it) => it.short_label(), - ast::ConstDef(it) => it.short_label(), - ast::StaticDef(it) => it.short_label(), + ast::Const(it) => it.short_label(), + ast::Static(it) => it.short_label(), ast::RecordField(it) => it.short_label(), ast::Variant(it) => it.short_label(), _ => None, diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index ddf1059ee..282f362f2 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -53,13 +53,13 @@ impl ShortLabel for ast::TypeAlias { } } -impl ShortLabel for ast::ConstDef { +impl ShortLabel for ast::Const { fn short_label(&self) -> Option { short_label_from_ascribed_node(self, "const ") } } -impl ShortLabel for ast::StaticDef { +impl ShortLabel for ast::Static { fn short_label(&self) -> Option { short_label_from_ascribed_node(self, "static ") } diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 43202499d..77384b6ec 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -137,8 +137,8 @@ fn structure_node(node: &SyntaxNode) -> Option { decl_with_type_ref(it, ty) }, ast::RecordField(it) => decl_with_ascription(it), - ast::ConstDef(it) => decl_with_ascription(it), - ast::StaticDef(it) => decl_with_ascription(it), + ast::Const(it) => decl_with_ascription(it), + ast::Static(it) => decl_with_ascription(it), ast::ImplDef(it) => { let target_type = it.target_type()?; let target_trait = it.target_trait(); @@ -350,7 +350,7 @@ fn very_obsolete() {} label: "S", navigation_range: 201..202, node_range: 194..213, - kind: STATIC_DEF, + kind: STATIC, detail: Some( "i32", ), @@ -361,7 +361,7 @@ fn very_obsolete() {} label: "C", navigation_range: 220..221, node_range: 214..232, - kind: CONST_DEF, + kind: CONST, detail: Some( "i32", ), diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index ce890c816..19ec73d2a 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -714,8 +714,8 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { RECORD_FIELD => HighlightTag::Field, MODULE => HighlightTag::Module, FN => HighlightTag::Function, - CONST_DEF => HighlightTag::Constant, - STATIC_DEF => HighlightTag::Static, + CONST => HighlightTag::Constant, + STATIC => HighlightTag::Static, VARIANT => HighlightTag::EnumVariant, BIND_PAT => HighlightTag::Local, _ => default, -- cgit v1.2.3 From ba71f05438a93991aff6970488a720c90774d35b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:10:07 +0200 Subject: fmt --- crates/ra_ide/src/completion/complete_trait_impl.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 88679f3bd..87221d964 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -106,10 +106,9 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { - SyntaxKind::FN - | SyntaxKind::TYPE_ALIAS - | SyntaxKind::CONST - | SyntaxKind::BLOCK_EXPR => Some((p, 2)), + SyntaxKind::FN | SyntaxKind::TYPE_ALIAS | SyntaxKind::CONST | SyntaxKind::BLOCK_EXPR => { + Some((p, 2)) + } SyntaxKind::NAME_REF => Some((p, 5)), _ => None, })?; -- cgit v1.2.3 From c83467796b6c7365ea4f41900d74444384a9e618 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:17:28 +0200 Subject: Finalize Trait grammar --- crates/ra_ide/src/completion/patterns.rs | 4 ++-- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- crates/ra_ide/src/display/short_label.rs | 2 +- crates/ra_ide/src/file_structure.rs | 2 +- crates/ra_ide/src/goto_implementation.rs | 4 ++-- crates/ra_ide/src/hover.rs | 32 +++++++++++++------------- crates/ra_ide/src/syntax_highlighting.rs | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index b8408da4e..6c11f5830 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -15,7 +15,7 @@ pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool { not_same_range_ancestor(element) .filter(|it| it.kind() == ASSOC_ITEM_LIST) .and_then(|it| it.parent()) - .filter(|it| it.kind() == TRAIT_DEF) + .filter(|it| it.kind() == TRAIT) .is_some() } #[test] @@ -113,7 +113,7 @@ fn test_if_is_prev() { } pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool { - previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT_DEF).is_some() + previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT).is_some() } #[test] fn test_has_trait_as_prev_sibling() { diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 9e2c01245..45fbc86ef 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -382,7 +382,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option ast::Fn(it) => it.doc_comment_text(), ast::Struct(it) => it.doc_comment_text(), ast::Enum(it) => it.doc_comment_text(), - ast::TraitDef(it) => it.doc_comment_text(), + ast::Trait(it) => it.doc_comment_text(), ast::Module(it) => it.doc_comment_text(), ast::TypeAlias(it) => it.doc_comment_text(), ast::Const(it) => it.doc_comment_text(), @@ -407,7 +407,7 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> ast::Fn(it) => it.short_label(), ast::Struct(it) => it.short_label(), ast::Enum(it) => it.short_label(), - ast::TraitDef(it) => it.short_label(), + ast::Trait(it) => it.short_label(), ast::Module(it) => it.short_label(), ast::TypeAlias(it) => it.short_label(), ast::Const(it) => it.short_label(), diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index 282f362f2..c600908a4 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -31,7 +31,7 @@ impl ShortLabel for ast::Enum { } } -impl ShortLabel for ast::TraitDef { +impl ShortLabel for ast::Trait { fn short_label(&self) -> Option { if self.unsafe_token().is_some() { short_label_from_node(self, "unsafe trait ") diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 77384b6ec..3fc972460 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -130,7 +130,7 @@ fn structure_node(node: &SyntaxNode) -> Option { ast::Union(it) => decl(it), ast::Enum(it) => decl(it), ast::Variant(it) => decl(it), - ast::TraitDef(it) => decl(it), + ast::Trait(it) => decl(it), ast::Module(it) => decl(it), ast::TypeAlias(it) => { let ty = it.type_ref(); diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs index e2f7e6373..9912b7142 100644 --- a/crates/ra_ide/src/goto_implementation.rs +++ b/crates/ra_ide/src/goto_implementation.rs @@ -28,7 +28,7 @@ pub(crate) fn goto_implementation( nominal_def.syntax().text_range(), impls_for_def(&sema, &nominal_def, krate)?, )); - } else if let Some(trait_def) = find_node_at_offset::(&syntax, position.offset) { + } else if let Some(trait_def) = find_node_at_offset::(&syntax, position.offset) { return Some(RangeInfo::new( trait_def.syntax().text_range(), impls_for_trait(&sema, &trait_def, krate)?, @@ -62,7 +62,7 @@ fn impls_for_def( fn impls_for_trait( sema: &Semantics, - node: &ast::TraitDef, + node: &ast::Trait, krate: Crate, ) -> Option> { let tr = sema.to_def(node)?; diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 83228af2e..aa48cb412 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -1678,7 +1678,7 @@ fn main() { let s<|>t = foo(); } 6..9, ), name: "Foo", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Foo", @@ -1718,7 +1718,7 @@ fn main() { let s<|>t = foo(); } 6..9, ), name: "Foo", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Foo", @@ -1777,7 +1777,7 @@ fn main() { let s<|>t = foo(); } 6..9, ), name: "Foo", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Foo", @@ -1796,7 +1796,7 @@ fn main() { let s<|>t = foo(); } 19..22, ), name: "Bar", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Bar", @@ -1839,7 +1839,7 @@ fn main() { let s<|>t = foo(); } 6..9, ), name: "Foo", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Foo", @@ -1858,7 +1858,7 @@ fn main() { let s<|>t = foo(); } 22..25, ), name: "Bar", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Bar", @@ -1933,7 +1933,7 @@ fn foo(ar<|>g: &impl Foo) {} 6..9, ), name: "Foo", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Foo", @@ -1973,7 +1973,7 @@ fn foo(ar<|>g: &impl Foo + Bar) {} 6..9, ), name: "Foo", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Foo", @@ -1992,7 +1992,7 @@ fn foo(ar<|>g: &impl Foo + Bar) {} 19..22, ), name: "Bar", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Bar", @@ -2049,7 +2049,7 @@ fn foo(ar<|>g: &impl Foo) {} 6..9, ), name: "Foo", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Foo", @@ -2130,7 +2130,7 @@ fn main() { let s<|>t = foo(); } 6..9, ), name: "Foo", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Foo", @@ -2167,7 +2167,7 @@ fn foo(ar<|>g: &dyn Foo) {} 6..9, ), name: "Foo", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Foo", @@ -2205,7 +2205,7 @@ fn foo(ar<|>g: &dyn Foo) {} 6..9, ), name: "Foo", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Foo", @@ -2265,7 +2265,7 @@ fn foo(a<|>rg: &impl ImplTrait>>>) {} 6..15, ), name: "ImplTrait", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait ImplTrait", @@ -2303,7 +2303,7 @@ fn foo(a<|>rg: &impl ImplTrait>>>) {} 28..36, ), name: "DynTrait", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait DynTrait", @@ -2370,7 +2370,7 @@ fn main() { let s<|>t = test().get(); } 6..9, ), name: "Foo", - kind: TRAIT_DEF, + kind: TRAIT, container_name: None, description: Some( "trait Foo", diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 19ec73d2a..a66453c04 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -708,7 +708,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { STRUCT => HighlightTag::Struct, ENUM => HighlightTag::Enum, UNION => HighlightTag::Union, - TRAIT_DEF => HighlightTag::Trait, + TRAIT => HighlightTag::Trait, TYPE_ALIAS => HighlightTag::TypeAlias, TYPE_PARAM => HighlightTag::TypeParam, RECORD_FIELD => HighlightTag::Field, -- cgit v1.2.3 From c5798c4d75aa807aec47208a49101bdec3affcca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:28:28 +0200 Subject: Finalize impl Grammar --- crates/ra_ide/src/completion/complete_trait_impl.rs | 8 ++++---- crates/ra_ide/src/completion/completion_context.rs | 4 ++-- crates/ra_ide/src/completion/patterns.rs | 4 ++-- crates/ra_ide/src/file_structure.rs | 6 +++--- crates/ra_ide/src/references/rename.rs | 5 ++--- crates/ra_ide/src/syntax_highlighting.rs | 2 +- 6 files changed, 14 insertions(+), 15 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 87221d964..d9a0ef167 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -3,7 +3,7 @@ //! This module adds the completion items related to implementing associated //! items within a `impl Trait for Struct` block. The current context node //! must be within either a `FN`, `TYPE_ALIAS`, or `CONST` node -//! and an direct child of an `IMPL_DEF`. +//! and an direct child of an `IMPL`. //! //! # Examples //! @@ -34,7 +34,7 @@ use hir::{self, Docs, HasSource}; use ra_assists::utils::get_missing_assoc_items; use ra_syntax::{ - ast::{self, edit, ImplDef}, + ast::{self, edit, Impl}, AstNode, SyntaxKind, SyntaxNode, TextRange, T, }; use ra_text_edit::TextEdit; @@ -104,7 +104,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext } } -fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { +fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, Impl)> { let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() { SyntaxKind::FN | SyntaxKind::TYPE_ALIAS | SyntaxKind::CONST | SyntaxKind::BLOCK_EXPR => { Some((p, 2)) @@ -114,7 +114,7 @@ fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, ImplDef)> { })?; let impl_def = (0..impl_def_offset - 1) .try_fold(trigger.parent()?, |t, _| t.parent()) - .and_then(ast::ImplDef::cast)?; + .and_then(ast::Impl::cast)?; Some((trigger, impl_def)) } diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index c8704eb3e..2113abbb2 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -40,7 +40,7 @@ pub(crate) struct CompletionContext<'a> { pub(super) record_lit_syntax: Option, pub(super) record_pat_syntax: Option, pub(super) record_field_syntax: Option, - pub(super) impl_def: Option, + pub(super) impl_def: Option, /// FIXME: `ActiveParameter` is string-based, which is very very wrong pub(super) active_parameter: Option, pub(super) is_param: bool, @@ -325,7 +325,7 @@ impl<'a> CompletionContext<'a> { .sema .ancestors_with_macros(self.token.parent()) .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) - .find_map(ast::ImplDef::cast); + .find_map(ast::Impl::cast); let top_node = name_ref .syntax() diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index 6c11f5830..a68861e1c 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -27,7 +27,7 @@ pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool { not_same_range_ancestor(element) .filter(|it| it.kind() == ASSOC_ITEM_LIST) .and_then(|it| it.parent()) - .filter(|it| it.kind() == IMPL_DEF) + .filter(|it| it.kind() == IMPL) .is_some() } #[test] @@ -121,7 +121,7 @@ fn test_has_trait_as_prev_sibling() { } pub(crate) fn has_impl_as_prev_sibling(element: SyntaxElement) -> bool { - previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == IMPL_DEF).is_some() + previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == IMPL).is_some() } #[test] fn test_has_impl_as_prev_sibling() { diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 3fc972460..7d378f2d0 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -139,7 +139,7 @@ fn structure_node(node: &SyntaxNode) -> Option { ast::RecordField(it) => decl_with_ascription(it), ast::Const(it) => decl_with_ascription(it), ast::Static(it) => decl_with_ascription(it), - ast::ImplDef(it) => { + ast::Impl(it) => { let target_type = it.target_type()?; let target_trait = it.target_trait(); let label = match target_trait { @@ -372,7 +372,7 @@ fn very_obsolete() {} label: "impl E", navigation_range: 239..240, node_range: 234..243, - kind: IMPL_DEF, + kind: IMPL, detail: None, deprecated: false, }, @@ -381,7 +381,7 @@ fn very_obsolete() {} label: "impl fmt::Debug for E", navigation_range: 265..266, node_range: 245..269, - kind: IMPL_DEF, + kind: IMPL, detail: None, deprecated: false, }, diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index d8ffb8c84..d330109f1 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -192,15 +192,14 @@ fn text_edit_from_self_param( self_param: &ast::SelfParam, new_name: &str, ) -> Option { - fn target_type_name(impl_def: &ast::ImplDef) -> Option { + fn target_type_name(impl_def: &ast::Impl) -> Option { if let Some(ast::TypeRef::PathType(p)) = impl_def.target_type() { return Some(p.path()?.segment()?.name_ref()?.text().to_string()); } None } - let impl_def = - find_node_at_offset::(syn, self_param.syntax().text_range().start())?; + let impl_def = find_node_at_offset::(syn, self_param.syntax().text_range().start())?; let type_name = target_type_name(&impl_def)?; let mut replacement_text = String::from(new_name); diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index a66453c04..e3a96f9d5 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -647,7 +647,7 @@ fn highlight_element( fn is_child_of_impl(element: &SyntaxElement) -> bool { match element.parent() { - Some(e) => e.kind() == IMPL_DEF, + Some(e) => e.kind() == IMPL, _ => false, } } -- cgit v1.2.3 From fcce07d2d1b07cf4578af65b00a243e743a67f05 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 20:16:04 +0200 Subject: Finalize attribute grammar --- crates/ra_ide/src/completion/complete_attribute.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_attribute.rs b/crates/ra_ide/src/completion/complete_attribute.rs index 109c5e9a8..2faaae974 100644 --- a/crates/ra_ide/src/completion/complete_attribute.rs +++ b/crates/ra_ide/src/completion/complete_attribute.rs @@ -13,20 +13,18 @@ use crate::completion::{ pub(super) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { let attribute = ctx.attribute_under_caret.as_ref()?; - match (attribute.path(), attribute.input()) { - (Some(path), Some(ast::AttrInput::TokenTree(token_tree))) - if path.to_string() == "derive" => - { + match (attribute.path(), attribute.token_tree()) { + (Some(path), Some(token_tree)) if path.to_string() == "derive" => { complete_derive(acc, ctx, token_tree) } - (Some(path), Some(ast::AttrInput::TokenTree(token_tree))) + (Some(path), Some(token_tree)) if ["allow", "warn", "deny", "forbid"] .iter() .any(|lint_level| lint_level == &path.to_string()) => { complete_lint(acc, ctx, token_tree) } - (_, Some(ast::AttrInput::TokenTree(_token_tree))) => {} + (_, Some(_token_tree)) => {} _ => complete_attribute_start(acc, ctx, attribute), } Some(()) -- cgit v1.2.3 From 2e2642efccd5855e4158b01a006e7884a96982bb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 20:51:43 +0200 Subject: Remove TypeAscriptionOwner --- crates/ra_ide/src/display/short_label.rs | 14 +++++++------- crates/ra_ide/src/file_structure.rs | 28 +++++++++------------------- crates/ra_ide/src/inlay_hints.rs | 6 +++--- crates/ra_ide/src/references/rename.rs | 5 +++-- 4 files changed, 22 insertions(+), 31 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index c600908a4..bddf1bd47 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; +use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; use stdx::format_to; pub(crate) trait ShortLabel { @@ -55,19 +55,19 @@ impl ShortLabel for ast::TypeAlias { impl ShortLabel for ast::Const { fn short_label(&self) -> Option { - short_label_from_ascribed_node(self, "const ") + short_label_from_ty(self, self.ty(), "const ") } } impl ShortLabel for ast::Static { fn short_label(&self) -> Option { - short_label_from_ascribed_node(self, "static ") + short_label_from_ty(self, self.ty(), "static ") } } impl ShortLabel for ast::RecordField { fn short_label(&self) -> Option { - short_label_from_ascribed_node(self, "") + short_label_from_ty(self, self.ty(), "") } } @@ -77,13 +77,13 @@ impl ShortLabel for ast::Variant { } } -fn short_label_from_ascribed_node(node: &T, prefix: &str) -> Option +fn short_label_from_ty(node: &T, ty: Option, prefix: &str) -> Option where - T: NameOwner + VisibilityOwner + TypeAscriptionOwner, + T: NameOwner + VisibilityOwner, { let mut buf = short_label_from_node(node, prefix)?; - if let Some(type_ref) = node.ascribed_type() { + if let Some(type_ref) = ty { format_to!(buf, ": {}", type_ref.syntax()); } diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 7d378f2d0..22cf8637a 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -1,5 +1,5 @@ use ra_syntax::{ - ast::{self, AttrsOwner, GenericParamsOwner, NameOwner, TypeAscriptionOwner}, + ast::{self, AttrsOwner, GenericParamsOwner, NameOwner}, match_ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, WalkEvent, }; @@ -52,18 +52,11 @@ pub fn file_structure(file: &SourceFile) -> Vec { fn structure_node(node: &SyntaxNode) -> Option { fn decl(node: N) -> Option { - decl_with_detail(node, None) - } - - fn decl_with_ascription( - node: N, - ) -> Option { - let ty = node.ascribed_type(); - decl_with_type_ref(node, ty) + decl_with_detail(&node, None) } fn decl_with_type_ref( - node: N, + node: &N, type_ref: Option, ) -> Option { let detail = type_ref.map(|type_ref| { @@ -75,7 +68,7 @@ fn structure_node(node: &SyntaxNode) -> Option { } fn decl_with_detail( - node: N, + node: &N, detail: Option, ) -> Option { let name = node.name()?; @@ -124,7 +117,7 @@ fn structure_node(node: &SyntaxNode) -> Option { collapse_ws(ret_type.syntax(), &mut detail); } - decl_with_detail(it, Some(detail)) + decl_with_detail(&it, Some(detail)) }, ast::Struct(it) => decl(it), ast::Union(it) => decl(it), @@ -132,13 +125,10 @@ fn structure_node(node: &SyntaxNode) -> Option { ast::Variant(it) => decl(it), ast::Trait(it) => decl(it), ast::Module(it) => decl(it), - ast::TypeAlias(it) => { - let ty = it.type_ref(); - decl_with_type_ref(it, ty) - }, - ast::RecordField(it) => decl_with_ascription(it), - ast::Const(it) => decl_with_ascription(it), - ast::Static(it) => decl_with_ascription(it), + ast::TypeAlias(it) => decl_with_type_ref(&it, it.type_ref()), + ast::RecordField(it) => decl_with_type_ref(&it, it.ty()), + ast::Const(it) => decl_with_type_ref(&it, it.ty()), + ast::Static(it) => decl_with_type_ref(&it, it.ty()), ast::Impl(it) => { let target_type = it.target_type()?; let target_trait = it.target_trait(); diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 714ba6bd9..4bbbcd258 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -2,7 +2,7 @@ use hir::{Adt, Callable, HirDisplay, Semantics, Type}; use ra_ide_db::RootDatabase; use ra_prof::profile; use ra_syntax::{ - ast::{self, ArgListOwner, AstNode, TypeAscriptionOwner}, + ast::{self, ArgListOwner, AstNode}, match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T, }; use stdx::to_lower_snake_case; @@ -230,10 +230,10 @@ fn should_not_display_type_hint(db: &RootDatabase, bind_pat: &ast::BindPat, pat_ match_ast! { match node { ast::LetStmt(it) => { - return it.ascribed_type().is_some() + return it.ty().is_some() }, ast::Param(it) => { - return it.ascribed_type().is_some() + return it.ty().is_some() }, ast::MatchArm(_it) => { return pat_is_enum_variant(db, bind_pat, pat_ty); diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index d330109f1..31654bf79 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -7,7 +7,8 @@ use ra_ide_db::{ RootDatabase, }; use ra_syntax::{ - algo::find_node_at_offset, ast, ast::NameOwner, ast::TypeAscriptionOwner, + algo::find_node_at_offset, + ast::{self, NameOwner}, lex_single_valid_syntax_kind, match_ast, AstNode, SyntaxKind, SyntaxNode, SyntaxToken, }; use ra_text_edit::TextEdit; @@ -155,7 +156,7 @@ fn rename_to_self( return None; // method already has self param } let first_param = params.params().next()?; - let mutable = match first_param.ascribed_type() { + let mutable = match first_param.ty() { Some(ast::TypeRef::ReferenceType(rt)) => rt.mut_token().is_some(), _ => return None, // not renaming other types }; -- cgit v1.2.3 From f95f425ae4199e814e6956be1d9bb59a14758c07 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 21:02:55 +0200 Subject: Use ty to access most TypeRefs --- crates/ra_ide/src/display.rs | 2 +- crates/ra_ide/src/file_structure.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs index 3efca0649..fd42aa435 100644 --- a/crates/ra_ide/src/display.rs +++ b/crates/ra_ide/src/display.rs @@ -44,7 +44,7 @@ pub(crate) fn function_declaration(node: &ast::Fn) -> String { format_to!(buf, "{}", param_list); } if let Some(ret_type) = node.ret_type() { - if ret_type.type_ref().is_some() { + if ret_type.ty().is_some() { format_to!(buf, " {}", ret_type); } } diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 22cf8637a..91765140a 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -125,7 +125,7 @@ fn structure_node(node: &SyntaxNode) -> Option { ast::Variant(it) => decl(it), ast::Trait(it) => decl(it), ast::Module(it) => decl(it), - ast::TypeAlias(it) => decl_with_type_ref(&it, it.type_ref()), + ast::TypeAlias(it) => decl_with_type_ref(&it, it.ty()), ast::RecordField(it) => decl_with_type_ref(&it, it.ty()), ast::Const(it) => decl_with_type_ref(&it, it.ty()), ast::Static(it) => decl_with_type_ref(&it, it.ty()), -- cgit v1.2.3 From 08ea2271e8050165d0aaf4c994ed3dd746aff3ba Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 12:06:38 +0200 Subject: Rename TypeRef -> Type The TypeRef name comes from IntelliJ days, where you often have both type *syntax* as well as *semantical* representation of types in scope. And naming both Type is confusing. In rust-analyzer however, we use ast types as `ast::Type`, and have many more semantic counterparts to ast types, so avoiding name clash here is just confusing. --- crates/ra_ide/src/display/short_label.rs | 2 +- crates/ra_ide/src/file_structure.rs | 2 +- crates/ra_ide/src/references/rename.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/short_label.rs b/crates/ra_ide/src/display/short_label.rs index bddf1bd47..0fdf8e9a5 100644 --- a/crates/ra_ide/src/display/short_label.rs +++ b/crates/ra_ide/src/display/short_label.rs @@ -77,7 +77,7 @@ impl ShortLabel for ast::Variant { } } -fn short_label_from_ty(node: &T, ty: Option, prefix: &str) -> Option +fn short_label_from_ty(node: &T, ty: Option, prefix: &str) -> Option where T: NameOwner + VisibilityOwner, { diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index 91765140a..ef368651a 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -57,7 +57,7 @@ fn structure_node(node: &SyntaxNode) -> Option { fn decl_with_type_ref( node: &N, - type_ref: Option, + type_ref: Option, ) -> Option { let detail = type_ref.map(|type_ref| { let mut detail = String::new(); diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 31654bf79..96aed7cc7 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -157,7 +157,7 @@ fn rename_to_self( } let first_param = params.params().next()?; let mutable = match first_param.ty() { - Some(ast::TypeRef::ReferenceType(rt)) => rt.mut_token().is_some(), + Some(ast::Type::ReferenceType(rt)) => rt.mut_token().is_some(), _ => return None, // not renaming other types }; @@ -194,7 +194,7 @@ fn text_edit_from_self_param( new_name: &str, ) -> Option { fn target_type_name(impl_def: &ast::Impl) -> Option { - if let Some(ast::TypeRef::PathType(p)) = impl_def.target_type() { + if let Some(ast::Type::PathType(p)) = impl_def.target_type() { return Some(p.path()?.segment()?.name_ref()?.text().to_string()); } None -- cgit v1.2.3 From 633aace41108b74fe6c93c5ab04272067db033f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 17:08:58 +0200 Subject: Rename LambdaExpr -> ClosureExpr --- crates/ra_ide/src/completion/patterns.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index a68861e1c..9e654b373 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -134,7 +134,7 @@ pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool { NodeOrToken::Token(token) => token.parent(), }; for node in leaf.ancestors() { - if node.kind() == FN || node.kind() == LAMBDA_EXPR { + if node.kind() == FN || node.kind() == CLOSURE_EXPR { break; } let loop_body = match_ast! { -- cgit v1.2.3 From 91781c7ce8201b28afd56b4e35eba47e076a8498 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 18:29:29 +0200 Subject: Rename TypeArgList -> GenericArgList --- crates/ra_ide/src/completion/completion_context.rs | 2 +- crates/ra_ide/src/extend_selection.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 2113abbb2..2a5f3c3d2 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -377,7 +377,7 @@ impl<'a> CompletionContext<'a> { path.syntax().parent().and_then(ast::TupleStructPat::cast).is_some(); self.is_path_type = path.syntax().parent().and_then(ast::PathType::cast).is_some(); - self.has_type_args = segment.type_arg_list().is_some(); + self.has_type_args = segment.generic_arg_list().is_some(); #[allow(deprecated)] if let Some(path) = hir::Path::from_ast(path.clone()) { diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index fc81b48cc..319fd500d 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -45,7 +45,7 @@ fn try_extend_selection( VARIANT_LIST, USE_TREE_LIST, GENERIC_PARAM_LIST, - TYPE_ARG_LIST, + GENERIC_ARG_LIST, TYPE_BOUND_LIST, PARAM_LIST, ARG_LIST, -- cgit v1.2.3 From 14cb96ec0e6be3b99bfe4ea373c058dcbd2a4f79 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 19:54:16 +0200 Subject: Allign RecordPat with RecordExpr --- crates/ra_ide/src/completion/completion_context.rs | 6 +++--- crates/ra_ide/src/extend_selection.rs | 2 +- crates/ra_ide/src/folding_ranges.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 2a5f3c3d2..29955754c 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -265,7 +265,7 @@ impl<'a> CompletionContext<'a> { return; } // FIXME: remove this (V) duplication and make the check more precise - if name_ref.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() { + if name_ref.syntax().ancestors().find_map(ast::RecordPatFieldList::cast).is_some() { self.record_pat_syntax = self.sema.find_node_at_offset_with_macros(&original_file, offset); } @@ -283,7 +283,7 @@ impl<'a> CompletionContext<'a> { { self.is_pat_binding_or_const = false; } - if bind_pat.syntax().parent().and_then(ast::RecordFieldPatList::cast).is_some() { + if bind_pat.syntax().parent().and_then(ast::RecordPatFieldList::cast).is_some() { self.is_pat_binding_or_const = false; } if let Some(let_stmt) = bind_pat.syntax().ancestors().find_map(ast::LetStmt::cast) { @@ -300,7 +300,7 @@ impl<'a> CompletionContext<'a> { return; } // FIXME: remove this (^) duplication and make the check more precise - if name.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() { + if name.syntax().ancestors().find_map(ast::RecordPatFieldList::cast).is_some() { self.record_pat_syntax = self.sema.find_node_at_offset_with_macros(&original_file, offset); } diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index 319fd500d..7230a0ff9 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -37,7 +37,7 @@ fn try_extend_selection( let string_kinds = [COMMENT, STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING]; let list_kinds = [ - RECORD_FIELD_PAT_LIST, + RECORD_PAT_FIELD_LIST, MATCH_ARM_LIST, RECORD_FIELD_LIST, TUPLE_FIELD_LIST, diff --git a/crates/ra_ide/src/folding_ranges.rs b/crates/ra_ide/src/folding_ranges.rs index 5a6e17936..903c34996 100644 --- a/crates/ra_ide/src/folding_ranges.rs +++ b/crates/ra_ide/src/folding_ranges.rs @@ -86,7 +86,7 @@ fn fold_kind(kind: SyntaxKind) -> Option { USE => Some(FoldKind::Imports), ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList), RECORD_FIELD_LIST - | RECORD_FIELD_PAT_LIST + | RECORD_PAT_FIELD_LIST | RECORD_EXPR_FIELD_LIST | ITEM_LIST | EXTERN_ITEM_LIST -- cgit v1.2.3 From 98181087984157e27faba0b969e384f3c62c39d5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:09:09 +0200 Subject: Rename BindPat -> IdentPat --- crates/ra_ide/src/completion/completion_context.rs | 2 +- crates/ra_ide/src/completion/patterns.rs | 2 +- crates/ra_ide/src/display/navigation_target.rs | 4 ++-- crates/ra_ide/src/inlay_hints.rs | 14 +++++++++----- crates/ra_ide/src/references.rs | 14 +++++++------- crates/ra_ide/src/syntax_highlighting.rs | 2 +- 6 files changed, 21 insertions(+), 17 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 29955754c..6b03b30bb 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -275,7 +275,7 @@ impl<'a> CompletionContext<'a> { // Otherwise, see if this is a declaration. We can use heuristics to // suggest declaration names, see `CompletionKind::Magic`. 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) { + if let Some(bind_pat) = name.syntax().ancestors().find_map(ast::IdentPat::cast) { self.is_pat_binding_or_const = true; if bind_pat.at_token().is_some() || bind_pat.ref_token().is_some() diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index 9e654b373..7c4feff6d 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -44,7 +44,7 @@ fn test_has_block_expr_parent() { } pub(crate) fn has_bind_pat_parent(element: SyntaxElement) -> bool { - element.ancestors().find(|it| it.kind() == BIND_PAT).is_some() + element.ancestors().find(|it| it.kind() == IDENT_PAT).is_some() } #[test] fn test_has_bind_pat_parent() { diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index 45fbc86ef..d70e33e72 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -7,7 +7,7 @@ use ra_ide_db::{defs::Definition, RootDatabase}; use ra_syntax::{ ast::{self, DocCommentsOwner, NameOwner}, match_ast, AstNode, SmolStr, - SyntaxKind::{self, BIND_PAT, TYPE_PARAM}, + SyntaxKind::{self, IDENT_PAT, TYPE_PARAM}, TextRange, }; @@ -339,7 +339,7 @@ impl ToNav for hir::Local { NavigationTarget { file_id: full_range.file_id, name, - kind: BIND_PAT, + kind: IDENT_PAT, full_range: full_range.range, focus_range: None, container_name: None, diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 4bbbcd258..1bacead63 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -78,7 +78,7 @@ pub(crate) fn inlay_hints( match node { ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); }, ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, config, ast::Expr::from(it)); }, - ast::BindPat(it) => { get_bind_pat_hints(&mut res, &sema, config, it); }, + ast::IdentPat(it) => { get_bind_pat_hints(&mut res, &sema, config, it); }, _ => (), } } @@ -161,7 +161,7 @@ fn get_param_name_hints( Either::Left(self_param) => Some((self_param.to_string(), arg)), Either::Right(pat) => { let param_name = match pat { - ast::Pat::BindPat(it) => it.name()?.to_string(), + ast::Pat::IdentPat(it) => it.name()?.to_string(), it => it.to_string(), }; Some((param_name, arg)) @@ -182,7 +182,7 @@ fn get_bind_pat_hints( acc: &mut Vec, sema: &Semantics, config: &InlayHintsConfig, - pat: ast::BindPat, + pat: ast::IdentPat, ) -> Option<()> { if !config.type_hints { return None; @@ -202,7 +202,7 @@ fn get_bind_pat_hints( Some(()) } -fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::BindPat, pat_ty: &Type) -> bool { +fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::IdentPat, pat_ty: &Type) -> bool { if let Some(Adt::Enum(enum_data)) = pat_ty.as_adt() { let pat_text = bind_pat.to_string(); enum_data @@ -215,7 +215,11 @@ fn pat_is_enum_variant(db: &RootDatabase, bind_pat: &ast::BindPat, pat_ty: &Type } } -fn should_not_display_type_hint(db: &RootDatabase, bind_pat: &ast::BindPat, pat_ty: &Type) -> bool { +fn should_not_display_type_hint( + db: &RootDatabase, + bind_pat: &ast::IdentPat, + pat_ty: &Type, +) -> bool { if pat_ty.is_unknown() { return true; } diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 519e4bf1a..cf456630a 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -150,7 +150,7 @@ fn decl_access(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> Optio let stmt = find_node_at_offset::(syntax, range.start())?; if stmt.initializer().is_some() { let pat = stmt.pat()?; - if let ast::Pat::BindPat(it) = pat { + if let ast::Pat::IdentPat(it) = pat { if it.mut_token().is_some() { return Some(ReferenceAccess::Write); } @@ -290,7 +290,7 @@ fn main() { ); check_result( refs, - "i BIND_PAT FileId(1) 24..25 Other Write", + "i IDENT_PAT FileId(1) 24..25 Other Write", &[ "FileId(1) 50..51 Other Write", "FileId(1) 54..55 Other Read", @@ -316,7 +316,7 @@ fn bar() { ); check_result( refs, - "spam BIND_PAT FileId(1) 19..23 Other", + "spam IDENT_PAT FileId(1) 19..23 Other", &["FileId(1) 34..38 Other Read", "FileId(1) 41..45 Other Read"], ); } @@ -330,7 +330,7 @@ fn foo(i : u32) -> u32 { } "#, ); - check_result(refs, "i BIND_PAT FileId(1) 7..8 Other", &["FileId(1) 29..30 Other Read"]); + check_result(refs, "i IDENT_PAT FileId(1) 7..8 Other", &["FileId(1) 29..30 Other Read"]); } #[test] @@ -342,7 +342,7 @@ fn foo(i<|> : u32) -> u32 { } "#, ); - check_result(refs, "i BIND_PAT FileId(1) 7..8 Other", &["FileId(1) 29..30 Other Read"]); + check_result(refs, "i IDENT_PAT FileId(1) 7..8 Other", &["FileId(1) 29..30 Other Read"]); } #[test] @@ -559,7 +559,7 @@ fn foo() { ); check_result( refs, - "i BIND_PAT FileId(1) 23..24 Other Write", + "i IDENT_PAT FileId(1) 23..24 Other Write", &["FileId(1) 34..35 Other Write", "FileId(1) 38..39 Other Read"], ); } @@ -595,7 +595,7 @@ fn foo() { } "#, ); - check_result(refs, "i BIND_PAT FileId(1) 19..20 Other", &["FileId(1) 26..27 Other Write"]); + check_result(refs, "i IDENT_PAT FileId(1) 19..20 Other", &["FileId(1) 26..27 Other Write"]); } #[test] diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index e3a96f9d5..027fdecd0 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -717,7 +717,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight { CONST => HighlightTag::Constant, STATIC => HighlightTag::Static, VARIANT => HighlightTag::EnumVariant, - BIND_PAT => HighlightTag::Local, + IDENT_PAT => HighlightTag::Local, _ => default, }; -- cgit v1.2.3 From af53d5f4b081ad50d8fe08fc1e107aa6025b2491 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:23:52 +0200 Subject: Rename --- crates/ra_ide/src/display/navigation_target.rs | 2 +- crates/ra_ide/src/file_structure.rs | 4 ++-- crates/ra_ide/src/references/rename.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index d70e33e72..fdbf75abd 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs @@ -253,7 +253,7 @@ impl ToNav for hir::ImplDef { let focus_range = if derive_attr.is_some() { None } else { - src.value.target_type().map(|ty| original_range(db, src.with_value(ty.syntax())).range) + src.value.self_ty().map(|ty| original_range(db, src.with_value(ty.syntax())).range) }; NavigationTarget::from_syntax( diff --git a/crates/ra_ide/src/file_structure.rs b/crates/ra_ide/src/file_structure.rs index ef368651a..87cab4503 100644 --- a/crates/ra_ide/src/file_structure.rs +++ b/crates/ra_ide/src/file_structure.rs @@ -130,8 +130,8 @@ fn structure_node(node: &SyntaxNode) -> Option { ast::Const(it) => decl_with_type_ref(&it, it.ty()), ast::Static(it) => decl_with_type_ref(&it, it.ty()), ast::Impl(it) => { - let target_type = it.target_type()?; - let target_trait = it.target_trait(); + let target_type = it.self_ty()?; + let target_trait = it.trait_(); let label = match target_trait { None => format!("impl {}", target_type.syntax().text()), Some(t) => { diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 96aed7cc7..3cd6c815b 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -194,7 +194,7 @@ fn text_edit_from_self_param( new_name: &str, ) -> Option { fn target_type_name(impl_def: &ast::Impl) -> Option { - if let Some(ast::Type::PathType(p)) = impl_def.target_type() { + if let Some(ast::Type::PathType(p)) = impl_def.self_ty() { return Some(p.path()?.segment()?.name_ref()?.text().to_string()); } None -- cgit v1.2.3 From 22d295ceaaee76dbd555cdeedc0ed7578e66279d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 21:45:29 +0200 Subject: Rename DotDotPat -> RestPat --- crates/ra_ide/src/syntax_highlighting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 027fdecd0..32f34ef10 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -577,7 +577,7 @@ fn highlight_element( _ if element.parent().and_then(ast::RangePat::cast).is_some() => { HighlightTag::Operator.into() } - _ if element.parent().and_then(ast::DotDotPat::cast).is_some() => { + _ if element.parent().and_then(ast::RestPat::cast).is_some() => { HighlightTag::Operator.into() } _ if element.parent().and_then(ast::Attr::cast).is_some() => { -- cgit v1.2.3 From bff8dd094958f1abe2fcfe8fe9f15dc7a7e6b53e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 1 Aug 2020 13:47:19 +0200 Subject: Update grammar --- crates/ra_ide/src/references/rename.rs | 2 +- crates/ra_ide/src/syntax_highlighting.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 3cd6c815b..c8d80fcf7 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -157,7 +157,7 @@ fn rename_to_self( } let first_param = params.params().next()?; let mutable = match first_param.ty() { - Some(ast::Type::ReferenceType(rt)) => rt.mut_token().is_some(), + Some(ast::Type::RefType(rt)) => rt.mut_token().is_some(), _ => return None, // not renaming other types }; diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 32f34ef10..a32ae0165 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -546,7 +546,7 @@ fn highlight_element( T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => { HighlightTag::Macro.into() } - T![*] if element.parent().and_then(ast::PointerType::cast).is_some() => { + T![*] if element.parent().and_then(ast::PtrType::cast).is_some() => { HighlightTag::Keyword.into() } T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => { -- cgit v1.2.3 From f1bbc776c01f88b678d693a3a3d824309e304ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 3 Aug 2020 15:45:39 +0300 Subject: Fold trait declarations --- crates/ra_ide/src/folding_ranges.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/folding_ranges.rs b/crates/ra_ide/src/folding_ranges.rs index 903c34996..0fbc9babd 100644 --- a/crates/ra_ide/src/folding_ranges.rs +++ b/crates/ra_ide/src/folding_ranges.rs @@ -85,7 +85,8 @@ fn fold_kind(kind: SyntaxKind) -> Option { COMMENT => Some(FoldKind::Comment), USE => Some(FoldKind::Imports), ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList), - RECORD_FIELD_LIST + ASSOC_ITEM_LIST + | RECORD_FIELD_LIST | RECORD_PAT_FIELD_LIST | RECORD_EXPR_FIELD_LIST | ITEM_LIST @@ -336,6 +337,26 @@ fn main() { ); } + #[test] + fn test_folds_structs() { + check( + r#" +struct Foo { +} +"#, + ); + } + + #[test] + fn test_folds_traits() { + check( + r#" +trait Foo { +} +"#, + ); + } + #[test] fn test_folds_macros() { check( -- cgit v1.2.3 From cc3eb8531177940ad34ff505f0426151b985daf3 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Tue, 4 Aug 2020 09:23:23 -0400 Subject: Add test showing unresolved module rename --- crates/ra_ide/src/syntax_highlighting/tests.rs | 3 +++ crates/ra_ide/test_data/highlighting.html | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index 87a6e2523..2deee404c 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs @@ -9,6 +9,9 @@ use crate::{mock_analysis::single_file, FileRange, TextRange}; fn test_highlighting() { check_highlighting( r#" +use inner::{self as inner_mod}; +mod inner {} + #[derive(Clone, Debug)] struct Foo { pub x: i32, diff --git a/crates/ra_ide/test_data/highlighting.html b/crates/ra_ide/test_data/highlighting.html index 345a2f023..efd725bcc 100644 --- a/crates/ra_ide/test_data/highlighting.html +++ b/crates/ra_ide/test_data/highlighting.html @@ -35,7 +35,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; } -
#[derive(Clone, Debug)]
+
use inner::{self as inner_mod};
+mod inner {}
+
+#[derive(Clone, Debug)]
 struct Foo {
     pub x: i32,
     pub y: i32,
-- 
cgit v1.2.3


From 4e2e3543c72b5963eb91b94b8180fecf268930e3 Mon Sep 17 00:00:00 2001
From: Paul Daniel Faria 
Date: Tue, 4 Aug 2020 09:28:40 -0400
Subject: When resolving a rename, fallback to the name higher in the use tree
 if the path segment is `self`

---
 crates/ra_ide/test_data/highlighting.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'crates/ra_ide')

diff --git a/crates/ra_ide/test_data/highlighting.html b/crates/ra_ide/test_data/highlighting.html
index efd725bcc..23c25ad8c 100644
--- a/crates/ra_ide/test_data/highlighting.html
+++ b/crates/ra_ide/test_data/highlighting.html
@@ -35,7 +35,7 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 
 .unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
 
-
use inner::{self as inner_mod};
+
use inner::{self as inner_mod};
 mod inner {}
 
 #[derive(Clone, Debug)]
-- 
cgit v1.2.3


From 09d3b7d7a2ae23a0463fadee9ae8cb6a0fa2c4bf Mon Sep 17 00:00:00 2001
From: Aleksey Kladov 
Date: Wed, 5 Aug 2020 19:29:24 +0200
Subject: align names in make

---
 crates/ra_ide/src/diagnostics.rs | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

(limited to 'crates/ra_ide')

diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index dd8a7ffd9..73c0b8275 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -78,8 +78,10 @@ pub(crate) fn diagnostics(
             } else {
                 let mut field_list = d.ast(db);
                 for f in d.missed_fields.iter() {
-                    let field =
-                        make::record_field(make::name_ref(&f.to_string()), Some(make::expr_unit()));
+                    let field = make::record_expr_field(
+                        make::name_ref(&f.to_string()),
+                        Some(make::expr_unit()),
+                    );
                     field_list = field_list.append_field(&field);
                 }
 
@@ -178,9 +180,9 @@ fn missing_struct_field_fix(
     if new_field_type.is_unknown() {
         return None;
     }
-    let new_field = make::record_field_def(
+    let new_field = make::record_field(
         record_expr.field_name()?,
-        make::type_ref(&new_field_type.display_source_code(sema.db, module.into()).ok()?),
+        make::ty(&new_field_type.display_source_code(sema.db, module.into()).ok()?),
     );
 
     let last_field = record_fields.fields().last()?;
-- 
cgit v1.2.3


From 6be528da0de45606498a9755ad2c54f3bc41dc6c Mon Sep 17 00:00:00 2001
From: Paul Daniel Faria 
Date: Thu, 6 Aug 2020 19:58:37 -0400
Subject: Add test for accessing static mut

---
 crates/ra_ide/src/syntax_highlighting/tests.rs | 7 +++++++
 crates/ra_ide/test_data/highlight_unsafe.html  | 7 +++++++
 2 files changed, 14 insertions(+)

(limited to 'crates/ra_ide')

diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index 2deee404c..b9b358022 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -281,6 +281,12 @@ impl HasUnsafeFn {
     unsafe fn unsafe_method(&self) {}
 }
 
+struct TypeForStaticMut {
+    a: u8
+}
+
+static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
+
 fn main() {
     let x = &5 as *const usize;
     unsafe {
@@ -288,6 +294,7 @@ fn main() {
         HasUnsafeFn.unsafe_method();
         let y = *(x);
         let z = -x;
+        let a = global_mut.a;
     }
 }
 "#
diff --git a/crates/ra_ide/test_data/highlight_unsafe.html b/crates/ra_ide/test_data/highlight_unsafe.html
index b81b6f1c3..7c519ef5e 100644
--- a/crates/ra_ide/test_data/highlight_unsafe.html
+++ b/crates/ra_ide/test_data/highlight_unsafe.html
@@ -43,6 +43,12 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
     unsafe fn unsafe_method(&self) {}
 }
 
+struct TypeForStaticMut {
+    a: u8
+}
+
+static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 };
+
 fn main() {
     let x = &5 as *const usize;
     unsafe {
@@ -50,5 +56,6 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
         HasUnsafeFn.unsafe_method();
         let y = *(x);
         let z = -x;
+        let a = global_mut.a;
     }
 }
\ No newline at end of file -- cgit v1.2.3 From 8e657f663d519771ac8ffcd4b52ded8cb381b918 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Thu, 6 Aug 2020 20:07:42 -0400 Subject: Mark static mutable names as unsafe --- crates/ra_ide/src/syntax_highlighting.rs | 1 + crates/ra_ide/test_data/highlight_unsafe.html | 4 ++-- crates/ra_ide/test_data/highlighting.html | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index a32ae0165..89efe71da 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -677,6 +677,7 @@ fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight { let mut h = Highlight::new(HighlightTag::Static); if s.is_mut(db) { h |= HighlightModifier::Mutable; + h |= HighlightModifier::Unsafe; } return h; } diff --git a/crates/ra_ide/test_data/highlight_unsafe.html b/crates/ra_ide/test_data/highlight_unsafe.html index 7c519ef5e..87d8c1556 100644 --- a/crates/ra_ide/test_data/highlight_unsafe.html +++ b/crates/ra_ide/test_data/highlight_unsafe.html @@ -47,7 +47,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd a: u8 } -static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 }; +static mut global_mut: TypeForStaticMut = TypeForStaticMut { a: 0 }; fn main() { let x = &5 as *const usize; @@ -56,6 +56,6 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd HasUnsafeFn.unsafe_method(); let y = *(x); let z = -x; - let a = global_mut.a; + let a = global_mut.a; } }
\ No newline at end of file diff --git a/crates/ra_ide/test_data/highlighting.html b/crates/ra_ide/test_data/highlighting.html index 23c25ad8c..8e0160eee 100644 --- a/crates/ra_ide/test_data/highlighting.html +++ b/crates/ra_ide/test_data/highlighting.html @@ -64,7 +64,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd } } -static mut STATIC_MUT: i32 = 0; +static mut STATIC_MUT: i32 = 0; fn foo<'a, T>() -> T { foo::<'a, i32>() @@ -97,7 +97,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd } unsafe { vec.set_len(0); - STATIC_MUT = 1; + STATIC_MUT = 1; } for e in vec { -- cgit v1.2.3 From a6532905a983c4a3f035fde95ec288dc751f833a Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Thu, 6 Aug 2020 21:15:31 -0400 Subject: Add test for unsafe union field access highlighting --- crates/ra_ide/src/syntax_highlighting/tests.rs | 11 +++++++++++ crates/ra_ide/test_data/highlight_unsafe.html | 11 +++++++++++ 2 files changed, 22 insertions(+) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index 2deee404c..a09422da3 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs @@ -275,6 +275,11 @@ fn test_unsafe_highlighting() { r#" unsafe fn unsafe_fn() {} +union Union { + a: u32, + b: f32, +} + struct HasUnsafeFn; impl HasUnsafeFn { @@ -283,8 +288,14 @@ impl HasUnsafeFn { fn main() { let x = &5 as *const usize; + let u = Union { b: 0 }; unsafe { unsafe_fn(); + let b = u.b; + match u { + Union { b: 0 } => (), + Union { a } => (), + } HasUnsafeFn.unsafe_method(); let y = *(x); let z = -x; diff --git a/crates/ra_ide/test_data/highlight_unsafe.html b/crates/ra_ide/test_data/highlight_unsafe.html index b81b6f1c3..39582b5bb 100644 --- a/crates/ra_ide/test_data/highlight_unsafe.html +++ b/crates/ra_ide/test_data/highlight_unsafe.html @@ -37,6 +37,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
unsafe fn unsafe_fn() {}
 
+union Union {
+    a: u32,
+    b: f32,
+}
+
 struct HasUnsafeFn;
 
 impl HasUnsafeFn {
@@ -45,8 +50,14 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 
 fn main() {
     let x = &5 as *const usize;
+    let u = Union { b: 0 };
     unsafe {
         unsafe_fn();
+        let b = u.b;
+        match u {
+            Union { b: 0 } => (),
+            Union { a } => (),
+        }
         HasUnsafeFn.unsafe_method();
         let y = *(x);
         let z = -x;
-- 
cgit v1.2.3


From 3bf033e54814919f2214ca4e9b73cebc5ba7d86d Mon Sep 17 00:00:00 2001
From: Paul Daniel Faria 
Date: Fri, 7 Aug 2020 09:24:20 -0400
Subject: Add support for unions in inference and lowering

---
 crates/ra_ide/test_data/highlight_unsafe.html | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'crates/ra_ide')

diff --git a/crates/ra_ide/test_data/highlight_unsafe.html b/crates/ra_ide/test_data/highlight_unsafe.html
index 39582b5bb..de70363da 100644
--- a/crates/ra_ide/test_data/highlight_unsafe.html
+++ b/crates/ra_ide/test_data/highlight_unsafe.html
@@ -50,13 +50,13 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 
 fn main() {
     let x = &5 as *const usize;
-    let u = Union { b: 0 };
+    let u = Union { b: 0 };
     unsafe {
         unsafe_fn();
-        let b = u.b;
+        let b = u.b;
         match u {
-            Union { b: 0 } => (),
-            Union { a } => (),
+            Union { b: 0 } => (),
+            Union { a } => (),
         }
         HasUnsafeFn.unsafe_method();
         let y = *(x);
-- 
cgit v1.2.3


From be935b2b56dcbda5a5918d8c600552b0adbb3a96 Mon Sep 17 00:00:00 2001
From: Paul Daniel Faria 
Date: Fri, 7 Aug 2020 09:33:40 -0400
Subject: Apply unsafe semantic highlighting to union field access

---
 crates/ra_ide/src/syntax_highlighting.rs      | 66 +++++++++++++++++++++++----
 crates/ra_ide/test_data/highlight_unsafe.html |  6 +--
 2 files changed, 59 insertions(+), 13 deletions(-)

(limited to 'crates/ra_ide')

diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index a32ae0165..bfe6143ca 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -4,7 +4,7 @@ mod injection;
 #[cfg(test)]
 mod tests;
 
-use hir::{Name, Semantics};
+use hir::{Name, Semantics, VariantDef};
 use ra_ide_db::{
     defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass},
     RootDatabase,
@@ -455,6 +455,18 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option {
     Some(TextRange::new(range_start, range_end))
 }
 
+fn is_possibly_unsafe(name_ref: &ast::NameRef) -> bool {
+    name_ref
+        .syntax()
+        .parent()
+        .and_then(|parent| {
+            ast::FieldExpr::cast(parent.clone())
+                .map(|_| true)
+                .or_else(|| ast::RecordPatField::cast(parent).map(|_| true))
+        })
+        .unwrap_or(false)
+}
+
 fn highlight_element(
     sema: &Semantics,
     bindings_shadow_count: &mut FxHashMap,
@@ -484,10 +496,19 @@ fn highlight_element(
 
             match name_kind {
                 Some(NameClass::Definition(def)) => {
-                    highlight_name(db, def) | HighlightModifier::Definition
+                    highlight_name(db, def, false) | HighlightModifier::Definition
+                }
+                Some(NameClass::ConstReference(def)) => highlight_name(db, def, false),
+                Some(NameClass::FieldShorthand { field, .. }) => {
+                    let mut h = HighlightTag::Field.into();
+                    if let Definition::Field(field) = field {
+                        if let VariantDef::Union(_) = field.parent_def(db) {
+                            h |= HighlightModifier::Unsafe;
+                        }
+                    }
+
+                    h
                 }
-                Some(NameClass::ConstReference(def)) => highlight_name(db, def),
-                Some(NameClass::FieldShorthand { .. }) => HighlightTag::Field.into(),
                 None => highlight_name_by_syntax(name) | HighlightModifier::Definition,
             }
         }
@@ -498,6 +519,7 @@ fn highlight_element(
         }
         NAME_REF => {
             let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap();
+            let possibly_unsafe = is_possibly_unsafe(&name_ref);
             match classify_name_ref(sema, &name_ref) {
                 Some(name_kind) => match name_kind {
                     NameRefClass::Definition(def) => {
@@ -508,11 +530,13 @@ fn highlight_element(
                                 binding_hash = Some(calc_binding_hash(&name, *shadow_count))
                             }
                         };
-                        highlight_name(db, def)
+                        highlight_name(db, def, possibly_unsafe)
                     }
                     NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(),
                 },
-                None if syntactic_name_ref_highlighting => highlight_name_ref_by_syntax(name_ref),
+                None if syntactic_name_ref_highlighting => {
+                    highlight_name_ref_by_syntax(name_ref, sema)
+                }
                 None => HighlightTag::UnresolvedReference.into(),
             }
         }
@@ -652,10 +676,19 @@ fn is_child_of_impl(element: &SyntaxElement) -> bool {
     }
 }
 
-fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight {
+fn highlight_name(db: &RootDatabase, def: Definition, possibly_unsafe: bool) -> Highlight {
     match def {
         Definition::Macro(_) => HighlightTag::Macro,
-        Definition::Field(_) => HighlightTag::Field,
+        Definition::Field(field) => {
+            let mut h = HighlightTag::Field.into();
+            if possibly_unsafe {
+                if let VariantDef::Union(_) = field.parent_def(db) {
+                    h |= HighlightModifier::Unsafe;
+                }
+            }
+
+            return h;
+        }
         Definition::ModuleDef(def) => match def {
             hir::ModuleDef::Module(_) => HighlightTag::Module,
             hir::ModuleDef::Function(func) => {
@@ -724,7 +757,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
     tag.into()
 }
 
-fn highlight_name_ref_by_syntax(name: ast::NameRef) -> Highlight {
+fn highlight_name_ref_by_syntax(name: ast::NameRef, sema: &Semantics) -> Highlight {
     let default = HighlightTag::UnresolvedReference;
 
     let parent = match name.syntax().parent() {
@@ -734,7 +767,20 @@ fn highlight_name_ref_by_syntax(name: ast::NameRef) -> Highlight {
 
     let tag = match parent.kind() {
         METHOD_CALL_EXPR => HighlightTag::Function,
-        FIELD_EXPR => HighlightTag::Field,
+        FIELD_EXPR => {
+            let h = HighlightTag::Field;
+            let is_union = ast::FieldExpr::cast(parent)
+                .and_then(|field_expr| {
+                    let field = sema.resolve_field(&field_expr)?;
+                    Some(if let VariantDef::Union(_) = field.parent_def(sema.db) {
+                        true
+                    } else {
+                        false
+                    })
+                })
+                .unwrap_or(false);
+            return if is_union { h | HighlightModifier::Unsafe } else { h.into() };
+        }
         PATH_SEGMENT => {
             let path = match parent.parent().and_then(ast::Path::cast) {
                 Some(it) => it,
diff --git a/crates/ra_ide/test_data/highlight_unsafe.html b/crates/ra_ide/test_data/highlight_unsafe.html
index de70363da..cfc872832 100644
--- a/crates/ra_ide/test_data/highlight_unsafe.html
+++ b/crates/ra_ide/test_data/highlight_unsafe.html
@@ -53,10 +53,10 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
     let u = Union { b: 0 };
     unsafe {
         unsafe_fn();
-        let b = u.b;
+        let b = u.b;
         match u {
-            Union { b: 0 } => (),
-            Union { a } => (),
+            Union { b: 0 } => (),
+            Union { a } => (),
         }
         HasUnsafeFn.unsafe_method();
         let y = *(x);
-- 
cgit v1.2.3