@@ -557,7 +557,8 @@ private IEnumerable<SingleResultItem> GetNodeAutocompleMLResults()
557557 AutocompleteMLTitle = Resources . AutocompleteNoRecommendationsTitle ;
558558 AutocompleteMLMessage = Resources . AutocompleteNoRecommendationsMessage ;
559559 Analytics . TrackEvent ( Actions . View , Categories . NodeAutoCompleteOperations , "NoRecommendation" ) ;
560- return new List < SingleResultItem > ( ) ;
560+
561+ return TryGetLocalAutoCompleteResult ( ) ;
561562 }
562563 ServiceVersion = MLresults . Version ;
563564 var results = new List < SingleResultItem > ( ) ;
@@ -630,6 +631,90 @@ private IEnumerable<SingleResultItem> GetNodeAutocompleMLResults()
630631
631632 return results ;
632633 }
634+
635+ /// <summary>
636+ /// Use local node help files to at least return one result that will work.
637+ /// </summary>
638+ /// <returns></returns>
639+ private List < SingleResultItem > TryGetLocalAutoCompleteResult ( )
640+ {
641+ var dynamoModel = this . dynamoViewModel . Model ;
642+
643+ var nodeHelpDocPath = new DirectoryInfo ( Path . Combine ( new FileInfo ( Assembly . GetExecutingAssembly ( ) . Location ) . DirectoryName ,
644+ Configurations . DynamoNodeHelpDocs ) ) ;
645+
646+ var selectedNode = this . PortViewModel . NodeViewModel . NodeModel ;
647+ var selectedPortModel = this . PortViewModel . PortModel ;
648+
649+ string nodeFullName ;
650+
651+ switch ( selectedNode )
652+ {
653+ case DSFunction dsFunction :
654+ string fullSignature = dsFunction . FunctionSignature ;
655+ nodeFullName = fullSignature . Split ( '@' ) [ 0 ] ;
656+ break ;
657+ case Function function :
658+ string fullFunctionSignature = function . FunctionSignature . ToString ( ) ;
659+ nodeFullName = fullFunctionSignature . Split ( '@' ) [ 0 ] ;
660+ break ;
661+ default :
662+ nodeFullName = selectedNode . GetType ( ) . ToString ( ) ;
663+ break ;
664+ }
665+
666+ string sampleDynPath = Path . Combine ( nodeHelpDocPath . FullName , $ "{ nodeFullName } .dyn") ;
667+
668+ if ( ! File . Exists ( sampleDynPath ) )
669+ {
670+ var minimumQualifiedName = dynamoViewModel . GetMinimumQualifiedName ( selectedNode ) ;
671+ var shortName = Hash . GetHashFilenameFromString ( minimumQualifiedName ) ;
672+ sampleDynPath = Path . Combine ( nodeHelpDocPath . FullName , $ "{ shortName } .dyn") ;
673+ }
674+
675+ //no help file found, return nothing
676+ if ( ! File . Exists ( sampleDynPath ) )
677+ {
678+ return new List < SingleResultItem > ( ) ;
679+ }
680+
681+ Exception ex ;
682+ DynamoUtilities . PathHelper . isValidJson ( sampleDynPath , out var fileContents , out ex ) ;
683+
684+ //get the workspace model from the sample to lookup the node
685+ var workspace = WorkspaceModel . FromJson ( fileContents , dynamoModel . LibraryServices ,
686+ dynamoModel . EngineController , dynamoModel . Scheduler ,
687+ dynamoModel . NodeFactory , false , false ,
688+ dynamoModel . CustomNodeManager ,
689+ dynamoModel . LinterManager ) ;
690+
691+ var matchingNode = workspace . Nodes
692+ . FirstOrDefault ( n => n . CreationName == selectedNode . CreationName ) ;
693+
694+ //no matching node found, return nothing
695+ if ( matchingNode is null ) return new List < SingleResultItem > ( ) ;
696+
697+ //find the port model and the node to place
698+ NodeModel predictedNode = null ;
699+ PortModel matchingPortModel = null ;
700+ switch ( selectedPortModel . PortType )
701+ {
702+ case PortType . Input :
703+ matchingPortModel = matchingNode . InPorts [ selectedPortModel . Index ] ;
704+ predictedNode = matchingPortModel . Connectors . First ( ) . Start . Owner ;
705+ break ;
706+ case PortType . Output :
707+ matchingPortModel = matchingNode . OutPorts [ selectedPortModel . Index ] ;
708+ predictedNode = matchingPortModel . Connectors . First ( ) . End . Owner ;
709+ break ;
710+ }
711+
712+ if ( predictedNode is null ) return new List < SingleResultItem > ( ) ;
713+
714+ SingleResultItem singleResultItem = new SingleResultItem ( predictedNode , matchingPortModel . Index ) ;
715+ return [ singleResultItem ] ;
716+ }
717+
633718 private T GetGenericAutocompleteResult < T > ( string endpoint )
634719 {
635720 var requestDTO = GenerateRequestForMLAutocomplete ( ) ;
0 commit comments