mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Improve contextual completions (#53554)
This commit is contained in:
committed by
GitHub
parent
4849947357
commit
40787a7076
@@ -2938,7 +2938,7 @@ function getContextualType(previousToken: Node, position: number, sourceFile: So
|
||||
isEqualityOperatorKind(previousToken.kind) && isBinaryExpression(parent) && isEqualityOperatorKind(parent.operatorToken.kind) ?
|
||||
// completion at `x ===/**/` should be for the right side
|
||||
checker.getTypeAtLocation(parent.left) :
|
||||
checker.getContextualType(previousToken as Expression);
|
||||
checker.getContextualType(previousToken as Expression, ContextFlags.Completions) || checker.getContextualType(previousToken as Expression);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// declare function test<P extends "a" | "b">(p: P): void;
|
||||
////
|
||||
//// test(/*ts*/)
|
||||
////
|
||||
|
||||
verify.completions({ marker: ["ts"], includes: ['"a"', '"b"'], isNewIdentifierLocation: true });
|
||||
@@ -0,0 +1,7 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// declare function test<T extends 'a' | 'b'>(a: { foo: T[] }): void
|
||||
////
|
||||
//// test({ foo: [/*ts*/] })
|
||||
|
||||
verify.completions({ marker: ["ts"], includes: ['"a"', '"b"'], isNewIdentifierLocation: true });
|
||||
@@ -0,0 +1,7 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// declare function test<T extends 'a' | 'b'>(a: { foo: T[] }): void
|
||||
////
|
||||
//// test({ foo: ['a', /*ts*/] })
|
||||
|
||||
verify.completions({ marker: ["ts"], includes: ['"a"', '"b"'], isNewIdentifierLocation: true });
|
||||
@@ -0,0 +1,7 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// declare function test<P extends "a" | "b">(p: { type: P }): void;
|
||||
////
|
||||
//// test({ type: /*ts*/ })
|
||||
|
||||
verify.completions({ marker: ["ts"], includes: ['"a"', '"b"'], isNewIdentifierLocation: false });
|
||||
@@ -13,5 +13,13 @@
|
||||
//// b: "/*ts*/",
|
||||
//// },
|
||||
//// });
|
||||
////
|
||||
//// test({
|
||||
//// foo: {},
|
||||
//// bar: {
|
||||
//// b: /*ts2*/,
|
||||
//// },
|
||||
//// });
|
||||
|
||||
verify.completions({ marker: ["ts"], exact: ["foo", "bar"] });
|
||||
verify.completions({ marker: ["ts2"], includes: ['"foo"', '"bar"'], isNewIdentifierLocation: false });
|
||||
|
||||
@@ -12,5 +12,13 @@
|
||||
//// b: ["/*ts*/"],
|
||||
//// },
|
||||
//// });
|
||||
////
|
||||
//// test({
|
||||
//// foo: {},
|
||||
//// bar: {
|
||||
//// b: [/*ts2*/],
|
||||
//// },
|
||||
//// });
|
||||
|
||||
verify.completions({ marker: ["ts"], exact: ["foo", "bar"] });
|
||||
verify.completions({ marker: ["ts2"], includes: ['"foo"', '"bar"'], isNewIdentifierLocation: true });
|
||||
|
||||
Reference in New Issue
Block a user