Skip to content

Commit bbd0c60

Browse files
authored
fix: remove TSC_NONPOLLING_WATCHER env variable and provide default watchOptions (#1323) (#1326)
`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 3d5ccb6 commit bbd0c60

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
@@ -358,10 +358,7 @@ function constructArgs(ctx: vscode.ExtensionContext): string[] {
358358

359359
function getServerOptions(ctx: vscode.ExtensionContext, debug: boolean): lsp.NodeModule {
360360
// Environment variables for server process
361-
const prodEnv = {
362-
// Force TypeScript to use the non-polling version of the file watchers.
363-
TSC_NONPOLLING_WATCHER: true,
364-
};
361+
const prodEnv = {};
365362
const devEnv = {
366363
...prodEnv,
367364
NG_DEBUG: true,

integration/lsp/test_utils.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ export function createConnection(serverOptions: ServerOptions): MessageConnectio
3737
}
3838
const server = fork(SERVER_PATH, argv, {
3939
cwd: PROJECT_PATH,
40-
env: {
41-
TSC_NONPOLLING_WATCHER: 'true',
42-
},
4340
// uncomment to debug server process
4441
// execArgv: ['--inspect-brk=9330']
4542
});

server/src/server.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,4 @@ if (logger.loggingEnabled()) {
5656
if (process.env.NG_DEBUG === 'true') {
5757
session.info('Angular Language Service is running under DEBUG mode');
5858
}
59-
if (process.env.TSC_NONPOLLING_WATCHER !== 'true') {
60-
session.warn(`Using less efficient polling watcher. Set TSC_NONPOLLING_WATCHER to true.`);
61-
}
62-
6359
session.listen();

server/src/session.ts

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

136142
const pluginConfig: PluginConfig = {

0 commit comments

Comments
 (0)