@@ -330,7 +330,7 @@ private bool EnterIdentifier(ParserRuleContext context, Selection selection, boo
330
330
var name = context . GetText ( ) ;
331
331
var matches = _declarations [ name ] . Where ( IsInScope ) ;
332
332
333
- var declaration = GetClosestScope ( matches ) ;
333
+ var declaration = GetClosestScope ( matches , context ) ;
334
334
if ( declaration != null )
335
335
{
336
336
var reference = new IdentifierReference ( _qualifiedName , name , selection , context , declaration , isAssignmentTarget , hasExplicitLetStatement ) ;
@@ -357,24 +357,29 @@ public override void EnterVsAssign(VBAParser.VsAssignContext context)
357
357
var callStatementD = context . Parent . Parent . Parent as VBAParser . ICS_B_ProcedureCallContext ;
358
358
359
359
var procedureName = string . Empty ;
360
+ ParserRuleContext identifierContext = null ;
360
361
if ( callStatementA != null )
361
362
{
362
363
procedureName = callStatementA . ambiguousIdentifier ( ) . GetText ( ) ;
364
+ identifierContext = callStatementA . ambiguousIdentifier ( ) ;
363
365
}
364
366
else if ( callStatementB != null )
365
367
{
366
368
procedureName = callStatementB . ambiguousIdentifier ( ) . GetText ( ) ;
369
+ identifierContext = callStatementB . ambiguousIdentifier ( ) ;
367
370
}
368
371
else if ( callStatementC != null )
369
372
{
370
373
procedureName = callStatementC . ambiguousIdentifier ( ) . GetText ( ) ;
374
+ identifierContext = callStatementC . ambiguousIdentifier ( ) ;
371
375
}
372
376
else if ( callStatementD != null )
373
377
{
374
378
procedureName = callStatementD . certainIdentifier ( ) . GetText ( ) ;
379
+ identifierContext = callStatementD . certainIdentifier ( ) ;
375
380
}
376
381
377
- var procedure = FindProcedureDeclaration ( procedureName ) ;
382
+ var procedure = FindProcedureDeclaration ( procedureName , identifierContext ) ;
378
383
if ( procedure == null )
379
384
{
380
385
return ;
@@ -393,13 +398,13 @@ public override void EnterVsAssign(VBAParser.VsAssignContext context)
393
398
}
394
399
}
395
400
396
- private Declaration FindProcedureDeclaration ( string procedureName )
401
+ private Declaration FindProcedureDeclaration ( string procedureName , ParserRuleContext context )
397
402
{
398
403
var matches = _declarations [ procedureName ]
399
404
. Where ( declaration => ProcedureDeclarations . Contains ( declaration . DeclarationType ) )
400
405
. Where ( IsInScope ) ;
401
406
402
- var procedure = GetClosestScope ( matches ) ;
407
+ var procedure = GetClosestScope ( matches , context ) ;
403
408
return procedure ;
404
409
}
405
410
@@ -428,7 +433,8 @@ private bool IsInScope(Declaration declaration)
428
433
429
434
if ( ProcedureDeclarations . Contains ( declaration . DeclarationType ) )
430
435
{
431
- if ( declaration . Accessibility == Accessibility . Public )
436
+ if ( declaration . Accessibility == Accessibility . Public
437
+ || declaration . Accessibility == Accessibility . Implicit )
432
438
{
433
439
var result = declaration . Project . Equals ( _qualifiedName . Project ) ;
434
440
return result ;
@@ -443,7 +449,7 @@ private bool IsInScope(Declaration declaration)
443
449
|| IsGlobalProcedure ( declaration ) ;
444
450
}
445
451
446
- private Declaration GetClosestScope ( IEnumerable < Declaration > declarations )
452
+ private Declaration GetClosestScope ( IEnumerable < Declaration > declarations , ParserRuleContext context )
447
453
{
448
454
// this method (as does the rest of Rubberduck) assumes the VBA code is compilable.
449
455
@@ -460,7 +466,25 @@ private Declaration GetClosestScope(IEnumerable<Declaration> declarations)
460
466
return moduleScope ;
461
467
}
462
468
463
- // multiple matches in global scope??
469
+ if ( matches . Count == 1 )
470
+ {
471
+ return matches [ 0 ] ;
472
+ }
473
+
474
+ var memberProcedureCallContext = context . Parent as VBAParser . ICS_B_MemberProcedureCallContext ;
475
+ if ( memberProcedureCallContext != null )
476
+ {
477
+ var parentMemberName = memberProcedureCallContext . implicitCallStmt_InStmt ( ) . Stop . Text ;
478
+ var matchingParents = _declarations . Items . Where ( d => d . IdentifierName == parentMemberName ) ;
479
+
480
+ var matchingParent = matchingParents . FirstOrDefault ( ) ;
481
+ if ( matchingParent != null )
482
+ {
483
+ var parentType = matches . FirstOrDefault ( p => p . ComponentName == matchingParent . AsTypeName ) ;
484
+ return matches . FirstOrDefault ( m => m . ParentScope == parentType . ParentScope ) ;
485
+ }
486
+ }
487
+
464
488
return matches . FirstOrDefault ( ) ;
465
489
}
466
490
0 commit comments