@@ -227,7 +227,7 @@ export class AngularLanguageClient implements vscode.Disposable {
227
227
}
228
228
229
229
// Node module for the language server
230
- const args = this . constructArgs ( ) ;
230
+ const args = await this . constructArgs ( ) ;
231
231
const prodBundle = this . context . asAbsolutePath ( 'server' ) ;
232
232
const devBundle =
233
233
this . context . asAbsolutePath ( path . join ( 'bazel-bin' , 'server' , 'src' , 'server.js' ) ) ;
@@ -289,7 +289,7 @@ export class AngularLanguageClient implements vscode.Disposable {
289
289
* Construct the arguments that's used to spawn the server process.
290
290
* @param ctx vscode extension context
291
291
*/
292
- private constructArgs ( ) : string [ ] {
292
+ private async constructArgs ( ) : Promise < string [ ] > {
293
293
const config = vscode . workspace . getConfiguration ( ) ;
294
294
const args : string [ ] = [ '--logToConsole' ] ;
295
295
@@ -317,8 +317,8 @@ export class AngularLanguageClient implements vscode.Disposable {
317
317
}
318
318
319
319
// Sort the versions from oldest to newest.
320
- const angularVersions = getAngularVersionsInWorkspace ( ) . sort (
321
- ( a , b ) => a . version . greaterThanOrEqual ( b . version ) ? 1 : - 1 ) ;
320
+ const angularVersions = ( await getAngularVersionsInWorkspace ( this . outputChannel ) )
321
+ . sort ( ( a , b ) => a . version . greaterThanOrEqual ( b . version ) ? 1 : - 1 ) ;
322
322
323
323
// Only disable block syntax if we find angular/core and every one we find does not support
324
324
// block syntax
@@ -552,13 +552,22 @@ function extensionVersionCompatibleWithAllProjects(serverModuleLocation: string)
552
552
}
553
553
554
554
/**
555
- * Returns true if any project in the workspace supports block syntax (v17+).
555
+ * Traverses through the currently open VSCode workspace (i.e. all open folders)
556
+ * and finds all `@angular/core` versions installed based on `package.json` files.
556
557
*/
557
- function getAngularVersionsInWorkspace ( ) : NodeModule [ ] {
558
+ async function getAngularVersionsInWorkspace ( outputChannel : vscode . OutputChannel ) :
559
+ Promise < NodeModule [ ] > {
560
+ const packageJsonFiles = await vscode . workspace . findFiles (
561
+ '**/package.json' ,
562
+ // Skip looking inside `node_module` folders as those contain irrelevant files.
563
+ '**/node_modules/**' ) ;
564
+ const packageJsonRoots = packageJsonFiles . map ( f => path . dirname ( f . fsPath ) ) ;
558
565
const angularCoreModules = new Set < NodeModule > ( ) ;
559
- const workspaceFolders = vscode . workspace . workspaceFolders || [ ] ;
560
- for ( const workspaceFolder of workspaceFolders ) {
561
- const angularCore = resolve ( '@angular/core' , workspaceFolder . uri . fsPath ) ;
566
+
567
+ outputChannel . appendLine ( `package.json roots detected: ${ packageJsonRoots . join ( ',\n ' ) } ` ) ;
568
+
569
+ for ( const packageJsonRoot of packageJsonRoots ) {
570
+ const angularCore = resolve ( '@angular/core' , packageJsonRoot ) ;
562
571
if ( angularCore === undefined ) {
563
572
continue ;
564
573
}
0 commit comments