Skip to content

TSServer doesn't respect watchOptions for watchFile #41549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gluxon opened this issue Nov 16, 2020 · 6 comments · Fixed by #42542
Closed

TSServer doesn't respect watchOptions for watchFile #41549

gluxon opened this issue Nov 16, 2020 · 6 comments · Fixed by #42542
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@gluxon
Copy link
Contributor

gluxon commented Nov 16, 2020

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.
@gluxon
Copy link
Contributor Author

gluxon commented Nov 16, 2020

@zhengbli Apologies if you're no longer involved with TypeScript, but if you have a moment I'm curious if it was intentional for this to be non-configurable in tsserver (but configurable in tsc).

@gluxon
Copy link
Contributor Author

gluxon commented Nov 16, 2020

This affects language service plugins that provide typings for imported files.

mrmckeb/typescript-plugin-css-modules#95

To summarize, I'm trying to set up CSS type checks but not seeing updates happen until 7+ minutes later due to tsserver's polling watch being slow.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Nov 16, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.2.1 milestone Nov 16, 2020
@dko-slapdash
Copy link

dko-slapdash commented Nov 24, 2020

What an awesome improvement would it be at least on MacOS VSCode! We currently wait for 20-40 seconds after a git pull for some files to be typechecked properly in VSCode. I made an experiment, manually commented out the code @gluxon mentioned above right in tsserver.js:

image

and it made VSCode pickup changes within several seconds.

@ericjeney
Copy link

@sheetalkamat Do you have any updates on whether this is something that the TypeScript team is interested in accepting a fix for? This is the only thing blocking my team from adding type-safety to the last untyped piece of our codebase (CSS modules).

@sheetalkamat
Copy link
Member

This is scheduled for 4.2.1

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Jan 28, 2021
sheetalkamat added a commit that referenced this issue Mar 3, 2021
…rver (#42542)

* Move fixed chunk size polling as a watch option and move it out of server
Fixes #41549

* Feedback
@gluxon
Copy link
Contributor Author

gluxon commented Mar 3, 2021

@sheetalkamat Thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants