Skip to content

Commit 6eb2984

Browse files
authored
fix: remove TSC_NONPOLLING_WATCHER env variable and provide default watchOptions (#1323)
`TSC_NONPOLLING_WATCHER` was used back in the early days to improve file watcher performance, but it prevents files / directories from being moved / renamed. Since TS now provides built-in option to configure file watcher, this environment variable is no longer needed. See https://www.typescriptlang.org/docs/handbook/configuring-watch.html The watch options used are derived from the user defined options in their `tsconfig` combined with the default options provided to the project service via `setHostConfiguration` ([code reference](https://github.com/microsoft/TypeScript/blob/f7ef1540d3c10fb282d1d433d9f2850b28391169/src/server/editorServices.ts#L2985-L2989)). As noted in the documentation for configuration watch options, the default when no watch options are provided falls back to `fs.watchFile` with `250ms` for any file. This would cause the performance issues as seen in #1310. Fixes #750
1 parent 5823b34 commit 6eb2984

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

client/src/client.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,7 @@ function constructArgs(ctx: vscode.ExtensionContext): string[] {
403403

404404
function getServerOptions(ctx: vscode.ExtensionContext, debug: boolean): lsp.NodeModule {
405405
// Environment variables for server process
406-
const prodEnv = {
407-
// Force TypeScript to use the non-polling version of the file watchers.
408-
TSC_NONPOLLING_WATCHER: true,
409-
};
406+
const prodEnv = {};
410407
const devEnv = {
411408
...prodEnv,
412409
NG_DEBUG: true,

integration/lsp/test_utils.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ export function createConnection(serverOptions: ServerOptions): MessageConnectio
3030
}
3131
const server = fork(SERVER_PATH, argv, {
3232
cwd: PROJECT_PATH,
33-
env: {
34-
TSC_NONPOLLING_WATCHER: 'true',
35-
},
3633
// uncomment to debug server process
3734
// execArgv: ['--inspect-brk=9330']
3835
});

server/src/server.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ function main() {
5959
session.info('Angular Language Service is running under DEBUG mode');
6060
}
6161

62-
if (process.env.TSC_NONPOLLING_WATCHER !== 'true') {
63-
session.warn(`Using less efficient polling watcher. Set TSC_NONPOLLING_WATCHER to true.`);
64-
}
65-
6662
session.listen();
6763
}
6864

server/src/session.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ export class Session {
129129
// https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/#smarter-auto-imports
130130
includePackageJsonAutoImports: 'off',
131131
},
132+
watchOptions: {
133+
// Used as watch options when not specified by user's `tsconfig`.
134+
watchFile: ts.WatchFileKind.UseFsEvents,
135+
watchDirectory: ts.WatchDirectoryKind.UseFsEvents,
136+
fallbackPolling: ts.PollingWatchKind.DynamicPriority,
137+
}
132138
});
133139

134140
const pluginConfig: PluginConfig = {

0 commit comments

Comments
 (0)