@@ -100,6 +100,11 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
100100 */
101101 protected $ globalIndex ;
102102
103+ /**
104+ * @var ProjectIndex
105+ */
106+ protected $ projectIndex ;
107+
103108 /**
104109 * @var DefinitionResolver
105110 */
@@ -182,21 +187,22 @@ public function initialize(ClientCapabilities $capabilities, string $rootPath =
182187
183188 $ dependenciesIndex = new DependenciesIndex ;
184189 $ sourceIndex = new Index ;
185- $ projectIndex = new ProjectIndex ($ sourceIndex , $ dependenciesIndex );
190+ $ this -> projectIndex = new ProjectIndex ($ sourceIndex , $ dependenciesIndex );
186191 $ stubsIndex = StubsIndex::read ();
187- $ this ->globalIndex = new GlobalIndex ($ stubsIndex , $ projectIndex );
192+ $ this ->globalIndex = new GlobalIndex ($ stubsIndex , $ this -> projectIndex );
188193
189194 // The DefinitionResolver should look in stubs, the project source and dependencies
190195 $ this ->definitionResolver = new DefinitionResolver ($ this ->globalIndex );
191196
192197 $ this ->documentLoader = new PhpDocumentLoader (
193198 $ this ->contentRetriever ,
194- $ projectIndex ,
199+ $ this -> projectIndex ,
195200 $ this ->definitionResolver
196201 );
197202
198203 if ($ rootPath !== null ) {
199- yield $ this ->index ($ rootPath );
204+ yield $ this ->beforeIndex ($ rootPath );
205+ $ this ->index ($ rootPath )->otherwise ('\\LanguageServer \\crash ' );
200206 }
201207
202208 // Find composer.json
@@ -225,7 +231,13 @@ public function initialize(ClientCapabilities $capabilities, string $rootPath =
225231 );
226232 }
227233 if ($ this ->workspace === null ) {
228- $ this ->workspace = new Server \Workspace ($ projectIndex , $ dependenciesIndex , $ sourceIndex , $ this ->composerLock , $ this ->documentLoader );
234+ $ this ->workspace = new Server \Workspace (
235+ $ this ->projectIndex ,
236+ $ dependenciesIndex ,
237+ $ sourceIndex ,
238+ $ this ->composerLock ,
239+ $ this ->documentLoader
240+ );
229241 }
230242
231243 $ serverCapabilities = new ServerCapabilities ();
@@ -278,6 +290,15 @@ public function exit()
278290 exit (0 );
279291 }
280292
293+ /**
294+ * Called before indexing, can return a Promise
295+ *
296+ * @param string $rootPath
297+ */
298+ protected function beforeIndex (string $ rootPath )
299+ {
300+ }
301+
281302 /**
282303 * Will read and parse the passed source files in the project and add them to the appropiate indexes
283304 *
@@ -295,8 +316,8 @@ protected function index(string $rootPath): Promise
295316
296317 $ startTime = microtime (true );
297318
298- foreach (['Collecting definitions and static references ' , 'Collecting dynamic references ' ] as $ run ) {
299- $ this ->client ->window ->logMessage (MessageType::INFO , $ run );
319+ foreach (['Collecting definitions and static references ' , 'Collecting dynamic references ' ] as $ run => $ text ) {
320+ $ this ->client ->window ->logMessage (MessageType::INFO , $ text );
300321 foreach ($ uris as $ i => $ uri ) {
301322 if ($ this ->documentLoader ->isOpen ($ uri )) {
302323 continue ;
@@ -325,6 +346,11 @@ protected function index(string $rootPath): Promise
325346 );
326347 }
327348 }
349+ if ($ run === 0 ) {
350+ $ this ->projectIndex ->setStaticComplete ();
351+ } else {
352+ $ this ->projectIndex ->setComplete ();
353+ }
328354 $ duration = (int )(microtime (true ) - $ startTime );
329355 $ mem = (int )(memory_get_usage (true ) / (1024 * 1024 ));
330356 $ this ->client ->window ->logMessage (
0 commit comments