mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Expand nodes for findNodes instead of refreshing (#599)
This commit is contained in:
committed by
Karl Burtram
parent
2d4918ad83
commit
92456d50aa
@@ -181,7 +181,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
|||||||
nodePath = path;
|
nodePath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreeNode FindNodeByPath(string path, bool refreshChildren = false)
|
public TreeNode FindNodeByPath(string path, bool expandIfNeeded = false)
|
||||||
{
|
{
|
||||||
TreeNode nodeForPath = ObjectExplorerUtils.FindNode(this, node =>
|
TreeNode nodeForPath = ObjectExplorerUtils.FindNode(this, node =>
|
||||||
{
|
{
|
||||||
@@ -189,7 +189,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
|||||||
}, nodeToFilter =>
|
}, nodeToFilter =>
|
||||||
{
|
{
|
||||||
return path.StartsWith(nodeToFilter.GetNodePath());
|
return path.StartsWith(nodeToFilter.GetNodePath());
|
||||||
}, refreshChildren);
|
}, expandIfNeeded);
|
||||||
|
|
||||||
return nodeForPath;
|
return nodeForPath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
/// determines whether to stop going further up the tree</param>
|
/// determines whether to stop going further up the tree</param>
|
||||||
/// <param name="filter">Predicate function to filter the children when traversing</param>
|
/// <param name="filter">Predicate function to filter the children when traversing</param>
|
||||||
/// <returns>A Tree Node that matches the condition</returns>
|
/// <returns>A Tree Node that matches the condition</returns>
|
||||||
public static TreeNode FindNode(TreeNode node, Predicate<TreeNode> condition, Predicate<TreeNode> filter, bool refreshChildren = false)
|
public static TreeNode FindNode(TreeNode node, Predicate<TreeNode> condition, Predicate<TreeNode> filter, bool expandIfNeeded = false)
|
||||||
{
|
{
|
||||||
if(node == null)
|
if(node == null)
|
||||||
{
|
{
|
||||||
@@ -60,12 +60,12 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
{
|
{
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
var children = refreshChildren && !node.IsAlwaysLeaf ? node.Refresh() : node.GetChildren();
|
var children = expandIfNeeded && !node.IsAlwaysLeaf ? node.Expand() : node.GetChildren();
|
||||||
foreach (var child in children)
|
foreach (var child in children)
|
||||||
{
|
{
|
||||||
if (filter != null && filter(child))
|
if (filter != null && filter(child))
|
||||||
{
|
{
|
||||||
TreeNode childNode = FindNode(child, condition, filter, refreshChildren);
|
TreeNode childNode = FindNode(child, condition, filter, expandIfNeeded);
|
||||||
if (childNode != null)
|
if (childNode != null)
|
||||||
{
|
{
|
||||||
return childNode;
|
return childNode;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Contracts;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
|
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
|
||||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
using Moq.Protected;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
@@ -263,6 +264,21 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
|
|||||||
Assert.Equal(0, foundNodes.Count);
|
Assert.Equal(0, foundNodes.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void FindNodeCanExpandParentNodes()
|
||||||
|
{
|
||||||
|
var mockTreeNode = new Mock<TreeNode>();
|
||||||
|
object[] populateChildrenArguments = { ItExpr.Is<bool>(x => x == false), ItExpr.IsNull<string>() };
|
||||||
|
mockTreeNode.Protected().Setup("PopulateChildren", populateChildrenArguments);
|
||||||
|
mockTreeNode.Object.IsAlwaysLeaf = false;
|
||||||
|
|
||||||
|
// If I try to find a child node of the mock tree node with the expand parameter set to true
|
||||||
|
ObjectExplorerUtils.FindNode(mockTreeNode.Object, node => false, node => false, true);
|
||||||
|
|
||||||
|
// Then PopulateChildren gets called to expand the tree node
|
||||||
|
mockTreeNode.Protected().Verify("PopulateChildren", Times.Once(), populateChildrenArguments);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<SessionCreatedParameters> CreateSession()
|
private async Task<SessionCreatedParameters> CreateSession()
|
||||||
{
|
{
|
||||||
SessionCreatedParameters sessionResult = null;
|
SessionCreatedParameters sessionResult = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user