-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Code fix for missing imports #11768
Merged
Merged
Code fix for missing imports #11768
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0389207
Add codefix for missing imports + tests
eb46886
Re-order and cleanup
80d7f5c
refactor
zhengbli a6807ab
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
zhengbli 1502f75
make tests pass
zhengbli e72f0c8
Make import specifier for new imports more comprehensive
zhengbli d273308
Fix existing import cases
zhengbli 35d668a
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
zhengbli eb892d3
refactor
zhengbli 6d024dc
Fix multiple import statement case
zhengbli 26cd24a
add multiple code fixes and code action filtering and polishing
zhengbli a282fc0
not using the generic verify method for import fixes.
zhengbli 1f82ce7
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
zhengbli d83c292
Correct insert position for new imports
zhengbli 7568f6f
Merge branch 'master' of https://github.com/Microsoft/TypeScript into…
zhengbli aa2891c
improve the code action filtering logic
zhengbli 055d20f
Fix line ending issue
zhengbli 11ea6b3
cache where we can
zhengbli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
///<reference path='superFixes.ts' /> | ||
///<reference path='importFixes.ts' /> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import [|{ v1 }|] from "./module"; | ||
//// f1/*0*/(); | ||
|
||
// @Filename: module.ts | ||
//// export function f1() {} | ||
//// export var v1 = 5; | ||
|
||
verify.codeFixAtPosition(`{ v1, f1 }`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import d, [|{ v1 }|] from "./module"; | ||
//// f1/*0*/(); | ||
|
||
// @Filename: module.ts | ||
//// export function f1() {} | ||
//// export var v1 = 5; | ||
//// export default var d1 = 6; | ||
|
||
verify.codeFixAtPosition(`{ v1, f1 }`); |
21 changes: 21 additions & 0 deletions
21
tests/cases/fourslash/importNameCodeFixExistingImport10.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import [|{ | ||
//// v1, | ||
//// v2 | ||
//// }|] from "./module"; | ||
//// f1/*0*/(); | ||
|
||
// @Filename: module.ts | ||
//// export function f1() {} | ||
//// export var v1 = 5; | ||
//// export var v2 = 5; | ||
//// export var v3 = 5; | ||
|
||
verify.codeFixAtPosition( | ||
`{ | ||
v1, | ||
v2, | ||
f1 | ||
}` | ||
); |
20 changes: 20 additions & 0 deletions
20
tests/cases/fourslash/importNameCodeFixExistingImport11.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import [|{ | ||
//// v1, v2, | ||
//// v3 | ||
//// }|] from "./module"; | ||
//// f1/*0*/(); | ||
|
||
// @Filename: module.ts | ||
//// export function f1() {} | ||
//// export var v1 = 5; | ||
//// export var v2 = 5; | ||
//// export var v3 = 5; | ||
|
||
verify.codeFixAtPosition( | ||
`{ | ||
v1, v2, | ||
v3, f1 | ||
}` | ||
); |
12 changes: 12 additions & 0 deletions
12
tests/cases/fourslash/importNameCodeFixExistingImport12.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import [|{}|] from "./module"; | ||
//// f1/*0*/(); | ||
|
||
// @Filename: module.ts | ||
//// export function f1() {} | ||
//// export var v1 = 5; | ||
//// export var v2 = 5; | ||
//// export var v3 = 5; | ||
|
||
verify.codeFixAtPosition(`{ f1 }`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import * as ns from "./module"; | ||
//// [|f1|]/*0*/(); | ||
|
||
// @Filename: module.ts | ||
//// export function f1() {} | ||
//// export var v1 = 5; | ||
|
||
verify.codeFixAtPosition(`ns.f1`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import d, * as ns from "./module"; | ||
//// [|f1|]/*0*/(); | ||
|
||
// @Filename: module.ts | ||
//// export function f1() {} | ||
//// export var v1 = 5; | ||
//// export default var d1 = 6; | ||
|
||
verify.codeFixAtPosition(`ns.f1`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// [|import d from "./module"; | ||
//// f1/*0*/();|] | ||
|
||
// @Filename: module.ts | ||
//// export function f1() {} | ||
//// export var v1 = 5; | ||
//// export default var d1 = 6; | ||
|
||
verify.codeFixAtPosition(`import d from "./module"; | ||
import { f1 } from "./module"; | ||
f1();`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// [|import "./module"; | ||
//// f1/*0*/();|] | ||
|
||
// @Filename: module.ts | ||
//// export function f1() {} | ||
//// export var v1 = 5; | ||
|
||
verify.codeFixAtPosition(`import "./module"; | ||
import { f1 } from "./module"; | ||
f1();`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import [|{ v1 }|] from "fake-module"; | ||
//// f1/*0*/(); | ||
|
||
// @Filename: ../package.json | ||
//// { "dependencies": { "fake-module": "latest" } } | ||
|
||
// @Filename: ../node_modules/fake-module/index.ts | ||
//// export var v1 = 5; | ||
//// export function f1(); | ||
|
||
verify.codeFixAtPosition(`{ v1, f1 }`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import [|{ v1 }|] from "../other_dir/module"; | ||
//// f1/*0*/(); | ||
|
||
// @Filename: ../other_dir/module.ts | ||
//// export var v1 = 5; | ||
//// export function f1(); | ||
|
||
verify.codeFixAtPosition(`{ v1, f1 }`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import [|{v1, v2, v3,}|] from "./module"; | ||
//// f1/*0*/(); | ||
|
||
// @Filename: module.ts | ||
//// export function f1() {} | ||
//// export var v1 = 5; | ||
//// export var v2 = 5; | ||
//// export var v3 = 5; | ||
|
||
verify.codeFixAtPosition(`{v1, v2, v3, f1,}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import [|{ | ||
//// v1 | ||
//// }|] from "./module"; | ||
//// f1/*0*/(); | ||
|
||
// @Filename: module.ts | ||
//// export function f1() {} | ||
//// export var v1 = 5; | ||
|
||
verify.codeFixAtPosition( | ||
`{ | ||
v1, | ||
f1 | ||
}` | ||
); |
14 changes: 14 additions & 0 deletions
14
tests/cases/fourslash/importNameCodeFixNewImportAmbient0.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// [|f1/*0*/();|] | ||
|
||
// @Filename: ambientModule.ts | ||
//// declare module "ambient-module" { | ||
//// export function f1(); | ||
//// export var v1; | ||
//// } | ||
|
||
verify.codeFixAtPosition( | ||
`import { f1 } from "ambient-module"; | ||
f1();` | ||
); |
28 changes: 28 additions & 0 deletions
28
tests/cases/fourslash/importNameCodeFixNewImportAmbient1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// import d from "other-ambient-module"; | ||
//// [|import * as ns from "yet-another-ambient-module"; | ||
//// var x = v1/*0*/ + 5;|] | ||
|
||
// @Filename: ambientModule.ts | ||
//// declare module "ambient-module" { | ||
//// export function f1(); | ||
//// export var v1; | ||
//// } | ||
|
||
// @Filename: otherAmbientModule.ts | ||
//// declare module "other-ambient-module" { | ||
//// export default function f2(); | ||
//// } | ||
|
||
// @Filename: yetAnotherAmbientModule.ts | ||
//// declare module "yet-another-ambient-module" { | ||
//// export function f3(); | ||
//// export var v3; | ||
//// } | ||
|
||
verify.codeFixAtPosition( | ||
`import * as ns from "yet-another-ambient-module"; | ||
import { v1 } from "ambient-module"; | ||
var x = v1 + 5;` | ||
); |
20 changes: 20 additions & 0 deletions
20
tests/cases/fourslash/importNameCodeFixNewImportAmbient2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
//// [|/* | ||
//// * I'm a license or something | ||
//// */ | ||
//// f1/*0*/();|] | ||
|
||
// @Filename: ambientModule.ts | ||
//// declare module "ambient-module" { | ||
//// export function f1(); | ||
//// export var v1; | ||
//// } | ||
|
||
verify.codeFixAtPosition( | ||
`/* | ||
* I'm a license or something | ||
*/ | ||
import { f1 } from "ambient-module"; | ||
f1();` | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we can not rename it as this is a published API and ppl are using it already. consider adding a new method instead
getExportOfModule(moduleSymbol, exportName): Symbol