Exclude literal completions after closing quote and JSX attribute location (#52676)

This commit is contained in:
Vitaly 2023-03-01 00:31:30 +03:00 committed by GitHub
parent a0374077dd
commit 0e357f510b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View File

@ -2927,7 +2927,10 @@ function getCompletionData(
log("getCompletionData: Semantic work: " + (timestamp() - semanticStart));
const contextualType = previousToken && getContextualType(previousToken, position, sourceFile, typeChecker);
const literals = mapDefined(
// exclude literal suggestions after <input type="text" [||] /> (#51667) and after closing quote (#52675)
// for strings getStringLiteralCompletions handles completions
const isLiteralExpected = !tryCast(previousToken, isStringLiteralLike) && !isJsxIdentifierExpected;
const literals = !isLiteralExpected ? [] : mapDefined(
contextualType && (contextualType.isUnion() ? contextualType.types : [contextualType]),
t => t.isLiteral() && !(t.flags & TypeFlags.EnumLiteral) ? t.value : undefined);

View File

@ -2,6 +2,7 @@
////const x: 0 | "one" = /**/;
////const y: 0 | "one" | 1n = /*1*/;
////const y2: 0 | "one" | 1n = 'one'/*2*/;
verify.completions({
marker: "",
@ -20,3 +21,9 @@ verify.completions({
],
isNewIdentifierLocation: true,
});
verify.completions({
marker: "2",
excludes: [
'"one"'
],
});

View File

@ -2,10 +2,15 @@
// @jsx: preserve
// @filename: /a.tsx
////type Props = { a: number } | { b: "somethingelse" };
////type Props = { a: number } | { b: "somethingelse", c: 0 | 1 };
////declare function Foo(args: Props): any
////
////const a1 = <Foo b={"/*1*/"} />
////const a2 = <Foo b="/*2*/" />
////const a3 = <Foo b="somethingelse"/*3*/ />
////const a4 = <Foo b={"somethingelse"} /*4*/ />
////const a5 = <Foo b={"somethingelse"} c={0} /*5*/ />
verify.completions({ marker: ["1", "2"], exact: ["somethingelse"] });
verify.completions({ marker: ["3", "4"], excludes: ['"somethingelse"'], });
verify.completions({ marker: ["5"], excludes: ["0", "1"], });