mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Rewrite logic for JSX attribute completion detection (#47412)
This commit is contained in:
@@ -456,6 +456,7 @@ namespace ts.Completions {
|
||||
isJsxInitializer,
|
||||
isTypeOnlyLocation,
|
||||
isJsxIdentifierExpected,
|
||||
isRightOfOpenTag,
|
||||
importCompletionNode,
|
||||
insideJsDocTagTypeExpression,
|
||||
symbolToSortTextIdMap,
|
||||
@@ -495,7 +496,9 @@ namespace ts.Completions {
|
||||
importCompletionNode,
|
||||
recommendedCompletion,
|
||||
symbolToOriginInfoMap,
|
||||
symbolToSortTextIdMap
|
||||
symbolToSortTextIdMap,
|
||||
isJsxIdentifierExpected,
|
||||
isRightOfOpenTag,
|
||||
);
|
||||
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
|
||||
}
|
||||
@@ -526,7 +529,9 @@ namespace ts.Completions {
|
||||
importCompletionNode,
|
||||
recommendedCompletion,
|
||||
symbolToOriginInfoMap,
|
||||
symbolToSortTextIdMap
|
||||
symbolToSortTextIdMap,
|
||||
isJsxIdentifierExpected,
|
||||
isRightOfOpenTag,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -669,6 +674,8 @@ namespace ts.Completions {
|
||||
preferences: UserPreferences,
|
||||
completionKind: CompletionKind,
|
||||
formatContext: formatting.FormatContext | undefined,
|
||||
isJsxIdentifierExpected: boolean | undefined,
|
||||
isRightOfOpenTag: boolean | undefined,
|
||||
): CompletionEntry | undefined {
|
||||
let insertText: string | undefined;
|
||||
let replacementSpan = getReplacementSpanForContextToken(replacementToken);
|
||||
@@ -744,8 +751,7 @@ namespace ts.Completions {
|
||||
}
|
||||
}
|
||||
|
||||
const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, location);
|
||||
if (kind === ScriptElementKind.jsxAttribute && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
|
||||
if (isJsxIdentifierExpected && !isRightOfOpenTag && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
|
||||
let useBraces = preferences.jsxAttributeCompletionStyle === "braces";
|
||||
const type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
|
||||
|
||||
@@ -790,7 +796,7 @@ namespace ts.Completions {
|
||||
// entries (like JavaScript identifier entries).
|
||||
return {
|
||||
name,
|
||||
kind,
|
||||
kind: SymbolDisplay.getSymbolKind(typeChecker, symbol, location),
|
||||
kindModifiers: SymbolDisplay.getSymbolModifiers(typeChecker, symbol),
|
||||
sortText,
|
||||
source,
|
||||
@@ -1186,6 +1192,8 @@ namespace ts.Completions {
|
||||
recommendedCompletion?: Symbol,
|
||||
symbolToOriginInfoMap?: SymbolOriginInfoMap,
|
||||
symbolToSortTextIdMap?: SymbolSortTextIdMap,
|
||||
isJsxIdentifierExpected?: boolean,
|
||||
isRightOfOpenTag?: boolean,
|
||||
): UniqueNameSet {
|
||||
const start = timestamp();
|
||||
const variableDeclaration = getVariableDeclaration(location);
|
||||
@@ -1228,6 +1236,8 @@ namespace ts.Completions {
|
||||
preferences,
|
||||
kind,
|
||||
formatContext,
|
||||
isJsxIdentifierExpected,
|
||||
isRightOfOpenTag,
|
||||
);
|
||||
if (!entry) {
|
||||
continue;
|
||||
@@ -1580,6 +1590,7 @@ namespace ts.Completions {
|
||||
readonly isTypeOnlyLocation: boolean;
|
||||
/** In JSX tag name and attribute names, identifiers like "my-tag" or "aria-name" is valid identifier. */
|
||||
readonly isJsxIdentifierExpected: boolean;
|
||||
readonly isRightOfOpenTag: boolean;
|
||||
readonly importCompletionNode?: Node;
|
||||
readonly hasUnresolvedAutoImports?: boolean;
|
||||
}
|
||||
@@ -1987,6 +1998,7 @@ namespace ts.Completions {
|
||||
symbolToSortTextIdMap,
|
||||
isTypeOnlyLocation,
|
||||
isJsxIdentifierExpected,
|
||||
isRightOfOpenTag,
|
||||
importCompletionNode,
|
||||
hasUnresolvedAutoImports,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user