mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Exclude literal completions after closing quote and JSX attribute location (#52676)
This commit is contained in:
parent
a0374077dd
commit
0e357f510b
@ -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);
|
||||
|
||||
|
||||
@ -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"'
|
||||
],
|
||||
});
|
||||
|
||||
@ -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"], });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user