Skip to content
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

Add directory watcher for tsserver and tsc #5127

Merged
merged 18 commits into from
Oct 15, 2015

Conversation

zhengbli
Copy link
Contributor

@zhengbli zhengbli commented Oct 5, 2015

This PR contains the following changes:

  1. Unify the file / directory watcher functions in tsc and tsserver;
  2. For inferred projects, add the ability to detect newly added tsconfig.json files in from the same directory up to the root path;
  3. For configured projects, add the ability to detect implicitly added/removed source files (e.g., when the tsconfig.json file doesn't have a files array, and source files are added to or removed from the directory) from the same directory down recursively. (Fix server doesn't watch for file add/remove #5076, Use new node recursive file watching in tsserver #4643)
  4. For tsconfig.json file without a files array, also added support to detect file addition / removal under tsc --watch. (Fix tsc: watch mode doesn't discover new files #4553)

Points worth notice:
Inferred projects and configured projects have different kinds of directory watchers:

  1. For inferred projects, the sole purpose of a directory watcher is to detect newly added tsconfig.json files; and the addition normally happens from the current path up. Also, it doesn't matter which project the watcher belongs to, all inferred projects can share one set of watchers if their root files happen to be in the same folder.
  2. For configured projects, each project has a recursive directory watcher of the path where its config file is located at. It does matter which project the watcher belongs to.
  3. Currently the recursive watchers are supported in Node 4.0 for both OSX and Windows. If the node version is before that, the recursive watcher might not work reliably.

}

let parsedCommandLine = configFileToParsedCommandLine(configFileName);
let newFileNames = parsedCommandLine.fileNames.map(compilerHost.getCanonicalFileName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ts.map(fileNames, ..) instead

export function copyListRemovingItem<T>(item: T, list: T[]) {
let copiedList: T[] = [];
for (var i = 0, len = list.length; i < len; i++) {
if (list[i] != item) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!==

if (!(--project.projectService.directoryWatchersRefCount[directory])) {
this.log("Close directory watcher for: " + directory);
project.projectService.directoryWatchersForTsconfig[directory].close();
project.projectService.directoryWatchersForTsconfig[directory] = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly use delete

@mhegazy
Copy link
Contributor

mhegazy commented Oct 15, 2015

👍

zhengbli added a commit that referenced this pull request Oct 15, 2015
Add directory watcher for tsserver and tsc
@zhengbli zhengbli merged commit 8864b06 into microsoft:master Oct 15, 2015

export function copyListRemovingItem<T>(item: T, list: T[]) {
let copiedList: T[] = [];
for (var i = 0, len = list.length; i < len; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use for-of

@vladima
Copy link
Contributor

vladima commented Oct 15, 2015

pinging @zhengbli, there are few comments, can you please address them (sorry for the delay)/

@zhengbli
Copy link
Contributor Author

@vladima The code review is addresses at #5263.

@jbrantly
Copy link

This included a breaking API change by renaming parseConfigFile to parseJsonConfigFileContent and parseConfigFileText to parseConfigFileTextToJson

Random aside but a new function copyListRemovingItem is also being exported. Seems like an internal utility function to me but shrug

zhengbli added a commit that referenced this pull request Oct 20, 2015
@mhegazy mhegazy added the Breaking Change Would introduce errors in existing code label Oct 27, 2015
chancancode added a commit to tildeio/broccoli-typescript-compiler that referenced this pull request Nov 4, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Breaking Change Would introduce errors in existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants