Rubberduck icon indicating copy to clipboard operation
Rubberduck copied to clipboard

Sub/Function in Class - references missing between various Projects

Open hwnd-git opened this issue 2 years ago • 4 comments

Rubberduck version information The info below can be copy-paste-completed from the first lines of Rubberduck's log or the About box:

Rubberduck version [2.5.2.5906]
Operating System: [Microsoft Windows NT 10.0.19044.0, x64]
Host Product: [Dassault Systemes Product x64] (Catia v5)
Host Version: [5.28.0.17255]
Host Executable: [CNEXT.EXE]

Description Rubberduck -> Navigate -> Find all referencess... does not seem to work for Subs or Functions located inside a Class, when the Class resides in one Project but is being accessed/invoked in another Project linked through References.

To Reproduce Steps to reproduce the behavior:

  1. Create simple structure: obraz
  • Project 'test1' contains Main_Module with main subroutine. It is referencing Project 'test2' via Tools -> References:
'Main_Module:
Sub CATMain()
    Debug.Print cls.testFunction("xxx")
    Call cls.TestSub
End Sub
  • Project 'test2' contains a private Class 'cCls' and a public instance of this class called 'cls' inside its Module 'Module_with_public_cls':
'cCls:
Public Function testFunction(iStr As String) As String
    testFunction = "testing function: '" & iStr & "'"
End Function

Public Sub TestSub()
    Debug.Print Me.testFunction("Testing SUB")
End Sub
'Module_with_public_cls:
Public cls As New cCls
  1. Click on 'Rubberduck -> Refresh'

  2. Go to class 'cCls' in project 'test2'

  3. Set cursor on 'testFunction'

  4. Click on 'Rubberduck -> Navigate -> Find all references...'

  5. Only two references will be found (contained inside project 'test2'. References to function calls in project 'test1' are missing.

  6. Go to module 'Main_Module'

  7. Set cursor on 'testFunction'

  8. 0 references found

  9. Click on 'Rubberduck -> Refactor -> Rename'. BUG: it wants to rename 'CATMain' instead on 'testFunction'

  10. Repeat steps 3,4.

  11. Click on 'Rubberduck -> Refactor -> Rename'; enter new name; click on OK

  12. Code execution fails as the 'testFunction' name is changed only in project 'test2', while 'CATMain' in project 'test1' still tries to call the function by its old name.

  13. Revert recent refactoring

  14. Repeat step 7.

  15. Set cursor on 'cls'

  16. Only two references found (from project 'test1')

  17. Click on 'Rubberduck -> Refactor -> Rename'; enter new name; click on OK

  18. This time refactoring went OK - 'cls' has been changed in both 'test1' and 'test2'; code executes properly

Expected behavior I would expect Rubberduck finding the references to function calls within various projects, provided that these projects are linked by referencing each other. Especially when the Code Explorer is aware of this connection. Even the native VBA functionality 'Definition' accessible through right click context menu sends the mouse cursor to proper definition in other project.

Screenshots None

Logfile Log has not been created

Additional context Nothing

hwnd-git avatar Jan 06 '23 13:01 hwnd-git

Thanks for the report! Probably a little oversight somewhere in the resolver causing too much filtering and excluding declarations in other projects that should be accessible.

retailcoder avatar Jan 06 '23 13:01 retailcoder

honestly to a certain extent I want to believe that that's by design. After all the number of declarations that needs to be searched is quite large enough already for find references even when not checking all open projects.

Vogel612 avatar Jan 06 '23 14:01 Vogel612

Hm to me that's definitely a scenario (cross-project refs) that should be handled correctly. There's no reason we can get refs for MsgBox but not for exposed classes & their public members in a user-code referenced project.

retailcoder avatar Jan 06 '23 14:01 retailcoder

@Vogel612 I have been wondering it that was intended behavior to maybe reduce the amount of computations needed to analyze all open projects that are referencing each other. But then, why the inconsistency during refactoring? Why can I refactor the name of the public object, and it is renamed in both projects, but can not refactor properly the names of its functions? This is what gave me an impression, that it might be a bug or kind of oversight.

hwnd-git avatar Jan 06 '23 14:01 hwnd-git