diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-01-11 22:42:39 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-01-11 22:42:39 +0000 |
commit | bcfd297f4910bbf2305ec859d7cf42b7dca25f57 (patch) | |
tree | c6b53cd774e7baacf213e91b295734852a83f40b /crates/ra_ide | |
parent | e90aa86fbfa716c4028f38d0d22654065011a964 (diff) | |
parent | ccb75f7c979b56bc62b61fadd81903e11a7f5d74 (diff) |
Merge #2727
2727: Qualify paths in 'add impl members' r=flodiebold a=flodiebold
This makes the 'add impl members' assist qualify paths, so that they should resolve to the same thing as in the definition. To do that, it adds an algorithm that finds a path to refer to any item from any module (if possible), which is actually probably the more important part of this PR :smile: It handles visibility, reexports, renamed crates, prelude etc.; I think the only thing that's missing is support for local items. I'm not sure about the performance, since it takes into account every location where the target item has been `pub use`d, and then recursively goes up the module tree; there's probably potential for optimization by memoizing more, but I think the general shape of the algorithm is necessary to handle every case in Rust's module system.
~The 'find path' part is actually pretty complete, I think; I'm still working on the assist (hence the failing tests).~
Fixes #1943.
Co-authored-by: Florian Diebold <[email protected]>
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/expand_macro.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/crates/ra_ide/src/expand_macro.rs b/crates/ra_ide/src/expand_macro.rs index bdbc31704..0f7b6e875 100644 --- a/crates/ra_ide/src/expand_macro.rs +++ b/crates/ra_ide/src/expand_macro.rs | |||
@@ -7,8 +7,7 @@ use rustc_hash::FxHashMap; | |||
7 | 7 | ||
8 | use ra_syntax::{ | 8 | use ra_syntax::{ |
9 | algo::{find_node_at_offset, replace_descendants}, | 9 | algo::{find_node_at_offset, replace_descendants}, |
10 | ast::{self}, | 10 | ast, AstNode, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, WalkEvent, T, |
11 | AstNode, NodeOrToken, SyntaxKind, SyntaxNode, WalkEvent, T, | ||
12 | }; | 11 | }; |
13 | 12 | ||
14 | pub struct ExpandedMacro { | 13 | pub struct ExpandedMacro { |
@@ -43,7 +42,7 @@ fn expand_macro_recur( | |||
43 | let mut expanded: SyntaxNode = db.parse_or_expand(macro_file_id)?; | 42 | let mut expanded: SyntaxNode = db.parse_or_expand(macro_file_id)?; |
44 | 43 | ||
45 | let children = expanded.descendants().filter_map(ast::MacroCall::cast); | 44 | let children = expanded.descendants().filter_map(ast::MacroCall::cast); |
46 | let mut replaces = FxHashMap::default(); | 45 | let mut replaces: FxHashMap<SyntaxElement, SyntaxElement> = FxHashMap::default(); |
47 | 46 | ||
48 | for child in children.into_iter() { | 47 | for child in children.into_iter() { |
49 | let node = hir::InFile::new(macro_file_id, &child); | 48 | let node = hir::InFile::new(macro_file_id, &child); |
@@ -59,7 +58,7 @@ fn expand_macro_recur( | |||
59 | } | 58 | } |
60 | } | 59 | } |
61 | 60 | ||
62 | Some(replace_descendants(&expanded, &replaces)) | 61 | Some(replace_descendants(&expanded, &|n| replaces.get(n).cloned())) |
63 | } | 62 | } |
64 | 63 | ||
65 | // FIXME: It would also be cool to share logic here and in the mbe tests, | 64 | // FIXME: It would also be cool to share logic here and in the mbe tests, |