Skip to content

Rename/Refresh: Code Explorer not updating correctlyΒ #4060

@Nesavi

Description

@Nesavi

This issue is probably related to #4056, #3468 and #3469.

Rubberduck version 2.2.6731.26856

Expected behaviour: Rubberduck renames a field in a class AND updates Code Explorer tree AND updates
references ie. on right-click "Open" Rubberduck takes you to the definition of said field.

Actual behaviour: Rubberdack renames a field in a class but does not update Code Explorer tree and does not update references.

Steps to reproduce error:

  1. Create a new Excel-file.
  2. Alt+F11 to go to VBA editor.
  3. Create a class "TestClass" with the following content:
    Option Explicit
    Public RenameMe As String
  4. Create a named range in Sheet1 of the Excel-file, see attachment "NamedRange.jpg"
  5. Back in the VBA-editor create a module "Module1" with the following content:
    Option Explicit
    Public Sub ClearNamedRange()
    [TestNamedRange].ClearContents
    End Sub
  6. Save and close Excel.
  7. Re-open the Excel file just created and go to VBA-editor.
  8. Open Rubberduck -> Code Explorer
  9. Rename "RenameMe" -> "Renamed"
  10. "RenameMe" still appears in the Code Explorer tree.
  11. Shift the line in which "Renamed" is defined one down and define a new variable "private Id As Long".
  12. Refresh in "Code Explorer" and nothing happens.

The error seems to be related to the code reference to the named range "TestNamedRange". Indeed, remove the
reference in "Module1" and the treeview in "Code Explorer" updates correctly. That is:

  1. In the VBA-editor in "Module1" delete the sub "ClearNamedRange".
  2. Save, close and re-open the Excel-file.
  3. Renaming now works as expected.

Cause of error:

As far as I have been able to figure out the error shows up when handling changes in state in the method
"private void HandleStateChanged(object sender, ParserStateEventArgs e)" defined in the class
"CodeExplorerViewModel". This method executes the following code:

var userDeclarations = _state.DeclarationFinder.AllUserDeclarations
.GroupBy(declaration => declaration.ProjectId)
.ToList();

if (userDeclarations.Any(
grouping => grouping.All(declaration => declaration.DeclarationType != DeclarationType.Project)))
{
return;
}

On the the first execution of the above code, the GroupBy-statement generates exactly one group, but in
subsequent executions it generates two groups, one containing only the named range in question. This
causes the method to return without updating the nodes of the tree.

Attached are also to logs produced in TRACE-mode, one with the reference to the named range in place and one where the reference has been deleted.

Do let me know if the description above is not satisfactory and I will elaborate as best I can.

RubberduckLog After Removing Reference To Named Range.txt
RubberduckLog With Reference to Named Range.txt
code explorer
namedrange

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIdentifies work items for known bugscriticalMarks a bug as a must-fix, showstopper issuefeature-code-explorer

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions