@@ -307,16 +307,26 @@ export class AngularLanguageClient implements vscode.Disposable {
307307 args . push ( '--includeCompletionsWithSnippetText' ) ;
308308 }
309309
310- const angularVersions = getAngularVersionsInWorkspace ( ) ;
310+ // Sort the versions from oldest to newest.
311+ const angularVersions = getAngularVersionsInWorkspace ( ) . sort (
312+ ( a , b ) => a . version . greaterThanOrEqual ( b . version ) ? 1 : - 1 ) ;
313+
311314 // Only disable block syntax if we find angular/core and every one we find does not support
312315 // block syntax
313- if ( angularVersions . size > 0 && Array . from ( angularVersions ) . every ( v => v . version . major < 17 ) ) {
316+ if ( angularVersions . length > 0 && angularVersions . every ( v => v . version . major < 17 ) ) {
314317 args . push ( '--disableBlockSyntax' ) ;
315318 this . outputChannel . appendLine (
316319 `All workspace roots are using versions of Angular that do not support control flow block syntax.` +
317320 ` Block syntax parsing in templates will be disabled.` ) ;
318321 }
319322
323+ // Pass the earliest Angular version along to the compiler for maximum compatibility.
324+ if ( angularVersions . length > 0 ) {
325+ args . push ( '--angularCoreVersion' , angularVersions [ 0 ] . version . toString ( ) ) ;
326+ this . outputChannel . appendLine (
327+ `Using Angular version ${ angularVersions [ 0 ] . version . toString ( ) } .` ) ;
328+ }
329+
320330 const forceStrictTemplates = config . get < boolean > ( 'angular.forceStrictTemplates' ) ;
321331 if ( forceStrictTemplates ) {
322332 args . push ( '--forceStrictTemplates' ) ;
@@ -515,7 +525,7 @@ function extensionVersionCompatibleWithAllProjects(serverModuleLocation: string)
515525/**
516526 * Returns true if any project in the workspace supports block syntax (v17+).
517527 */
518- function getAngularVersionsInWorkspace ( ) : Set < NodeModule > {
528+ function getAngularVersionsInWorkspace ( ) : NodeModule [ ] {
519529 const angularCoreModules = new Set < NodeModule > ( ) ;
520530 const workspaceFolders = vscode . workspace . workspaceFolders || [ ] ;
521531 for ( const workspaceFolder of workspaceFolders ) {
@@ -525,5 +535,5 @@ function getAngularVersionsInWorkspace(): Set<NodeModule> {
525535 }
526536 angularCoreModules . add ( angularCore ) ;
527537 }
528- return angularCoreModules ;
538+ return Array . from ( angularCoreModules ) ;
529539}
0 commit comments