@@ -11,7 +11,7 @@ import {
1111} from 'vscode' ;
1212import { RequestType , RequestType0 } from 'vscode-languageclient' ;
1313import { ConnectionHandler } from '../handler' ;
14- import { PuppetVersionRequest } from '../messages' ;
14+ import { PuppetVersionRequest , PuppetVersionDetails } from '../messages' ;
1515
1616class PuppetFact extends TreeItem {
1717 constructor (
@@ -75,6 +75,46 @@ export class PuppetFactsProvider implements TreeDataProvider<PuppetFact> {
7575 facts is slow.
7676 */
7777 await this . handler . languageClient . onReady ( ) ;
78+
79+ const details = await this . handler . languageClient . sendRequest (
80+ new RequestType0 < PuppetVersionDetails , void , void > ( 'puppet/getVersion' )
81+ ) ;
82+ if ( ! details . factsLoaded ) {
83+ // language server is ready, but hasn't loaded facts yet
84+ return new Promise < PuppetFact [ ] > ( ( resolve , reject ) => {
85+ let count = 0 ;
86+ let handle = setInterval ( async ( ) => {
87+ count ++ ;
88+ if ( count >= 60 ) {
89+ clearInterval ( handle ) ;
90+
91+ const results = await this . handler . languageClient . sendRequest (
92+ new RequestType0 < PuppetFactResponse , void , void > ( 'puppet/getFacts' )
93+ ) ;
94+ this . elements = this . toList ( results . facts ) ;
95+
96+ resolve ( this . elements . map ( ( e ) => e [ 1 ] ) ) ;
97+ }
98+
99+ const details = await this . handler . languageClient . sendRequest (
100+ new RequestType0 < PuppetVersionDetails , void , void > ( 'puppet/getVersion' )
101+ ) ;
102+ if ( details . factsLoaded ) {
103+ clearInterval ( handle ) ;
104+
105+ const results = await this . handler . languageClient . sendRequest (
106+ new RequestType0 < PuppetFactResponse , void , void > ( 'puppet/getFacts' )
107+ ) ;
108+ this . elements = this . toList ( results . facts ) ;
109+
110+ resolve ( this . elements . map ( ( e ) => e [ 1 ] ) ) ;
111+ } else {
112+ // not ready yet
113+ }
114+ } , 1000 ) ;
115+ } ) ;
116+ }
117+
78118 const results = await this . handler . languageClient . sendRequest (
79119 new RequestType0 < PuppetFactResponse , void , void > ( 'puppet/getFacts' )
80120 ) ;
0 commit comments