-
Notifications
You must be signed in to change notification settings - Fork 939
Fix auto-import of subpath imports starting with #/ in supported module resolution modes
#3123
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
Changes from all commits
3d847b0
cb06ee2
d85d8e2
4858e36
2ce94b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package fourslash_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/typescript-go/internal/fourslash" | ||
| "github.com/microsoft/typescript-go/internal/testutil" | ||
| ) | ||
|
|
||
| func TestAutoImportPackageJsonImportsHashSlashNodenext(t *testing.T) { | ||
| t.Parallel() | ||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = `// @Filename: /tsconfig.json | ||
| { | ||
| "compilerOptions": { | ||
| "module": "nodenext", | ||
| "rootDir": "./", | ||
| "outDir": "build" | ||
| } | ||
| } | ||
| // @Filename: /package.json | ||
| { | ||
| "imports": { | ||
| "#/*": { | ||
| "types": "./src/*", | ||
| "default": "./src/*" | ||
| } | ||
| } | ||
| } | ||
| // @Filename: /src/domain/entities/entity.ts | ||
| export const entity = 1; | ||
| // @Filename: /src/features/deep/consumer.ts | ||
| entit/**/` | ||
| f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| defer done() | ||
| f.BaselineAutoImportsCompletions(t, []string{""}) | ||
| } | ||
|
|
||
| func TestAutoImportPackageJsonImportsHashSlashNode16(t *testing.T) { | ||
| t.Parallel() | ||
| defer testutil.RecoverAndFail(t, "Panic on fourslash test") | ||
| const content = `// @Filename: /tsconfig.json | ||
| { | ||
| "compilerOptions": { | ||
| "module": "node16" | ||
| } | ||
| } | ||
| // @Filename: /package.json | ||
| { | ||
| "imports": { | ||
| "#/*": "./src/*" | ||
| } | ||
| } | ||
| // @Filename: /src/domain/entities/entity.ts | ||
| export const entity = 1; | ||
| // @Filename: /src/consumer.ts | ||
| entit/**/` | ||
| f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) | ||
| defer done() | ||
| f.BaselineAutoImportsCompletions(t, []string{""}) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // === Auto Imports === | ||
| ```ts | ||
| // @FileName: /src/consumer.ts | ||
| entit/**/ | ||
| ``````ts | ||
| import { entity } from "./domain/entities/entity"; | ||
|
|
||
| entit | ||
| ``` | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // === Auto Imports === | ||
| ```ts | ||
| // @FileName: /src/features/deep/consumer.ts | ||
| entit/**/ | ||
| ``````ts | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems broken, and the next like is missing a file path - what's going on here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These baselines have always been missing a newline. I'll fix them all in a separate PR but the baseline still shows everything is working. |
||
| import { entity } from "#/domain/entities/entity.js"; | ||
|
|
||
| entit | ||
| ``` | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is surprising - does the blog post need to be updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah,
--moduleResolution node20doesn't exist yet. Everything else is right.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this logic says that
"#"and"#/"are invalid entries in"imports"- so am I misunderstanding?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are, aren't they? You need something after that prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, to be explicit - the blog post example uses a bare
#entry, which is not being used as a prefix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omg, sorry, I totally missed that. I was only focused on the highlighted text. Yes, the blog post needs to be updated: