diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-19 13:46:48 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-19 13:46:48 +0000 |
commit | ff415582960dbd91a18a092271c0848d6c90b0ec (patch) | |
tree | c9a1d088b4683a0379eebdc3d374b42e48548ffc /crates/ra_ide/src | |
parent | b560de4117b5195717445b7c8894d39877035655 (diff) | |
parent | 0d5ae89948903bb150b72885c6d9f24dc7a2bb51 (diff) |
Merge #3235
3235: Derive visibility as well r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/references/classify.rs | 23 | ||||
-rw-r--r-- | crates/ra_ide/src/references/search_scope.rs | 2 |
2 files changed, 11 insertions, 14 deletions
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index 2394e68d1..ca5750521 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs | |||
@@ -22,14 +22,14 @@ pub(crate) fn classify_name_ref( | |||
22 | if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { | 22 | if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { |
23 | tested_by!(goto_def_for_methods); | 23 | tested_by!(goto_def_for_methods); |
24 | if let Some(func) = analyzer.resolve_method_call(&method_call) { | 24 | if let Some(func) = analyzer.resolve_method_call(&method_call) { |
25 | return Some(from_module_def(sb.db, func.into())); | 25 | return Some(from_module_def(func.into())); |
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) { | 29 | if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) { |
30 | tested_by!(goto_def_for_fields); | 30 | tested_by!(goto_def_for_fields); |
31 | if let Some(field) = analyzer.resolve_field(&field_expr) { | 31 | if let Some(field) = analyzer.resolve_field(&field_expr) { |
32 | return Some(from_struct_field(sb.db, field)); | 32 | return Some(from_struct_field(field)); |
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
@@ -37,50 +37,47 @@ pub(crate) fn classify_name_ref( | |||
37 | tested_by!(goto_def_for_record_fields); | 37 | tested_by!(goto_def_for_record_fields); |
38 | tested_by!(goto_def_for_field_init_shorthand); | 38 | tested_by!(goto_def_for_field_init_shorthand); |
39 | if let Some(field_def) = analyzer.resolve_record_field(&record_field) { | 39 | if let Some(field_def) = analyzer.resolve_record_field(&record_field) { |
40 | return Some(from_struct_field(sb.db, field_def)); | 40 | return Some(from_struct_field(field_def)); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | // FIXME: find correct container and visibility for each case | ||
45 | let visibility = None; | ||
46 | |||
47 | if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { | 44 | if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { |
48 | tested_by!(goto_def_for_macros); | 45 | tested_by!(goto_def_for_macros); |
49 | if let Some(macro_def) = | 46 | if let Some(macro_def) = |
50 | analyzer.resolve_macro_call(sb.db, name_ref.with_value(¯o_call)) | 47 | analyzer.resolve_macro_call(sb.db, name_ref.with_value(¯o_call)) |
51 | { | 48 | { |
52 | let kind = NameKind::Macro(macro_def); | 49 | let kind = NameKind::Macro(macro_def); |
53 | return Some(NameDefinition { kind, visibility }); | 50 | return Some(NameDefinition { kind }); |
54 | } | 51 | } |
55 | } | 52 | } |
56 | 53 | ||
57 | let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?; | 54 | let path = name_ref.value.syntax().ancestors().find_map(ast::Path::cast)?; |
58 | let resolved = analyzer.resolve_path(sb.db, &path)?; | 55 | let resolved = analyzer.resolve_path(sb.db, &path)?; |
59 | let res = match resolved { | 56 | let res = match resolved { |
60 | PathResolution::Def(def) => from_module_def(sb.db, def), | 57 | PathResolution::Def(def) => from_module_def(def), |
61 | PathResolution::AssocItem(item) => { | 58 | PathResolution::AssocItem(item) => { |
62 | let def = match item { | 59 | let def = match item { |
63 | hir::AssocItem::Function(it) => it.into(), | 60 | hir::AssocItem::Function(it) => it.into(), |
64 | hir::AssocItem::Const(it) => it.into(), | 61 | hir::AssocItem::Const(it) => it.into(), |
65 | hir::AssocItem::TypeAlias(it) => it.into(), | 62 | hir::AssocItem::TypeAlias(it) => it.into(), |
66 | }; | 63 | }; |
67 | from_module_def(sb.db, def) | 64 | from_module_def(def) |
68 | } | 65 | } |
69 | PathResolution::Local(local) => { | 66 | PathResolution::Local(local) => { |
70 | let kind = NameKind::Local(local); | 67 | let kind = NameKind::Local(local); |
71 | NameDefinition { kind, visibility: None } | 68 | NameDefinition { kind } |
72 | } | 69 | } |
73 | PathResolution::TypeParam(par) => { | 70 | PathResolution::TypeParam(par) => { |
74 | let kind = NameKind::TypeParam(par); | 71 | let kind = NameKind::TypeParam(par); |
75 | NameDefinition { kind, visibility } | 72 | NameDefinition { kind } |
76 | } | 73 | } |
77 | PathResolution::Macro(def) => { | 74 | PathResolution::Macro(def) => { |
78 | let kind = NameKind::Macro(def); | 75 | let kind = NameKind::Macro(def); |
79 | NameDefinition { kind, visibility } | 76 | NameDefinition { kind } |
80 | } | 77 | } |
81 | PathResolution::SelfType(impl_block) => { | 78 | PathResolution::SelfType(impl_block) => { |
82 | let kind = NameKind::SelfType(impl_block); | 79 | let kind = NameKind::SelfType(impl_block); |
83 | NameDefinition { kind, visibility } | 80 | NameDefinition { kind } |
84 | } | 81 | } |
85 | }; | 82 | }; |
86 | Some(res) | 83 | Some(res) |
diff --git a/crates/ra_ide/src/references/search_scope.rs b/crates/ra_ide/src/references/search_scope.rs index f9bbe64a4..e5ac12044 100644 --- a/crates/ra_ide/src/references/search_scope.rs +++ b/crates/ra_ide/src/references/search_scope.rs | |||
@@ -43,7 +43,7 @@ impl SearchScope { | |||
43 | return SearchScope::new(res); | 43 | return SearchScope::new(res); |
44 | } | 44 | } |
45 | 45 | ||
46 | let vis = def.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or_default(); | 46 | let vis = def.visibility(db).as_ref().map(|v| v.syntax().to_string()).unwrap_or_default(); |
47 | 47 | ||
48 | if vis.as_str() == "pub(super)" { | 48 | if vis.as_str() == "pub(super)" { |
49 | if let Some(parent_module) = module.parent(db) { | 49 | if let Some(parent_module) = module.parent(db) { |