Skip to content

Commit eb9f287

Browse files
committed
Add local node help lookup as fallback for DNA
1 parent 0b56acf commit eb9f287

4 files changed

Lines changed: 99 additions & 2 deletions

File tree

src/DynamoCore/Models/DynamoModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@ private void SetPeriodicEvaluation(WorkspaceModel ws)
24312431
}
24322432
}
24332433

2434-
private bool OpenJsonFile(
2434+
internal bool OpenJsonFile(
24352435
string filePath,
24362436
string fileContents,
24372437
DynamoPreferencesData dynamoPreferences,

src/DynamoUtilities/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@
3131
[assembly: InternalsVisibleTo("LibraryViewExtensionWebView2")]
3232
[assembly: InternalsVisibleTo("Notifications")]
3333
[assembly: InternalsVisibleTo("SystemTestServices")]
34+
[assembly: InternalsVisibleTo("NodeAutoCompleteViewExtension")]

src/NodeAutoCompleteViewExtension/ViewModels/NodeAutoCompleteBarViewModel.cs

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ private IEnumerable<SingleResultItem> GetNodeAutocompleMLResults()
546546
AutocompleteMLTitle = Resources.AutocompleteNoRecommendationsTitle;
547547
AutocompleteMLMessage = Resources.AutocompleteNoRecommendationsMessage;
548548
Analytics.TrackEvent(Actions.View, Categories.NodeAutoCompleteOperations, "NoRecommendation");
549-
return new List<SingleResultItem>();
549+
550+
return TryGetLocalAutoCompleteResult();
550551
}
551552
ServiceVersion = MLresults.Version;
552553
var results = new List<SingleResultItem>();
@@ -619,6 +620,90 @@ private IEnumerable<SingleResultItem> GetNodeAutocompleMLResults()
619620

620621
return results;
621622
}
623+
624+
/// <summary>
625+
/// Use local node help files to at least return one result that will work.
626+
/// </summary>
627+
/// <returns></returns>
628+
private List<SingleResultItem> TryGetLocalAutoCompleteResult()
629+
{
630+
var dynamoModel = this.dynamoViewModel.Model;
631+
632+
var nodeHelpDocPath = new DirectoryInfo(Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName,
633+
Configurations.DynamoNodeHelpDocs));
634+
635+
var selectedNode = this.PortViewModel.NodeViewModel.NodeModel;
636+
var selectedPortModel = this.PortViewModel.PortModel;
637+
638+
string nodeFullName;
639+
640+
switch (selectedNode)
641+
{
642+
case DSFunction dsFunction:
643+
string fullSignature = dsFunction.FunctionSignature;
644+
nodeFullName = fullSignature.Split('@')[0];
645+
break;
646+
case Function function:
647+
string fullFunctionSignature = function.FunctionSignature.ToString();
648+
nodeFullName = fullFunctionSignature.Split('@')[0];
649+
break;
650+
default:
651+
nodeFullName = selectedNode.GetType().ToString();
652+
break;
653+
}
654+
655+
string sampleDynPath = Path.Combine(nodeHelpDocPath.FullName, $"{nodeFullName}.dyn");
656+
657+
if (!File.Exists(sampleDynPath))
658+
{
659+
var minimumQualifiedName = dynamoViewModel.GetMinimumQualifiedName(selectedNode);
660+
var shortName = Hash.GetHashFilenameFromString(minimumQualifiedName);
661+
sampleDynPath = Path.Combine(nodeHelpDocPath.FullName, $"{shortName}.dyn");
662+
}
663+
664+
//no help file found, return nothing
665+
if (!File.Exists(sampleDynPath))
666+
{
667+
return new List<SingleResultItem>();
668+
}
669+
670+
Exception ex;
671+
DynamoUtilities.PathHelper.isValidJson(sampleDynPath, out var fileContents, out ex);
672+
673+
//get the workspace model from the sample to lookup the node
674+
var workspace = WorkspaceModel.FromJson(fileContents, dynamoModel.LibraryServices,
675+
dynamoModel.EngineController, dynamoModel.Scheduler,
676+
dynamoModel.NodeFactory, false, false,
677+
dynamoModel.CustomNodeManager,
678+
dynamoModel.LinterManager);
679+
680+
var matchingNode = workspace.Nodes
681+
.FirstOrDefault(n => n.CreationName == selectedNode.CreationName);
682+
683+
//no matching node found, return nothing
684+
if (matchingNode is null) return new List<SingleResultItem>();
685+
686+
//find the port model and the node to place
687+
NodeModel predictedNode = null;
688+
PortModel matchingPortModel = null;
689+
switch (selectedPortModel.PortType)
690+
{
691+
case PortType.Input:
692+
matchingPortModel = matchingNode.InPorts[selectedPortModel.Index];
693+
predictedNode = matchingPortModel.Connectors.First().Start.Owner;
694+
break;
695+
case PortType.Output:
696+
matchingPortModel = matchingNode.OutPorts[selectedPortModel.Index];
697+
predictedNode = matchingPortModel.Connectors.First().End.Owner;
698+
break;
699+
}
700+
701+
if (predictedNode is null) return new List<SingleResultItem>();
702+
703+
SingleResultItem singleResultItem = new SingleResultItem(predictedNode, matchingPortModel.Index);
704+
return [singleResultItem];
705+
}
706+
622707
private T GetGenericAutocompleteResult<T>(string endpoint)
623708
{
624709
var requestDTO = GenerateRequestForMLAutocomplete();

src/NodeAutoCompleteViewExtension/ViewModels/SingleResultItem.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Dynamo.Graph.Nodes;
12
using Dynamo.Search.SearchElements;
23
using Dynamo.Wpf.ViewModels;
34

@@ -17,6 +18,16 @@ public SingleResultItem(NodeSearchElement model, double score = 1.0)
1718
Score = score;
1819
}
1920

21+
public SingleResultItem(NodeModel nodeModel, int portToConnect, double score = 1.0)
22+
{
23+
Assembly = nodeModel.GetType().Assembly.GetName().Name;
24+
IconName = nodeModel.GetType().Name;
25+
Description = nodeModel.Name;
26+
CreationName = nodeModel.CreationName;
27+
PortToConnect = portToConnect;
28+
Score = score;
29+
}
30+
2031
public SingleResultItem(NodeSearchElementViewModel x) : this(x.Model)
2132
{
2233
//Convert percent to probability

0 commit comments

Comments
 (0)