Merge pull request #24769 from Microsoft/ignoreWindowsUsersFolder

Do not watch folders like "c:/users/username", "c:/users/username/folderAtRoot"
This commit is contained in:
Sheetal Nandi 2018-06-07 14:36:10 -07:00 committed by GitHub
commit 604bebab86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 17 deletions

View File

@ -349,8 +349,32 @@ namespace ts {
return endsWith(dirPath, "/node_modules/@types");
}
function isDirectoryAtleastAtLevelFromFSRoot(dirPath: Path, minLevels: number) {
for (let searchIndex = getRootLength(dirPath); minLevels > 0; minLevels--) {
/**
* Filter out paths like
* "/", "/user", "/user/username", "/user/username/folderAtRoot",
* "c:/", "c:/users", "c:/users/username", "c:/users/username/folderAtRoot", "c:/folderAtRoot"
* @param dirPath
*/
function canWatchDirectory(dirPath: Path) {
const rootLength = getRootLength(dirPath);
if (dirPath.length === rootLength) {
// Ignore "/", "c:/"
return false;
}
const nextDirectorySeparator = dirPath.indexOf(directorySeparator, rootLength);
if (nextDirectorySeparator === -1) {
// ignore "/user", "c:/users" or "c:/folderAtRoot"
return false;
}
if (dirPath.charCodeAt(0) !== CharacterCodes.slash &&
dirPath.substr(rootLength, nextDirectorySeparator).search(/users/i) === -1) {
// Paths like c:/folderAtRoot/subFolder are allowed
return true;
}
for (let searchIndex = nextDirectorySeparator + 1, searchLevels = 2; searchLevels > 0; searchLevels--) {
searchIndex = dirPath.indexOf(directorySeparator, searchIndex) + 1;
if (searchIndex === 0) {
// Folder isnt at expected minimun levels
@ -360,15 +384,6 @@ namespace ts {
return true;
}
function canWatchDirectory(dirPath: Path) {
return isDirectoryAtleastAtLevelFromFSRoot(dirPath,
// When root is "/" do not watch directories like:
// "/", "/user", "/user/username", "/user/username/folderAtRoot"
// When root is "c:/" do not watch directories like:
// "c:/", "c:/folderAtRoot"
dirPath.charCodeAt(0) === CharacterCodes.slash ? 3 : 1);
}
function filterFSRootDirectoriesToWatch(watchPath: DirectoryOfFailedLookupWatch, dirPath: Path): DirectoryOfFailedLookupWatch {
if (!canWatchDirectory(dirPath)) {
watchPath.ignore = true;

View File

@ -7564,8 +7564,8 @@ namespace ts.projectSystem {
});
describe("tsserverProjectSystem Watched recursive directories with windows style file system", () => {
function verifyWatchedDirectories(useProjectAtRoot: boolean) {
const root = useProjectAtRoot ? "c:/" : "c:/myfolder/allproject/";
function verifyWatchedDirectories(rootedPath: string, useProjectAtRoot: boolean) {
const root = useProjectAtRoot ? rootedPath : `${rootedPath}myfolder/allproject/`;
const configFile: File = {
path: root + "project/tsconfig.json",
content: "{}"
@ -7594,12 +7594,22 @@ namespace ts.projectSystem {
].concat(useProjectAtRoot ? [] : [root + nodeModulesAtTypes]), /*recursive*/ true);
}
it("When project is in rootFolder", () => {
verifyWatchedDirectories(/*useProjectAtRoot*/ true);
function verifyRootedDirectoryWatch(rootedPath: string) {
it("When project is in rootFolder of style c:/", () => {
verifyWatchedDirectories(rootedPath, /*useProjectAtRoot*/ true);
});
it("When files at some folder other than root", () => {
verifyWatchedDirectories(rootedPath, /*useProjectAtRoot*/ false);
});
}
describe("for rootFolder of style c:/", () => {
verifyRootedDirectoryWatch("c:/");
});
it("When files at some folder other than root", () => {
verifyWatchedDirectories(/*useProjectAtRoot*/ false);
describe("for rootFolder of style c:/users/username", () => {
verifyRootedDirectoryWatch("c:/users/username/");
});
});