Skip to content

TSServer doesn't respect watchOptions for watchFile #41549

Closed
@gluxon

Description

@gluxon

This seems to be intentional, but it looks like TSServer always uses fixed polling to watch files regardless of editor configured options.

Screen Shot 2020-11-15 at 9 46 45 PM

The relevant code was written 4.5 years ago. Does the TypeScript team plan on revisiting that decision? If not, should the watchFile option have its choices limited to reduce confusion? (I understand that will partly be a VSCode issue if the answer is yes.)

Personally I think it's strange that this is configurable in tsc but not tsserver.


Technical Details:

Here's the watchUtilities.ts call, which passes a WatchOptions arg:

watchFile: (file, callback, pollingInterval, options) => host.watchFile(file, callback, pollingInterval, options),

export interface WatchOptions {
watchFile?: WatchFileKind;
watchDirectory?: WatchDirectoryKind;
fallbackPolling?: PollingWatchKind;
synchronousWatchDirectory?: boolean;
excludeDirectories?: string[];
excludeFiles?: string[];
[option: string]: CompilerOptionsValue | undefined;
}

Here's the implemention in tsserver, which actually overrides the default implementation and ignores the options arg.

sys.watchFile = (fileName, callback) => {
const watchedFile = pollingWatchedFileSet.addFile(fileName, callback);
return {
close: () => pollingWatchedFileSet.removeFile(watchedFile)
};
};

tsserver.log also reports a watchFile option of 3 (WatchFileKind.UseFsEvents), which is incorrect.

Info 40   [19:45:41.986] FileWatcher:: Added:: WatchInfo: /Volumes/git/TypeScript/src/server/types.ts 500 {"watchFile":3,"watchDirectory":0} Project:  WatchType: Closed Script info

TypeScript Version: v4.2.0-dev.20201112

Search Terms:

  • tsserver polling

Steps to Reproduce

Add the following to VSCode settings.json:

{
  "typescript.tsserver.watchOptions": {
    "watchFile": "useFsEvents",
  }
}

Expected behavior:

  • TSServer watches files through FSEvents.
  • Updates to watched source files happen almost immediately.

Actual behavior:

  • TSServer watches files with fixed polling.

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions