@@ -26,6 +26,39 @@ protected IdentifierReferenceInspectionFromDeclarationsBase(IDeclarationFinderPr
2626 /// </summary>
2727 protected IEnumerable < Declaration > GetQualifierCandidates ( IdentifierReference reference , DeclarationFinder finder )
2828 {
29+ if ( reference . Context . TryGetAncestor < VBAParser . MemberAccessExprContext > ( out var memberAccess ) )
30+ {
31+ var parentModule = Declaration . GetModuleParent ( reference . ParentScoping ) ;
32+ var qualifyingExpression = memberAccess . lExpression ( ) ;
33+ if ( qualifyingExpression is VBAParser . SimpleNameExprContext simpleName )
34+ {
35+ if ( simpleName . GetText ( ) . Equals ( Tokens . Me , System . StringComparison . InvariantCultureIgnoreCase ) )
36+ {
37+ // qualifier is 'Me'
38+ return new [ ] { parentModule } ;
39+ }
40+
41+ // todo get the actual qualifying declaration?
42+ return finder . MatchName ( simpleName . GetText ( ) )
43+ . Where ( candidate => ! candidate . IdentifierName . Equals ( reference . Declaration . IdentifierName , System . StringComparison . InvariantCultureIgnoreCase ) ) ;
44+ }
45+
46+ if ( qualifyingExpression . ChildCount == 1 && qualifyingExpression . GetText ( ) . Equals ( Tokens . Me , System . StringComparison . InvariantCultureIgnoreCase ) )
47+ {
48+ // qualifier is 'Me'
49+ return new [ ] { parentModule } ;
50+ }
51+ }
52+
53+ if ( reference . Context . TryGetAncestor < VBAParser . WithMemberAccessExprContext > ( out var dot ) )
54+ {
55+ // qualifier is a With block
56+ var withBlock = dot . GetAncestor < VBAParser . WithStmtContext > ( ) ;
57+ return finder . ContainedIdentifierReferences ( new QualifiedSelection ( reference . QualifiedModuleName , withBlock . GetSelection ( ) ) )
58+ . Select ( r => r . Declaration ) . Distinct ( )
59+ . Where ( candidate => ! candidate . Equals ( reference . Declaration ) ) ;
60+ }
61+
2962 if ( reference . Context . TryGetAncestor < VBAParser . CallStmtContext > ( out var callStmt ) )
3063 {
3164 if ( reference . Context . TryGetAncestor < VBAParser . LExpressionContext > ( out var lExpression ) )
@@ -47,36 +80,10 @@ protected IEnumerable<Declaration> GetQualifierCandidates(IdentifierReference re
4780 }
4881
4982 // todo get the actual qualifying declaration?
50- return finder . MatchName ( member . lExpression ( ) . children . First ( ) . GetText ( ) ) ;
83+ return finder . MatchName ( member . lExpression ( ) . children . First ( ) . GetText ( ) )
84+ . Where ( candidate => ! candidate . Equals ( reference . Declaration ) ) ;
5185 }
5286 }
53-
54-
55- }
56-
57- if ( reference . Context . TryGetAncestor < VBAParser . MemberAccessExprContext > ( out var memberAccess ) )
58- {
59- var parentModule = Declaration . GetModuleParent ( reference . ParentScoping ) ;
60- var qualifyingExpression = memberAccess . lExpression ( ) ;
61- if ( qualifyingExpression is VBAParser . SimpleNameExprContext simpleName )
62- {
63- if ( simpleName . GetText ( ) . Equals ( Tokens . Me , System . StringComparison . InvariantCultureIgnoreCase ) )
64- {
65- // qualifier is 'Me'
66- return new [ ] { parentModule } ;
67- }
68-
69- // todo get the actual qualifying declaration?
70- return finder . MatchName ( simpleName . GetText ( ) ) ;
71- }
72- }
73-
74- if ( reference . Context . TryGetAncestor < VBAParser . WithMemberAccessExprContext > ( out var dot ) )
75- {
76- // qualifier is a With block
77- var withBlock = dot . GetAncestor < VBAParser . WithStmtContext > ( ) ;
78- return finder . ContainedIdentifierReferences ( new QualifiedSelection ( reference . QualifiedModuleName , withBlock . GetSelection ( ) ) )
79- . Select ( r => r . Declaration ) . Distinct ( ) ;
8087 }
8188
8289 return Enumerable . Empty < Declaration > ( ) ;
0 commit comments