Skip to content

Commit

Permalink
fix: remove TSC_NONPOLLING_WATCHER env variable and provide default w…
Browse files Browse the repository at this point in the history
…atchOptions (angular#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 angular#1310.

Fixes angular#750
  • Loading branch information
atscott committed May 4, 2021
1 parent 3d5ccb6 commit f4ffd36
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
5 changes: 1 addition & 4 deletions client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,7 @@ function constructArgs(ctx: vscode.ExtensionContext): string[] {

function getServerOptions(ctx: vscode.ExtensionContext, debug: boolean): lsp.NodeModule {
// Environment variables for server process
const prodEnv = {
// Force TypeScript to use the non-polling version of the file watchers.
TSC_NONPOLLING_WATCHER: true,
};
const prodEnv = {};
const devEnv = {
...prodEnv,
NG_DEBUG: true,
Expand Down
3 changes: 0 additions & 3 deletions integration/lsp/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export function createConnection(serverOptions: ServerOptions): MessageConnectio
}
const server = fork(SERVER_PATH, argv, {
cwd: PROJECT_PATH,
env: {
TSC_NONPOLLING_WATCHER: 'true',
},
// uncomment to debug server process
// execArgv: ['--inspect-brk=9330']
});
Expand Down
4 changes: 0 additions & 4 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,4 @@ if (logger.loggingEnabled()) {
if (process.env.NG_DEBUG === 'true') {
session.info('Angular Language Service is running under DEBUG mode');
}
if (process.env.TSC_NONPOLLING_WATCHER !== 'true') {
session.warn(`Using less efficient polling watcher. Set TSC_NONPOLLING_WATCHER to true.`);
}

session.listen();
6 changes: 6 additions & 0 deletions server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ export class Session {
// https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/#smarter-auto-imports
includePackageJsonAutoImports: 'off',
},
watchOptions: {
// Used as watch options when not specified by user's `tsconfig`.
watchFile: ts.WatchFileKind.UseFsEvents,
watchDirectory: ts.WatchDirectoryKind.UseFsEvents,
fallbackPolling: ts.PollingWatchKind.DynamicPriority,
}
});

const pluginConfig: PluginConfig = {
Expand Down

0 comments on commit f4ffd36

Please sign in to comment.