Skip to content

Commit 7ac5e59

Browse files
committed
Big comment
1 parent 1786d5e commit 7ac5e59

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Diff for: src/services/completions.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,22 @@ namespace ts.Completions {
739739
}
740740
}
741741

742+
// Before offering up a JSX attribute snippet, ensure that we aren't potentially completing
743+
// a tag name; this may appear as an attribute after the "<" when the tag has not yet been
744+
// closed, as in:
745+
//
746+
// return <>
747+
// foo <butto|
748+
// </>
749+
//
750+
// We can detect this case by checking if both:
751+
//
752+
// 1. The location is "<", so we are completing immediately after it.
753+
// 2. The "<" has the same position as its parent, so is not a binary expression.
742754
const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, location);
743755
if (
744756
kind === ScriptElementKind.jsxAttribute
745-
&& (location.kind !== SyntaxKind.LessThanToken || location.pos !== location.parent.pos) // Disable snippet for the first attribute, which is actually the tag name.
757+
&& (location.kind !== SyntaxKind.LessThanToken || location.pos !== location.parent.pos)
746758
&& preferences.includeCompletionsWithSnippetText
747759
&& preferences.jsxAttributeCompletionStyle
748760
&& preferences.jsxAttributeCompletionStyle !== "none") {

0 commit comments

Comments
 (0)