Skip to content

Canonicalize path before calling startsWith - #25364

Merged
3 commits merged into
masterfrom
pathStartsWith
Jul 3, 2018
Merged

3 commits merged into
masterfrom
pathStartsWith

Conversation

@ghost

@ghost Deleted user (ghost) commented Jul 2, 2018 •

Copy link
Copy Markdown

@ghost
ghost requested a review from Sheetal Nandi (sheetalkamat) July 2, 2018 15:14
@DanielRosenwasser

Copy link
Copy Markdown
Member

What about test cases? Also, does this fix any of #25358 #24599 #25345 #25186?

@weswigham

Copy link
Copy Markdown
Member

I do agree with Daniel that we probably should err on adding more test coverage tho, considering this is used for paths in declaration emit now, too.

// Get a path that's relative to node_modules or the importing file's path
// if node_modules folder is in this folder or any of its parent folders, no need to keep it.
if (!startsWith(sourceDirectory, moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex))) return undefined;
if (!startsWith(sourceDirectory, getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex)))) return undefined;

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.

Dont you need to do getCanonicalFileName for sourceDirectory as well?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That comes from importingSourceFile.path which should already be canonicalized.

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.

Makes sense. Good that you changed the type there so its easy to catch in future. Thanks.

@mhegazy

Copy link
Copy Markdown
Contributor

Also looks related to #25338

@ghost

Copy link
Copy Markdown
Author

Sheetal Nandi (@sheetalkamat) Do we have any existing case-insensitivity tests? I thought fourslash was case-insensitive but I can't reproduce the error in a fourslash test.

@ghost
ghost force-pushed the pathStartsWith branch from e36f1b9 to 0294132 Compare July 3, 2018 17:25
@sheetalkamat

Copy link
Copy Markdown
Member

you can add it in tsserver unit tests where default host is case insensitive

@ghost
ghost force-pushed the pathStartsWith branch from 0294132 to 140ebcd Compare July 3, 2018 17:28
@ghost

Copy link
Copy Markdown
Author

Figured out why fourslash test wasn't working, I needed to put a capitalized name before the importing directory.

@mhegazy

Copy link
Copy Markdown
Contributor

Andy (Andrewkraft) (@Andy-MS) can you also verify that this change fixes #25358 #24599 #25345 and #25186?

@Kingwl

Copy link
Copy Markdown
Contributor

image

seems fixed on my pc@20180705

@gremo

Copy link
Copy Markdown

I'm running vscode 1.25.0 and typscript 2.9.2, still have this issue. Can anyone help? Thanks

@Kingwl

Copy link
Copy Markdown
Contributor

I'm running vscode 1.25.0 and typscript 2.9.2, still have this issue. Can anyone help? Thanks

  1. install the typescript@next
  2. set typescript tsdk to gloabl typescript lib, eg: /usr/local/lib/node_modules/typescript/lib

@smnbbrv

Copy link
Copy Markdown

This is all cool, but angular cli does not allow to use the newest typescript. What should we do?

@ghost

Copy link
Copy Markdown
Author

Simon Bobrov (@smnbbrv) Just install typescript globally with npm install -g typescript@next and point the editor to that.

@smnbbrv

Copy link
Copy Markdown

Andy (Andrewkraft) (@Andy-MS) thanks, it works!

@ratidzidziguri

Rati Dzidziguri (ratidzidziguri) commented Jul 11, 2018 •

Copy link
Copy Markdown

for me installing @next did not work
image

and still when importing
image

@mhegazy

Copy link
Copy Markdown
Contributor

Rati Dzidziguri (@ratidzidziguri) can you share more info.

@ratidzidziguri

Copy link
Copy Markdown

solution for now was to only set VsCode to use workplace TS version. In my case that is the one installed with angular and it is 2.7.2

@smnbbrv

Copy link
Copy Markdown

Maybe I say bullshit but if the typescript version is so crucial why don’t you guys just bundle it with vscode or at least give users some hint about mismatching typescript versions and the consequences of that? The way how it is done right now is so counter intuitive; it was properly working one version before, then it gets broken and the only way to fix this is using beta versions of typescript; that’s kinda... weird

@mhegazy

Copy link
Copy Markdown
Contributor

The next version of VSCode should include the fix. VSCode insiders tomorrow should include the fix.

If you are on latest VSCode and want to try the fix out, you can find instructions on using a custom version of TS in your VSCode at: Using Newer TypeScript Versions.

@no-stack-dub-sack

Copy link
Copy Markdown

Andy (Andrewkraft) (@Andy-MS) I just installed the latest insiders and am on TS 2.9.2 - you mentioned the new insiders should have the fix - should 2.9.2 + latest insiders be working? I'm still getting the same behavior as when I originally opened the issue.

@no-stack-dub-sack

Copy link
Copy Markdown

☝️ never mind, it does work when I update to @next. So for those dealing with this issue that aren't using insiders and tsnext, will they have to wait until 3.0.0 is shipping with VSCode?

@ratidzidziguri

Copy link
Copy Markdown

For angular developers. till we get some fix, simple solution is to use work-space version instead of VsCodes one which is 2.7.2 in my case and everything works normally after that.

@lucasklaassen

Copy link
Copy Markdown

Rati Dzidziguri (@ratidzidziguri) can you explain what you mean by using a "work-space" version?

@alamothe

Copy link
Copy Markdown

This last release of VS Code is so, so buggy.

Hope an upgrade is coming soon!

Does it make sense to allow people to revert after so many bugs were introduced?

@weswigham

Copy link
Copy Markdown
Member

You can always set your workspace version of TS to an older (or newer!) version of TS.

@hobojoe

hobojoe commented Jul 30, 2018

Copy link
Copy Markdown

Rati Dzidziguri (@ratidzidziguri) can you explain what you mean by using a "work-space" version?

Lucas Klaassen (@lucasklaassen) You can click on the right bottom toolbar of VS Code. Where you have the typescript version. From there you can choose the workspace version.

@djensen47

Copy link
Copy Markdown

Is there any chance this can get into a patch release? This apparently fixes #52089? Which is a pretty bad regression, it's loss of functionality. Basically auto imports import the wrong file.

Thanks for all the hard work on this project. VS Code is awesome.

@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
This pull request was closed.
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.