Skip to content

Commit 37a66ac

Browse files
author
Keen Yee Liau
committed
fix: force enable Ivy and strictTemplates in google3
This commit checks if `typescript` is resolved to the tsdk in google3, and if so set `ivy` and `strictTemplates` to true. Both settings are required for the Angular extension to work in google3.
1 parent 98e6a67 commit 37a66ac

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

server/src/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const session = new Session({
3838
logger,
3939
ngPlugin: NGLANGSVC, // TypeScript allows only package names as plugin names.
4040
resolvedNgLsPath: ng.resolvedPath,
41+
resolvedTsLsPath: ts.resolvedPath,
4142
ivy: options.ivy,
4243
logToConsole: options.logToConsole,
4344
});

server/src/session.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {NgLanguageService} from '@angular/language-service';
9+
import {isNgLanguageService, NgLanguageService, PluginConfig} from '@angular/language-service/api';
1010
import * as ts from 'typescript/lib/tsserverlibrary';
1111
import * as lsp from 'vscode-languageserver/node';
1212

@@ -27,6 +27,7 @@ export interface SessionOptions {
2727
logger: ts.server.Logger;
2828
ngPlugin: string;
2929
resolvedNgLsPath: string;
30+
resolvedTsLsPath: string;
3031
ivy: boolean;
3132
logToConsole: boolean;
3233
}
@@ -110,11 +111,17 @@ export class Session {
110111
},
111112
});
112113

114+
const pluginConfig: PluginConfig = {
115+
angularOnly: true,
116+
ivy: options.ivy,
117+
};
118+
if (options.resolvedTsLsPath.includes('/google3/')) {
119+
pluginConfig.ivy = true;
120+
pluginConfig.forceStrictTemplates = true;
121+
}
113122
projSvc.configurePlugin({
114123
pluginName: options.ngPlugin,
115-
configuration: {
116-
angularOnly: true,
117-
},
124+
configuration: pluginConfig,
118125
});
119126

120127
return projSvc;
@@ -678,7 +685,7 @@ export class Session {
678685
return undefined;
679686
}
680687
const languageService = project.getLanguageService();
681-
if (!isNgLs(languageService)) {
688+
if (!isNgLanguageService(languageService)) {
682689
return undefined;
683690
}
684691
return {
@@ -929,11 +936,6 @@ function toArray<T>(it: ts.Iterator<T>): T[] {
929936
return results;
930937
}
931938

932-
// TODO: Replace with `isNgLanguageService` from `@angular/language-service`.
933-
function isNgLs(ls: ts.LanguageService|NgLanguageService): ls is NgLanguageService {
934-
return 'getTcb' in ls;
935-
}
936-
937939
function isAngularCore(path: string): boolean {
938940
return isExternalAngularCore(path) || isInternalAngularCore(path);
939941
}

0 commit comments

Comments
 (0)