Skip to content

Commit eeecc48

Browse files
author
Paul van Brenk
committed
Don't crash when node is missing from hierarchy when trying to remove
1 parent e7656a3 commit eeecc48

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

Nodejs/Product/Nodejs/Project/NodejsFolderNode.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,25 @@ namespace Microsoft.NodejsTools.Project
1010
{
1111
internal class NodejsFolderNode : CommonFolderNode
1212
{
13-
private readonly CommonProjectNode _project;
13+
private readonly CommonProjectNode project;
1414

1515
public NodejsFolderNode(CommonProjectNode root, ProjectElement element) : base(root, element)
1616
{
17-
this._project = root;
17+
this.project = root;
1818
}
1919

2020
public override string Caption => base.Caption;
2121

22-
public override void RemoveChild(HierarchyNode node)
23-
{
24-
base.RemoveChild(node);
25-
}
26-
2722
internal override int IncludeInProject(bool includeChildren)
2823
{
2924
// Include node_modules folder is generally unecessary and can cause VS to hang.
3025
// http://nodejstools.codeplex.com/workitem/1432
3126
// Check if the folder is node_modules, and warn the user to ensure they don't run into this issue or at least set expectations appropriately.
32-
var nodeModulesPath = Path.Combine(this._project.FullPathToChildren, NodejsConstants.NodeModulesFolder);
27+
var nodeModulesPath = Path.Combine(this.project.FullPathToChildren, NodejsConstants.NodeModulesFolder);
3328
if (CommonUtils.IsSameDirectory(nodeModulesPath, this.ItemNode.Url))
3429
{
3530
Utilities.ShowMessageBox(
36-
this._project.Site, Resources.IncludeNodeModulesContent, SR.ProductName, OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
31+
this.project.Site, Resources.IncludeNodeModulesContent, SR.ProductName, OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
3732
return VSConstants.S_OK;
3833
}
3934
return base.IncludeInProject(includeChildren);

Nodejs/Product/Nodejs/SharedProject/HierarchyNode.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -574,28 +574,28 @@ public virtual void RemoveChild(HierarchyNode node)
574574
this.projectMgr.Site.GetUIThread().MustBeCalledFromUIThread();
575575
this.projectMgr.ItemIdMap.Remove(node);
576576

577-
HierarchyNode last = null;
578-
for (var n = this.firstChild; n != null; n = n.nextSibling)
577+
HierarchyNode previous = null;
578+
for (var current = this.firstChild; current != null; current = current.nextSibling)
579579
{
580-
if (n == node)
580+
if (current == node)
581581
{
582-
if (last != null)
582+
if (previous != null)
583583
{
584-
last.nextSibling = n.nextSibling;
584+
previous.nextSibling = current.nextSibling;
585585
}
586-
if (n == this.firstChild)
586+
if (current == this.firstChild)
587587
{
588-
this.firstChild = n.nextSibling;
588+
this.firstChild = current.nextSibling;
589589
}
590590
if (object.ReferenceEquals(node, this.lastChild))
591591
{
592-
this.lastChild = last;
592+
this.lastChild = previous;
593593
}
594594
return;
595595
}
596-
last = n;
596+
previous = current;
597597
}
598-
throw new InvalidOperationException("Node not found");
598+
// Node is no longer in the tree
599599
}
600600

601601
/// <summary>

0 commit comments

Comments
 (0)