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

Canonicalize path before calling startsWith #25364

Merged
3 commits merged into from
Jul 3, 2018
Merged

Canonicalize path before calling startsWith #25364

3 commits merged into from
Jul 3, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jul 2, 2018

@ghost ghost requested a review from sheetalkamat July 2, 2018 15:14
@DanielRosenwasser
Copy link
Member

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

@weswigham
Copy link
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.

@@ -290,7 +290,7 @@ namespace ts.moduleSpecifiers {
const moduleSpecifier = getDirectoryOrExtensionlessFileName(moduleFileName);
// 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
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
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
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
Contributor

mhegazy commented Jul 2, 2018

Also looks related to #25338

@ghost
Copy link
Author

ghost commented Jul 3, 2018

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

ghost commented Jul 3, 2018

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

@mhegazy
Copy link
Contributor

mhegazy commented Jul 3, 2018

@andy-ms can you also verify that this change fixes #25358 #24599 #25345 and #25186?

@Kingwl
Copy link
Contributor

Kingwl commented Jul 5, 2018

image

seems fixed on my pc@20180705

@gremo
Copy link

gremo commented Jul 9, 2018

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

@Kingwl
Copy link
Contributor

Kingwl commented Jul 10, 2018

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

smnbbrv commented Jul 10, 2018

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

@ghost
Copy link
Author

ghost commented Jul 10, 2018

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

@smnbbrv
Copy link

smnbbrv commented Jul 11, 2018

@andy-ms thanks, it works!

@ratidzidziguri
Copy link

ratidzidziguri commented Jul 11, 2018

for me installing @next did not work
image

and still when importing
image

@mhegazy
Copy link
Contributor

mhegazy commented Jul 11, 2018

@ratidzidziguri can you share more info.

@ratidzidziguri
Copy link

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

smnbbrv commented Jul 12, 2018

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
Contributor

mhegazy commented Jul 12, 2018

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

@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

☝️ 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

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

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

@alamothe
Copy link

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
Member

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

@hobojoe
Copy link

hobojoe commented Jul 30, 2018

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

@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

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.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.