From a92ad59a02665672921ded490ca2103bd57d9af1 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 22 Nov 2019 12:04:20 +0800 Subject: More correct expand macro --- crates/ra_ide_api/src/expand_macro.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/expand_macro.rs b/crates/ra_ide_api/src/expand_macro.rs index 7dbf33a16..673301b10 100644 --- a/crates/ra_ide_api/src/expand_macro.rs +++ b/crates/ra_ide_api/src/expand_macro.rs @@ -40,7 +40,7 @@ fn expand_macro_recur( let analyzer = hir::SourceAnalyzer::new(db, source, None); let expansion = analyzer.expand(db, macro_call)?; let macro_file_id = expansion.file_id(); - let expanded: SyntaxNode = db.parse_or_expand(macro_file_id)?; + let mut expanded: SyntaxNode = db.parse_or_expand(macro_file_id)?; let children = expanded.descendants().filter_map(ast::MacroCall::cast); let mut replaces = FxHashMap::default(); @@ -49,7 +49,14 @@ fn expand_macro_recur( let node = hir::Source::new(macro_file_id, &child); let new_node = expand_macro_recur(db, source, node)?; - replaces.insert(child.syntax().clone().into(), new_node.into()); + // Replace the whole node if it is root + // `replace_descendants` will not replace the parent node + // but `SyntaxNode::descendants include itself + if expanded == *child.syntax() { + expanded = new_node; + } else { + replaces.insert(child.syntax().clone().into(), new_node.into()); + } } Some(replace_descendants(&expanded, &replaces)) @@ -217,4 +224,27 @@ fn some_thing() -> u32 { } "###); } + + #[test] + fn macro_expand_match_ast_inside_let_statement() { + let res = check_expand_macro( + r#" + //- /lib.rs + macro_rules! match_ast { + (match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) }; + (match ($node:expr) {}) => {{}}; + } + + fn main() { + let p = f(|it| { + let res = mat<|>ch_ast! { match c {}}; + Some(res) + })?; + } + "#, + ); + + assert_eq!(res.name, "match_ast"); + assert_snapshot!(res.expansion, @r###"{}"###); + } } -- cgit v1.2.3 From e42f9627664cc3c44094e1c4f985270fbfd592b1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 11:27:47 +0300 Subject: Encapsulate Attrs --- crates/ra_ide_api/src/completion/presentation.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index b20329459..cbaf169bf 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -286,10 +286,7 @@ impl Completions { } fn is_deprecated(node: impl Attrs, db: &impl HirDatabase) -> bool { - match node.attrs(db) { - None => false, - Some(attrs) => attrs.iter().any(|x| x.is_simple_atom("deprecated")), - } + node.attrs(db).has_atom("deprecated") } fn has_non_default_type_params(def: hir::GenericDef, db: &db::RootDatabase) -> bool { -- cgit v1.2.3 From a87e9145a67634a5ea8a893ab8b52b3c07108a13 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 11:36:14 +0300 Subject: Rename Atts trait --- crates/ra_ide_api/src/completion/presentation.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index cbaf169bf..bd464d193 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -1,6 +1,6 @@ //! This modules takes care of rendering various definitions as completion items. -use hir::{db::HirDatabase, Attrs, Docs, HasSource, HirDisplay, ScopeDef, Ty, TypeWalk}; +use hir::{db::HirDatabase, Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, Ty, TypeWalk}; use join_to_string::join; use ra_syntax::ast::NameOwner; use test_utils::tested_by; @@ -285,7 +285,7 @@ impl Completions { } } -fn is_deprecated(node: impl Attrs, db: &impl HirDatabase) -> bool { +fn is_deprecated(node: impl HasAttrs, db: &impl HirDatabase) -> bool { node.attrs(db).has_atom("deprecated") } -- cgit v1.2.3 From 2c48fa087b6cc79ebfd81af9daf4a07d8019fd67 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 13:55:03 +0300 Subject: Add support for environment to CrateGraph --- crates/ra_ide_api/src/lib.rs | 4 ++-- crates/ra_ide_api/src/mock_analysis.rs | 12 +++++++++--- crates/ra_ide_api/src/parent_module.rs | 11 +++++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 62ad996bc..cb6c24eaa 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -54,7 +54,7 @@ use std::sync::Arc; use ra_cfg::CfgOptions; use ra_db::{ salsa::{self, ParallelDatabase}, - CheckCanceled, FileLoader, SourceDatabase, + CheckCanceled, Env, FileLoader, SourceDatabase, }; use ra_syntax::{SourceFile, TextRange, TextUnit}; @@ -240,7 +240,7 @@ impl Analysis { // Default to enable test for single file. let mut cfg_options = CfgOptions::default(); cfg_options.insert_atom("test".into()); - crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options); + crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options, Env::default()); change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); change.set_crate_graph(crate_graph); host.apply_change(change); diff --git a/crates/ra_ide_api/src/mock_analysis.rs b/crates/ra_ide_api/src/mock_analysis.rs index 2b1c96dbf..bf8a54932 100644 --- a/crates/ra_ide_api/src/mock_analysis.rs +++ b/crates/ra_ide_api/src/mock_analysis.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use ra_cfg::CfgOptions; -use ra_db::RelativePathBuf; +use ra_db::{Env, RelativePathBuf}; use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; use crate::{ @@ -96,9 +96,15 @@ impl MockAnalysis { let file_id = FileId(i as u32 + 1); let cfg_options = CfgOptions::default(); if path == "/lib.rs" || path == "/main.rs" { - root_crate = Some(crate_graph.add_crate_root(file_id, Edition2018, cfg_options)); + root_crate = Some(crate_graph.add_crate_root( + file_id, + Edition2018, + cfg_options, + Env::default(), + )); } else if path.ends_with("/lib.rs") { - let other_crate = crate_graph.add_crate_root(file_id, Edition2018, cfg_options); + let other_crate = + crate_graph.add_crate_root(file_id, Edition2018, cfg_options, Env::default()); let crate_name = path.parent().unwrap().file_name().unwrap(); if let Some(root_crate) = root_crate { crate_graph.add_dep(root_crate, crate_name.into(), other_crate).unwrap(); diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs index fa232a379..6027e7d54 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs @@ -34,12 +34,14 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec { #[cfg(test)] mod tests { + use ra_cfg::CfgOptions; + use ra_db::Env; + use crate::{ mock_analysis::{analysis_and_position, MockAnalysis}, AnalysisChange, CrateGraph, Edition::Edition2018, }; - use ra_cfg::CfgOptions; #[test] fn test_resolve_parent_module() { @@ -87,7 +89,12 @@ mod tests { assert!(host.analysis().crate_for(mod_file).unwrap().is_empty()); let mut crate_graph = CrateGraph::default(); - let crate_id = crate_graph.add_crate_root(root_file, Edition2018, CfgOptions::default()); + let crate_id = crate_graph.add_crate_root( + root_file, + Edition2018, + CfgOptions::default(), + Env::default(), + ); let mut change = AnalysisChange::new(); change.set_crate_graph(crate_graph); host.apply_change(change); -- cgit v1.2.3 From 78f3b0627cf4a5d34aaf63c7b5a2e1b744a11b14 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 17:10:51 +0300 Subject: Move FunctionData to hir_def --- crates/ra_ide_api/src/call_info.rs | 4 ++-- crates/ra_ide_api/src/change.rs | 2 +- crates/ra_ide_api/src/completion/complete_dot.rs | 3 +-- crates/ra_ide_api/src/completion/complete_path.rs | 6 ++---- crates/ra_ide_api/src/completion/presentation.rs | 15 +++++++++------ 5 files changed, 15 insertions(+), 15 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 41ee81511..7c367230e 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -30,7 +30,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option { - (CallInfo::with_fn(db, it), it.data(db).has_self_param()) + (CallInfo::with_fn(db, it), it.has_self_param(db)) } hir::CallableDef::Struct(it) => (CallInfo::with_struct(db, it)?, false), hir::CallableDef::EnumVariant(it) => (CallInfo::with_enum_variant(db, it)?, false), @@ -38,7 +38,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option { let function = analyzer.resolve_method_call(&expr)?; - (CallInfo::with_fn(db, function), function.data(db).has_self_param()) + (CallInfo::with_fn(db, function), function.has_self_param(db)) } FnCallNode::MacroCallExpr(expr) => { let macro_def = analyzer.resolve_macro_call(db, &expr)?; diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 3c607d5b5..8a05b287f 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs @@ -313,7 +313,7 @@ impl RootDatabase { hir::db::RawItemsQuery hir::db::CrateDefMapQuery hir::db::GenericParamsQuery - hir::db::FnDataQuery + hir::db::FunctionDataQuery hir::db::TypeAliasDataQuery hir::db::ConstDataQuery hir::db::StaticDataQuery diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 4e2c497e1..5a3f9b5f6 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -59,8 +59,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { let mut seen_methods = FxHashSet::default(); ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| { - let data = func.data(ctx.db); - if data.has_self_param() && seen_methods.insert(data.name().clone()) { + if func.has_self_param(ctx.db) && seen_methods.insert(func.name(ctx.db)) { acc.add_function(ctx, func); } None::<()> diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 5d974cf6d..802c7701a 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -53,8 +53,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { ctx.analyzer.iterate_path_candidates(ctx.db, ty.clone(), None, |_ty, item| { match item { hir::AssocItem::Function(func) => { - let data = func.data(ctx.db); - if !data.has_self_param() { + if !func.has_self_param(ctx.db) { acc.add_function(ctx, func); } } @@ -80,8 +79,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { for item in t.items(ctx.db) { match item { hir::AssocItem::Function(func) => { - let data = func.data(ctx.db); - if !data.has_self_param() { + if !func.has_self_param(ctx.db) { acc.add_function(ctx, func); } } diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index bd464d193..50fdb0043 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -199,14 +199,17 @@ impl Completions { name: Option, func: hir::Function, ) { - let data = func.data(ctx.db); - let name = name.unwrap_or_else(|| data.name().to_string()); + let func_name = func.name(ctx.db); + let has_self_param = func.has_self_param(ctx.db); + let params = func.params(ctx.db); + + let name = name.unwrap_or_else(|| func_name.to_string()); let ast_node = func.source(ctx.db).value; let detail = function_label(&ast_node); let mut builder = CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) - .kind(if data.has_self_param() { + .kind(if has_self_param { CompletionItemKind::Method } else { CompletionItemKind::Function @@ -222,10 +225,10 @@ impl Completions { { tested_by!(inserts_parens_for_function_calls); let (snippet, label) = - if data.params().is_empty() || data.has_self_param() && data.params().len() == 1 { - (format!("{}()$0", data.name()), format!("{}()", name)) + if params.is_empty() || has_self_param && params.len() == 1 { + (format!("{}()$0", func_name), format!("{}()", name)) } else { - (format!("{}($0)", data.name()), format!("{}(…)", name)) + (format!("{}($0)", func_name), format!("{}(…)", name)) }; builder = builder.lookup_by(name).label(label).insert_snippet(snippet); } -- cgit v1.2.3 From b315f05cf160a11b9012fcde2a9aefc240e39135 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 17:32:10 +0300 Subject: Move data to a single file --- crates/ra_ide_api/src/completion/presentation.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 50fdb0043..896ad1517 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -224,12 +224,11 @@ impl Completions { && ctx.db.feature_flags.get("completion.insertion.add-call-parenthesis") { tested_by!(inserts_parens_for_function_calls); - let (snippet, label) = - if params.is_empty() || has_self_param && params.len() == 1 { - (format!("{}()$0", func_name), format!("{}()", name)) - } else { - (format!("{}($0)", func_name), format!("{}(…)", name)) - }; + let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { + (format!("{}()$0", func_name), format!("{}()", name)) + } else { + (format!("{}($0)", func_name), format!("{}(…)", name)) + }; builder = builder.lookup_by(name).label(label).insert_snippet(snippet); } -- cgit v1.2.3 From d8caf56dfc9eb3cdddff05b58b954a78cf1b9476 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Nov 2019 21:52:06 +0300 Subject: Uniformalize naming --- crates/ra_ide_api/src/display/function_signature.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs index f42dffc87..d96de4e4c 100644 --- a/crates/ra_ide_api/src/display/function_signature.rs +++ b/crates/ra_ide_api/src/display/function_signature.rs @@ -55,7 +55,7 @@ impl FunctionSignature { pub(crate) fn from_struct(db: &db::RootDatabase, st: hir::Struct) -> Option { let node: ast::StructDef = st.source(db).value; match node.kind() { - ast::StructKind::Named(_) => return None, + ast::StructKind::Record(_) => return None, _ => (), }; @@ -89,7 +89,7 @@ impl FunctionSignature { ) -> Option { let node: ast::EnumVariant = variant.source(db).value; match node.kind() { - ast::StructKind::Named(_) | ast::StructKind::Unit => return None, + ast::StructKind::Record(_) | ast::StructKind::Unit => return None, _ => (), }; -- cgit v1.2.3 From 9c521f00ff118c38cbec730ffae1cee5f465f6ac Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sat, 23 Nov 2019 10:33:14 +0800 Subject: Improve fail case in expand_macro --- crates/ra_ide_api/src/expand_macro.rs | 40 +++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/expand_macro.rs b/crates/ra_ide_api/src/expand_macro.rs index 673301b10..0b540b8cd 100644 --- a/crates/ra_ide_api/src/expand_macro.rs +++ b/crates/ra_ide_api/src/expand_macro.rs @@ -47,15 +47,15 @@ fn expand_macro_recur( for child in children.into_iter() { let node = hir::Source::new(macro_file_id, &child); - let new_node = expand_macro_recur(db, source, node)?; - - // Replace the whole node if it is root - // `replace_descendants` will not replace the parent node - // but `SyntaxNode::descendants include itself - if expanded == *child.syntax() { - expanded = new_node; - } else { - replaces.insert(child.syntax().clone().into(), new_node.into()); + if let Some(new_node) = expand_macro_recur(db, source, node) { + // Replace the whole node if it is root + // `replace_descendants` will not replace the parent node + // but `SyntaxNode::descendants include itself + if expanded == *child.syntax() { + expanded = new_node; + } else { + replaces.insert(child.syntax().clone().into(), new_node.into()); + } } } @@ -247,4 +247,26 @@ fn some_thing() -> u32 { assert_eq!(res.name, "match_ast"); assert_snapshot!(res.expansion, @r###"{}"###); } + + #[test] + fn macro_expand_inner_macro_fail_to_expand() { + let res = check_expand_macro( + r#" + //- /lib.rs + macro_rules! bar { + (BAD) => {}; + } + macro_rules! foo { + () => {bar!()}; + } + + fn main() { + let res = fo<|>o!(); + } + "#, + ); + + assert_eq!(res.name, "foo"); + assert_snapshot!(res.expansion, @r###"bar!()"###); + } } -- cgit v1.2.3 From 958862093e83083b188427246323047a2c9e7bab Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 23 Nov 2019 14:43:38 +0300 Subject: Move docs to hir_def --- crates/ra_ide_api/src/db.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index c96465b6a..7d35d2137 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs @@ -21,7 +21,6 @@ use crate::{ symbol_index::SymbolsDatabaseStorage, hir::db::InternDatabaseStorage, hir::db::AstDatabaseStorage, - hir::db::DefDatabaseStorage, hir::db::DefDatabase2Storage, hir::db::HirDatabaseStorage )] -- cgit v1.2.3 From fc1e543f7abb69b8cab308410fa0a127950ee1c5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 23 Nov 2019 14:44:43 +0300 Subject: Get rid of DefDatabase2 --- crates/ra_ide_api/src/db.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index 7d35d2137..c2a9dcdd1 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs @@ -21,7 +21,7 @@ use crate::{ symbol_index::SymbolsDatabaseStorage, hir::db::InternDatabaseStorage, hir::db::AstDatabaseStorage, - hir::db::DefDatabase2Storage, + hir::db::DefDatabaseStorage, hir::db::HirDatabaseStorage )] #[derive(Debug)] -- cgit v1.2.3 From e5bcb69e4f88c7536b1039a881816cb8f1c1f867 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 23 Nov 2019 16:39:53 +0300 Subject: Hide ImportId --- crates/ra_ide_api/src/completion/complete_path.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 802c7701a..63e25e0bf 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here -use hir::{Adt, Either, PathResolution}; +use hir::{Adt, Either, HasSource, PathResolution}; use ra_syntax::AstNode; use test_utils::tested_by; @@ -27,7 +27,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { } if Some(module) == ctx.module { if let Some(import) = import { - if let Either::A(use_tree) = module.import_source(ctx.db, import) { + if let Either::A(use_tree) = import.source(ctx.db).value { if use_tree.syntax().text_range().contains_inclusive(ctx.offset) { // for `use self::foo<|>`, don't suggest `foo` as a completion tested_by!(dont_complete_current_use); -- cgit v1.2.3 From 4b74fb1d896ce5a1c8c4c4bf73ad2940fb86abc5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 16:03:02 +0300 Subject: Nicer API for attrs --- crates/ra_ide_api/src/completion/presentation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 896ad1517..bac3f7582 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -288,7 +288,7 @@ impl Completions { } fn is_deprecated(node: impl HasAttrs, db: &impl HirDatabase) -> bool { - node.attrs(db).has_atom("deprecated") + node.attrs(db).by_key("deprecated").exists() } fn has_non_default_type_params(def: hir::GenericDef, db: &db::RootDatabase) -> bool { -- cgit v1.2.3 From 63e3ea38d3ff7ab69b968e8962f33e82a4f978fb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 20:06:55 +0300 Subject: Don't redo field resolution in the IDE --- crates/ra_ide_api/src/references/classify.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs index 4a4b030f8..cab06dea9 100644 --- a/crates/ra_ide_api/src/references/classify.rs +++ b/crates/ra_ide_api/src/references/classify.rs @@ -1,6 +1,6 @@ //! Functions that are used to classify an element from its definition or reference. -use hir::{FromSource, Module, ModuleSource, Path, PathResolution, Source, SourceAnalyzer}; +use hir::{FromSource, Module, ModuleSource, PathResolution, Source, SourceAnalyzer}; use ra_prof::profile; use ra_syntax::{ast, match_ast, AstNode}; use test_utils::tested_by; @@ -140,12 +140,8 @@ pub(crate) fn classify_name_ref( if let Some(record_field) = ast::RecordField::cast(parent.clone()) { tested_by!(goto_definition_works_for_record_fields); - if let Some(record_lit) = record_field.syntax().ancestors().find_map(ast::RecordLit::cast) { - let variant_def = analyzer.resolve_record_literal(&record_lit)?; - let hir_path = Path::from_name_ref(name_ref.value); - let hir_name = hir_path.as_ident()?; - let field = variant_def.field(db, hir_name)?; - return Some(from_struct_field(db, field)); + if let Some(field_def) = analyzer.resolve_record_field(&record_field) { + return Some(from_struct_field(db, field_def)); } } -- cgit v1.2.3 From d06904e90cdc1603ffcb714e70dab83905221f72 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 23:48:39 +0300 Subject: Switch to variant-granularity field type inference --- crates/ra_ide_api/src/change.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 8a05b287f..0f692460d 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs @@ -324,7 +324,7 @@ impl RootDatabase { hir::db::ExprScopesQuery hir::db::InferQuery hir::db::TypeForDefQuery - hir::db::TypeForFieldQuery + hir::db::FieldTypesQuery hir::db::CallableItemSignatureQuery hir::db::GenericPredicatesQuery hir::db::GenericDefaultsQuery -- cgit v1.2.3