-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Retry querying string completions from the inferred type if the original completions request doesn't return anything #52875
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
42f9e69
700e31f
56e2f4d
364ad69
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 |
---|---|---|
|
@@ -16,5 +16,5 @@ | |
verify.completions({ marker: "1", includes: ["a", "b", "c"] }); | ||
verify.completions({ marker: "2", includes: ["0", "1", "2"], isNewIdentifierLocation: true }); | ||
verify.completions({ marker: "3", includes: ["a", "b", "c"] }); | ||
verify.completions({ marker: "4", excludes: ["a", "b", "c"] }); | ||
verify.completions({ marker: "4", exact: [] }); | ||
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 case wasn't actually returning any meaningful completions, see the playground here. It's just that empty |
||
verify.completions({ marker: "5", includes: ["a", "b", "c"] }); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @Filename: /a.tsx | ||
//// declare function test<T>(a: { | ||
//// [K in keyof T]: { | ||
//// b?: keyof T; | ||
//// }; | ||
//// }): void; | ||
//// | ||
//// test({ | ||
//// foo: {}, | ||
//// bar: { | ||
//// b: "/*ts*/", | ||
//// }, | ||
//// }); | ||
|
||
verify.completions({ marker: ["ts"], exact: ["foo", "bar"] }); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @Filename: /a.tsx | ||
//// type Values<T> = T[keyof T]; | ||
//// | ||
//// type GetStates<T> = T extends { states: object } ? T["states"] : never; | ||
//// | ||
//// type IsNever<T> = [T] extends [never] ? 1 : 0; | ||
//// | ||
//// type GetIds<T, Gathered extends string = never> = IsNever<T> extends 1 | ||
//// ? Gathered | ||
//// : "id" extends keyof T | ||
//// ? GetIds<Values<GetStates<T>>, Gathered | `#${T["id"] & string}`> | ||
//// : GetIds<Values<GetStates<T>>, Gathered>; | ||
//// | ||
//// type StateConfig< | ||
//// TStates extends Record<string, StateConfig> = Record< | ||
//// string, | ||
//// StateConfig<any> | ||
//// >, | ||
//// TIds extends string = string | ||
//// > = { | ||
//// id?: string; | ||
//// initial?: keyof TStates & string; | ||
//// states?: { | ||
//// [K in keyof TStates]: StateConfig<GetStates<TStates[K]>, TIds>; | ||
//// }; | ||
//// on?: Record<string, TIds | `.${keyof TStates & string}`>; | ||
//// }; | ||
//// | ||
//// declare function createMachine<const T extends StateConfig<GetStates<T>, GetIds<T>>>( | ||
//// config: T | ||
//// ): void; | ||
//// | ||
//// createMachine({ | ||
//// initial: "child", | ||
//// states: { | ||
//// child: { | ||
//// initial: "foo", | ||
//// states: { | ||
//// foo: { | ||
//// id: "wow_deep_id", | ||
//// }, | ||
//// }, | ||
//// }, | ||
//// }, | ||
//// on: { | ||
//// EV: "/*ts*/", | ||
//// }, | ||
//// }); | ||
|
||
verify.completions({ marker: ["ts"], exact: ["#wow_deep_id", ".child"] }); |
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's unfortunate that this involves querying the contextual type twice (with different flags). However, it's super hard to distinguish the cases in which the completions should be returned from the constraint (that can be returned from the first requests since it blocks the inference) or if they should be returned based on the inferred type (second request without the inference block).
I assume here that this second request is somewhat cheap since it should often just look through the existing~ contextual type. Perhaps there is a way to limit situations in which this second request is even done. I wasn't sure what would be the best condition for that though. Essentially, I only want to do this request when the
node
is within a potential inference context (nested in a call-like).