Skip to content

Commit 508be4d

Browse files
committed
fixed jsx case handling
1 parent 2d661ce commit 508be4d

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

internal/ls/documenthighlights.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,23 @@ func (l *LanguageService) ProvideDocumentHighlights(ctx context.Context, documen
1919
position := int(l.converters.LineAndCharacterToPosition(sourceFile, documentPosition))
2020
node := astnav.GetTouchingPropertyName(sourceFile, position)
2121

22-
if node.Parent.Kind == ast.KindJsxOpeningElement || (node.Parent.Kind == ast.KindJsxClosingElement && node.Parent.TagName() == node) {
22+
if node.Parent != nil && (node.Parent.Kind == ast.KindJsxClosingElement || (node.Parent.Kind == ast.KindJsxOpeningElement && node.Parent.TagName() == node)) {
2323
var documentHighlights []*lsproto.DocumentHighlight
24+
var openingElement, closingElement *ast.Node
2425
kind := lsproto.DocumentHighlightKindRead
25-
if node.Parent.Kind == ast.KindJsxOpeningElement {
26+
if ast.IsJsxElement(node.Parent.Parent) {
27+
openingElement = node.Parent.Parent.AsJsxElement().OpeningElement
28+
closingElement = node.Parent.Parent.AsJsxElement().ClosingElement
29+
}
30+
if openingElement != nil {
2631
documentHighlights = append(documentHighlights, &lsproto.DocumentHighlight{
27-
Range: *l.createLspRangeFromNode(node.Parent, sourceFile),
32+
Range: *l.createLspRangeFromNode(openingElement, sourceFile),
2833
Kind: &kind,
2934
})
3035
}
31-
if node.Parent.Kind == ast.KindJsxClosingElement {
36+
if closingElement != nil {
3237
documentHighlights = append(documentHighlights, &lsproto.DocumentHighlight{
33-
Range: *l.createLspRangeFromNode(node.Parent, sourceFile),
38+
Range: *l.createLspRangeFromNode(closingElement, sourceFile),
3439
Kind: &kind,
3540
})
3641
}

testdata/baselines/reference/fourslash/documentHighlights/findReferencesJSXTagName3.baseline.jsonc

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
// [|</*HIGHLIGHTS*/div>|]
2929
// Some content
3030
// <div>More content</div>
31-
// </div>;
32-
// // --- (line: 13) skipped ---
31+
// [|</div>|];
32+
//
33+
// const x = <Comp>
34+
// Content
35+
// </Comp>;
3336

3437

3538

@@ -39,7 +42,7 @@
3942
// const Comp = () =>
4043
// <div>
4144
// Some content
42-
// [|</*HIGHLIGHTS*/div>|]More content</div>
45+
// [|</*HIGHLIGHTS*/div>|]More content[|</div>|]
4346
// </div>;
4447
//
4548
// const x = <Comp>
@@ -54,7 +57,7 @@
5457
// const Comp = () =>
5558
// <div>
5659
// Some content
57-
// <div>More content[|<//*HIGHLIGHTS*/div>|]
60+
// [|<div>|]More content[|<//*HIGHLIGHTS*/div>|]
5861
// </div>;
5962
//
6063
// const x = <Comp>
@@ -65,8 +68,11 @@
6568

6669
// === documentHighlights ===
6770
// === /a.tsx ===
68-
// --- (line: 8) skipped ---
69-
// <div>
71+
// --- (line: 5) skipped ---
72+
// }
73+
//
74+
// const Comp = () =>
75+
// [|<div>|]
7076
// Some content
7177
// <div>More content</div>
7278
// [|<//*HIGHLIGHTS*/div>|];
@@ -103,14 +109,16 @@
103109
//
104110
// const x = [|</*HIGHLIGHTS*/Comp>|]
105111
// Content
106-
// </Comp>;
112+
// [|</Comp>|];
107113

108114

109115

110116
// === documentHighlights ===
111117
// === /a.tsx ===
112-
// --- (line: 12) skipped ---
118+
// --- (line: 10) skipped ---
119+
// <div>More content</div>
120+
// </div>;
113121
//
114-
// const x = <Comp>
122+
// const x = [|<Comp>|]
115123
// Content
116124
// [|<//*HIGHLIGHTS*/Comp>|];

0 commit comments

Comments
 (0)