Skip to content

Commit 191aa68

Browse files
committed
Disable JSX attribute snippet if attribute is acutally the HTML tag
1 parent 4e39023 commit 191aa68

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Diff for: src/services/completions.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,12 @@ namespace ts.Completions {
740740
}
741741

742742
const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, location);
743-
if (kind === ScriptElementKind.jsxAttribute && preferences.includeCompletionsWithSnippetText && preferences.jsxAttributeCompletionStyle && preferences.jsxAttributeCompletionStyle !== "none") {
743+
if (
744+
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.
746+
&& preferences.includeCompletionsWithSnippetText
747+
&& preferences.jsxAttributeCompletionStyle
748+
&& preferences.jsxAttributeCompletionStyle !== "none") {
744749
let useBraces = preferences.jsxAttributeCompletionStyle === "braces";
745750
const type = typeChecker.getTypeOfSymbolAtLocation(symbol, location);
746751

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path="fourslash.ts" />
2+
//@Filename: file.tsx
3+
////declare namespace JSX {
4+
//// interface IntrinsicElements {
5+
//// button: any;
6+
//// div: any;
7+
//// }
8+
////}
9+
////function fn() {
10+
//// return <>
11+
//// <butto/*1*/
12+
//// </>;
13+
////}
14+
15+
16+
verify.completions(
17+
{
18+
marker: "1",
19+
includes: [
20+
{ name: "button", insertText: undefined, isSnippet: undefined }
21+
],
22+
preferences: {
23+
jsxAttributeCompletionStyle: "braces",
24+
includeCompletionsWithSnippetText: true,
25+
includeCompletionsWithInsertText: true,
26+
}
27+
},
28+
);

0 commit comments

Comments
 (0)