@@ -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 ( ) ;
0 commit comments