@@ -25,9 +25,10 @@ pub(crate) enum ImmediateLocation {
25
25
}
26
26
27
27
pub ( crate ) fn determine_location ( tok : SyntaxToken ) -> Option < ImmediateLocation > {
28
- // First "expand" the element we are completing to its maximum so that we can check in what
29
- // context it immediately lies. This for example means if the token is a NameRef at the end of
30
- // a path, we want to look at where the path is in the tree.
28
+ // First walk the element we are completing up to its highest node that has the same text range
29
+ // as the element so that we can check in what context it immediately lies. We only do this for
30
+ // NameRef -> Path as that's the only thing that makes sense to being "expanded" semantically.
31
+ // We only wanna do this if the NameRef is the last segment of the path.
31
32
let node = match tok. parent ( ) . and_then ( ast:: NameLike :: cast) ? {
32
33
ast:: NameLike :: NameRef ( name_ref) => {
33
34
if let Some ( segment) = name_ref. syntax ( ) . parent ( ) . and_then ( ast:: PathSegment :: cast) {
@@ -47,7 +48,20 @@ pub(crate) fn determine_location(tok: SyntaxToken) -> Option<ImmediateLocation>
47
48
it @ ast:: NameLike :: Name ( _) | it @ ast:: NameLike :: Lifetime ( _) => it. syntax ( ) . clone ( ) ,
48
49
} ;
49
50
let parent = match node. parent ( ) {
50
- Some ( parent) => parent,
51
+ Some ( parent) => match ast:: MacroCall :: cast ( parent. clone ( ) ) {
52
+ // When a path is being typed in an (Assoc)ItemList the parser will always emit a macro_call.
53
+ // This is usually fine as the node expansion code above already accounts for that with
54
+ // the ancestors call, but there is one exception to this which is that when an attribute
55
+ // precedes it the code above will not walk the Path to the parent MacroCall as their ranges differ.
56
+ Some ( call)
57
+ if call. excl_token ( ) . is_none ( )
58
+ && call. token_tree ( ) . is_none ( )
59
+ && call. semicolon_token ( ) . is_none ( ) =>
60
+ {
61
+ call. syntax ( ) . parent ( ) ?
62
+ }
63
+ _ => parent,
64
+ } ,
51
65
// SourceFile
52
66
None => {
53
67
return match node. kind ( ) {
0 commit comments