Skip to content

Normalize ProjectService.currentDirectory #24139

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

Merged
merged 2 commits into from
May 22, 2018

Conversation

minestarks
Copy link
Member

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
Member Author

FYI @paulvanbrenk

@paulvanbrenk
Copy link
Contributor

👍

@@ -1817,8 +1817,8 @@ namespace ts.server {
if (!info) {
const isDynamic = isDynamicFileName(fileName);
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
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
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
Member

@sheetalkamat sheetalkamat left a comment

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.

@minestarks minestarks force-pushed the dynamicprojectassert branch from be6bf5b to 298d23d Compare May 15, 2018 21:16
@@ -450,7 +450,7 @@ namespace ts.server {
if (this.host.realpath) {
this.realpathToScriptInfos = createMultiMap();
}
this.currentDirectory = this.host.getCurrentDirectory();
this.currentDirectory = normalizePath(this.host.getCurrentDirectory());
Copy link
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
Member 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
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 minestarks force-pushed the dynamicprojectassert branch from 298d23d to 0ab3c1f Compare May 15, 2018 21:34
@minestarks minestarks changed the title Debug.assert should use normalized paths to compare Normalize ProjectService.currentDirectory May 15, 2018
@minestarks
Copy link
Member Author

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

@sheetalkamat
Copy link
Member

@minestarks You want to accept the baseline changes to public API.

@minestarks minestarks merged commit 5e5c5a7 into microsoft:master May 22, 2018
@mhegazy mhegazy mentioned this pull request May 22, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
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