Skip to content

Normalize ProjectService.currentDirectory - #24139

Merged
Mine Starks (minestarks) merged 2 commits into
microsoft:masterfrom
minestarks:dynamicprojectassert
May 22, 2018
Merged

Normalize ProjectService.currentDirectory#24139
Mine Starks (minestarks) merged 2 commits into
microsoft:masterfrom
minestarks:dynamicprojectassert

Conversation

@minestarks

Copy link
Copy Markdown
Contributor

This was causing spurious asserts in dynamic file projects like:

"False expression: Verbose Debug Information: {"fileName":"^ScriptDocument104 .txt","currentDirectory":"E:/src/TypeScript-VS/VS/LanguageService/Vsix/bin/Debug","hostCurrentDirectory":"E:\\src\\TypeScript-VS\\VS\\LanguageService\\Vsix\\bin\\Debug","openKeys":[]} Dynamic files must always have current directory context since containing external project name will always match the script info name."

And preventing dynamic project creation in VS.

@minestarks

Copy link
Copy Markdown
Contributor Author

FYI Paul van Brenk (@paulvanbrenk)

@paulvanbrenk

Copy link
Copy Markdown
Contributor

👍

Comment thread src/server/editorServices.ts Outdated
Debug.assert(isRootedDiskPath(fileName) || isDynamic || openedByClient, "", () => `${JSON.stringify({ fileName, currentDirectory, hostCurrentDirectory: this.currentDirectory, openKeys: arrayFrom(this.openFilesWithNonRootedDiskPath.keys()) })}\nScript info with non-dynamic relative file name can only be open script info`);
Debug.assert(!isRootedDiskPath(fileName) || this.currentDirectory === currentDirectory || !this.openFilesWithNonRootedDiskPath.has(this.toCanonicalFileName(fileName)), "", () => `${JSON.stringify({ fileName, currentDirectory, hostCurrentDirectory: this.currentDirectory, openKeys: arrayFrom(this.openFilesWithNonRootedDiskPath.keys()) })}\nOpen script files with non rooted disk path opened with current directory context cannot have same canonical names`);
Debug.assert(!isDynamic || this.currentDirectory === currentDirectory, "", () => `${JSON.stringify({ fileName, currentDirectory, hostCurrentDirectory: this.currentDirectory, openKeys: arrayFrom(this.openFilesWithNonRootedDiskPath.keys()) })}\nDynamic files must always have current directory context since containing external project name will always match the script info name.`);
Debug.assert(!isRootedDiskPath(fileName) || toNormalizedPath(this.currentDirectory) === toNormalizedPath(currentDirectory) || !this.openFilesWithNonRootedDiskPath.has(this.toCanonicalFileName(fileName)), "", () => `${JSON.stringify({ fileName, currentDirectory, hostCurrentDirectory: this.currentDirectory, openKeys: arrayFrom(this.openFilesWithNonRootedDiskPath.keys()) })}\nOpen script files with non rooted disk path opened with current directory context cannot have same canonical names`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This doesnt seem like correct fix. You want to make sure this.currentDirectory is normalized when storing itself instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

https://github.com/Microsoft/TypeScript/blob/master/src/server/editorServices.ts#L453 this where you want to shore normalized current directory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doing the normalization when storing currentDirectory in projectService is correct solution.

Comment thread src/server/editorServices.ts Outdated
this.realpathToScriptInfos = createMultiMap();
}
this.currentDirectory = this.host.getCurrentDirectory();
this.currentDirectory = normalizePath(this.host.getCurrentDirectory());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it feasible to set currentDirectory: NormalizedPath now so that the type expresses that it's already been normalized?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. Wasn't familiar with NormalizedPath (still don't quite get it, as it doesn't seem to offer any interesting typechecking?)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's pretty underpowered right now but I'd like it to be more helpful in the future; seems like many of the path-related bugs I've had to fixed would have been caught by more consistent usage.

@minestarks Mine Starks (minestarks) changed the title Debug.assert should use normalized paths to compare Normalize ProjectService.currentDirectory May 15, 2018
@minestarks

Copy link
Copy Markdown
Contributor Author

I'm not very familiar with this code so I'm not too confident I'm testing it effectively. Sheetal Nandi (@sheetalkamat) Ben Lichtman (@uniqueiniquity) counting on your judgment to see if this is a safe change.

@sheetalkamat

Copy link
Copy Markdown
Member

Mine Starks (@minestarks) You want to accept the baseline changes to public API.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants