Skip to content

Commit 8680168

Browse files
Keen Yee Liaukyliau
authored andcommitted
fix: do not watch directories in google3
In google3, all the dependencies of a TypeScript program are known ahead of time and they are listed in `tsconfig.json`. For this reason, there is no need to watch `node_modules` directory. Tsserver in google3 has additonal patch that explicitly prohibits watching directories that start with `/google/src`. This was not detected during development because we did not actually use the TypeScript module specified in `typescript.tsdk`. The dynamic loading of the `typescript` module requires the server code to be compiled in AMD first, which happens only during the production build.
1 parent af167d7 commit 8680168

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

server/src/server.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@ const logger = createLogger({
2727
});
2828

2929
const ts = resolveTsServer(options.tsProbeLocations);
30-
const ng = resolveNgLangSvc(options.ngProbeLocations, options.ivy);
30+
const isG3 = ts.resolvedPath.includes('/google3/');
31+
const ivy = isG3 ? true : options.ivy;
32+
const ng = resolveNgLangSvc(options.ngProbeLocations, ivy);
3133

3234
// ServerHost provides native OS functionality
33-
const host = new ServerHost(options.ivy);
35+
const host = new ServerHost(ivy, isG3);
3436

3537
// Establish a new server session that encapsulates lsp connection.
3638
const session = new Session({
3739
host,
3840
logger,
3941
ngPlugin: NGLANGSVC, // TypeScript allows only package names as plugin names.
4042
resolvedNgLsPath: ng.resolvedPath,
41-
resolvedTsLsPath: ts.resolvedPath,
42-
ivy: options.ivy,
43+
ivy,
4344
logToConsole: options.logToConsole,
4445
});
4546

server/src/server_host.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import * as ts from 'typescript/lib/tsserverlibrary';
1010
import {NGLANGSVC} from './version_provider';
1111

12+
const NOOP_WATCHER: ts.FileWatcher = {
13+
close() {},
14+
};
15+
1216
/**
1317
* `ServerHost` is a wrapper around `ts.sys` for the Node system. In Node, all
1418
* optional methods of `ts.System` are implemented.
@@ -20,7 +24,7 @@ export class ServerHost implements ts.server.ServerHost {
2024
readonly newLine: string;
2125
readonly useCaseSensitiveFileNames: boolean;
2226

23-
constructor(private ivy: boolean) {
27+
constructor(private ivy: boolean, readonly isG3: boolean) {
2428
this.args = ts.sys.args;
2529
this.newLine = ts.sys.newLine;
2630
this.useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames;
@@ -57,6 +61,9 @@ export class ServerHost implements ts.server.ServerHost {
5761

5862
watchDirectory(path: string, callback: ts.DirectoryWatcherCallback, recursive?: boolean):
5963
ts.FileWatcher {
64+
if (this.isG3 && path.startsWith('/google/src')) {
65+
return NOOP_WATCHER;
66+
}
6067
return ts.sys.watchDirectory!(path, callback, recursive);
6168
}
6269

server/src/session.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import {isNgLanguageService, NgLanguageService, PluginConfig} from '@angular/language-service/api';
10+
import * as assert from 'assert';
1011
import * as ts from 'typescript/lib/tsserverlibrary';
1112
import * as lsp from 'vscode-languageserver/node';
1213

@@ -27,7 +28,6 @@ export interface SessionOptions {
2728
logger: ts.server.Logger;
2829
ngPlugin: string;
2930
resolvedNgLsPath: string;
30-
resolvedTsLsPath: string;
3131
ivy: boolean;
3232
logToConsole: boolean;
3333
}
@@ -115,8 +115,8 @@ export class Session {
115115
angularOnly: true,
116116
ivy: options.ivy,
117117
};
118-
if (options.resolvedTsLsPath.includes('/google3/')) {
119-
pluginConfig.ivy = true;
118+
if (options.host.isG3) {
119+
assert(options.ivy === true, 'Ivy LS must be used in google3');
120120
pluginConfig.forceStrictTemplates = true;
121121
}
122122
projSvc.configurePlugin({

0 commit comments

Comments
 (0)