-
Notifications
You must be signed in to change notification settings - Fork 13.1k
fix(41259) : JS autocomplete doesn't work for object literal shorthands #41539
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
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
78599ee
fix: #41259
orange4glace ea29b15
fix: #41259
orange4glace 78bd6a6
fix: fourslash
orange4glace 6d3db10
fix: remove nested if
orange4glace 0e6b319
fix: change tc result for #41259
orange4glace 20e2ad7
fix: less restrictive shorthand completion rules
orange4glace 2f8e441
fix: use typeMembers to find out whether properties are empty
orange4glace 9938e53
fix: typo
orange4glace 524b90e
fix: lint
orange4glace 8358a40
fix: exclude Object in completion
orange4glace a0f2476
fix: test
orange4glace 00dcdd6
fix: testcase tidy up
orange4glace b70118f
fix: apply completions for unclosed literal and missing comma
orange4glace a91b5e2
fix: ignore auto-imports
orange4glace 4b84a59
fix: use exact to ensure the order of completions
orange4glace 707e026
fix: use exact to ensure the order of completions
orange4glace 7785606
fix: add new lines so it can easy to be distinguished
orange4glace 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 hidden or 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
10 changes: 9 additions & 1 deletion
10
tests/cases/fourslash/completionListAtIdentifierDefinitionLocations_destructuring.ts
This file contains hidden or 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,19 +1,27 @@ | ||
| /// <reference path='fourslash.ts' /> | ||
|
|
||
| // @Filename: a.ts | ||
| //// var [x/*variable1*/ | ||
|
|
||
| // @Filename: b.ts | ||
| //// var [x, y/*variable2*/ | ||
|
|
||
| // @Filename: c.ts | ||
| //// var [./*variable3*/ | ||
|
|
||
| // @Filename: d.ts | ||
| //// var [x, ...z/*variable4*/ | ||
|
|
||
| // @Filename: e.ts | ||
| //// var {x/*variable5*/ | ||
|
|
||
| // @Filename: f.ts | ||
| //// var {x, y/*variable6*/ | ||
|
|
||
| // @Filename: g.ts | ||
| //// function func1({ a/*parameter1*/ | ||
|
|
||
| // @Filename: h.ts | ||
| //// function func2({ a, b/*parameter2*/ | ||
|
|
||
| verify.completions({ marker: test.markers(), exact: undefined }); | ||
| verify.completions({ marker: test.markers(), exact: undefined }); |
49 changes: 49 additions & 0 deletions
49
tests/cases/fourslash/completionPropertyShorthandForObjectLiteral.ts
This file contains hidden or 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,49 @@ | ||
| /// <reference path="fourslash.ts"/> | ||
|
|
||
| //// declare const foo: number; | ||
| //// interface Empty {} | ||
| //// interface Typed { typed: number; } | ||
|
|
||
| //// declare function f1(obj): void; | ||
| //// declare function f2(obj: any): void; | ||
| //// declare function f3(obj: unknown): void; | ||
| //// declare function f4(obj: object): void; | ||
| //// declare function f5(obj: Record<string, any>): void; | ||
| //// declare function f6(obj: { [key: string]: number }): void; | ||
| //// declare function f7<T>(obj: T): void; | ||
| //// declare function f8<T extends object>(obj: T): void; | ||
| //// declare function f9<T extends {}>(obj: T): void; | ||
| //// declare function f10<T extends Empty>(obj: T): void; | ||
| //// declare function f11<T extends (Empty | Record<string, any> | {})>(obj: T): void; | ||
| //// declare function f12(obj: Object): void; | ||
| //// declare function f13<T extends Object>(obj: T): void; | ||
| //// declare function f14(obj: Typed): void; | ||
| //// declare function f15<T extends (Empty | Object | Typed)>(obj: T): void; | ||
| //// declare function f16(obj: Record<number, any>): void; | ||
| //// declare function f17(obj: { [key: string]: number, prop: number }): void; | ||
| //// declare function f18(obj: { [key: number]: number }): void; | ||
|
|
||
| //// f1({f/*1*/}); | ||
| //// f2({f/*2*/}); | ||
| //// f3({f/*3*/}); | ||
| //// f4({f/*4*/}); | ||
| //// f5({f/*5*/}); | ||
| //// f6({f/*6*/}); | ||
| //// f7({f/*7*/}); | ||
| //// f8({f/*8*/}); | ||
| //// f9({f/*9*/}); | ||
| //// f10({f/*10*/}); | ||
| //// f11({f/*11*/}); | ||
| //// f12({f/*12*/}); | ||
| //// f13({f/*13*/}); | ||
| //// f14({f/*14*/}); | ||
| //// f15({f/*15*/}); | ||
| //// f16({f/*16*/}); | ||
| //// f17({f/*17*/}); | ||
| //// f18({f/*18*/}); | ||
|
|
||
| verify.completions( | ||
| { marker: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"], includes: ["foo"]}, | ||
| { marker: ["12", "13", "14", "15"], excludes: ["foo"]}, | ||
| { marker: ["16", "17", "18"], excludes: ["foo"], isNewIdentifierLocation: true}, | ||
| ); |
17 changes: 17 additions & 0 deletions
17
tests/cases/fourslash/completionPropertyShorthandForObjectLiteral2.ts
This file contains hidden or 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"/> | ||
|
|
||
| //// const foo = 1; | ||
| //// const bar = 2; | ||
|
|
||
| //// const obj1 = { | ||
| //// foo b/*1*/ | ||
| //// }; | ||
|
|
||
| //// const obj2: any = { | ||
| //// foo b/*2*/ | ||
| //// }; | ||
|
|
||
| verify.completions({ | ||
| marker: test.markers(), | ||
| includes: ["bar"] | ||
| }); |
11 changes: 11 additions & 0 deletions
11
tests/cases/fourslash/completionPropertyShorthandForObjectLiteral3.ts
This file contains hidden or 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"/> | ||
|
|
||
| //// const foo = 1; | ||
| //// const bar = 2; | ||
| //// const obj = { | ||
| //// foo b/*1*/ | ||
|
|
||
| verify.completions({ | ||
| marker: ["1"], | ||
| includes: ["bar"] | ||
| }); |
11 changes: 11 additions & 0 deletions
11
tests/cases/fourslash/completionPropertyShorthandForObjectLiteral4.ts
This file contains hidden or 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"/> | ||
|
|
||
| //// const foo = 1; | ||
| //// const bar = 2; | ||
| //// const obj: any = { | ||
| //// foo b/*1*/ | ||
|
|
||
| verify.completions({ | ||
| marker: ["1"], | ||
| includes: ["bar"] | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
It is a bit of a pain, but can we try to keep using
exactin all these tests? Hopefully in this case it’s justexact: completion.globals.exactis useful in some of these other tests for ensuring that locals get sorted before globals, which is important to this feature. I’m almost on the fence about whether globals should show up here at all (who wants to declare something likeconst obj = { Object, Date, setTimeout }?), but I think as long as they get sorted below locals, it’s fine.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.
Sure! I'll fix it after I find out how I can do this elegantly. :)
I agree with that by the way.
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.
Fixed! except it uses
globalsPlusfor this case (#41731)707e026#diff-758264b55071844e413a511bae1269991faea7f964e4d03cebb9a021ff42eb50R12