Skip to content

Commit 4916e22

Browse files
authored
Properly include JSX attributes in find-all-references (#2025)
1 parent 84d64f6 commit 4916e22

14 files changed

+124
-222
lines changed

internal/ls/utilities.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,20 +1647,24 @@ func getContainingObjectLiteralElementWorker(node *ast.Node) *ast.Node {
16471647
switch node.Kind {
16481648
case ast.KindStringLiteral, ast.KindNoSubstitutionTemplateLiteral, ast.KindNumericLiteral:
16491649
if node.Parent.Kind == ast.KindComputedPropertyName {
1650-
if ast.IsObjectLiteralElement(node.Parent.Parent) {
1650+
if isObjectLiteralOrJsxElement(node.Parent.Parent) {
16511651
return node.Parent.Parent
16521652
}
16531653
return nil
16541654
}
16551655
fallthrough
16561656
case ast.KindIdentifier:
1657-
if ast.IsObjectLiteralElement(node.Parent) && (node.Parent.Parent.Kind == ast.KindObjectLiteralExpression || node.Parent.Parent.Kind == ast.KindJsxAttributes) && node.Parent.Name() == node {
1657+
if isObjectLiteralOrJsxElement(node.Parent) && (node.Parent.Parent.Kind == ast.KindObjectLiteralExpression || node.Parent.Parent.Kind == ast.KindJsxAttributes) && node.Parent.Name() == node {
16581658
return node.Parent
16591659
}
16601660
}
16611661
return nil
16621662
}
16631663

1664+
func isObjectLiteralOrJsxElement(node *ast.Node) bool {
1665+
return ast.IsObjectLiteralElement(node) || ast.IsJsxAttribute(node) || ast.IsJsxSpreadAttribute(node)
1666+
}
1667+
16641668
// Return a function that returns true if the given node has not been seen
16651669
func nodeSeenTracker() func(*ast.Node) bool {
16661670
var seen collections.Set[*ast.Node]

testdata/baselines/reference/fourslash/findAllReferences/tsxFindAllReferences10.baseline.jsonc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@
88
// }
99
// interface LinkProps extends ClickableProps {
1010
// goTo: string;
11-
// // --- (line: 16) skipped ---
11+
// }
12+
// declare function MainButton(buttonProps: ButtonProps): JSX.Element;
13+
// declare function MainButton(linkProps: LinkProps): JSX.Element;
14+
// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element;
15+
// let opt = <MainButton />;
16+
// let opt = <MainButton children="chidlren" />;
17+
// let opt = <MainButton [|onClick|]={()=>{}} />;
18+
// let opt = <MainButton [|onClick|]={()=>{}} ignore-prop />;
19+
// let opt = <MainButton goTo="goTo" />;
20+
// let opt = <MainButton wrong />;

testdata/baselines/reference/fourslash/findAllReferences/tsxFindAllReferences2.baseline.jsonc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
// isOpen?: boolean;
99
// };
1010
// span: { n: string; };
11-
// // --- (line: 9) skipped ---
11+
// }
12+
// }
13+
// var x = <div [|name|]="hello" />;

testdata/baselines/reference/fourslash/findAllReferences/tsxFindAllReferences3.baseline.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
// }
1010
//
1111
//
12-
// var x = <MyClass name='hello'/>;
12+
// var x = <MyClass [|name|]='hello'/>;

testdata/baselines/reference/fourslash/findAllReferences/tsxFindAllReferences7.baseline.jsonc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
// propString: string
99
// optional?: boolean
1010
// }
11-
// // --- (line: 12) skipped ---
11+
// declare function Opt(attributes: OptionPropBag): JSX.Element;
12+
// let opt = <Opt />;
13+
// let opt1 = <Opt [|propx|]={100} propString />;
14+
// let opt2 = <Opt [|propx|]={100} optional/>;
15+
// let opt3 = <Opt wrong />;

testdata/baselines/reference/fourslash/findAllReferences/tsxFindAllReferences9.baseline.jsonc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@
88
// }
99
// declare function MainButton(buttonProps: ButtonProps): JSX.Element;
1010
// declare function MainButton(linkProps: LinkProps): JSX.Element;
11-
// // --- (line: 19) skipped ---
11+
// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element;
12+
// let opt = <MainButton />;
13+
// let opt = <MainButton children="chidlren" />;
14+
// let opt = <MainButton onClick={()=>{}} />;
15+
// let opt = <MainButton onClick={()=>{}} ignore-prop />;
16+
// let opt = <MainButton [|goTo|]="goTo" />;
17+
// let opt = <MainButton [|goTo|] />;
18+
// let opt = <MainButton wrong />;

testdata/baselines/reference/submodule/fourslash/findRenameLocations/tsxRename2.baseline.jsonc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88
// isOpen?: boolean;
99
// };
1010
// span: { n: string; };
11-
// // --- (line: 9) skipped ---
11+
// }
12+
// }
13+
// var x = <div [|nameRENAME|]="hello" />;
1214

1315

1416

1517
// === findRenameLocations ===
1618
// === /file.tsx ===
17-
// --- (line: 7) skipped ---
19+
// declare module JSX {
20+
// interface Element { }
21+
// interface IntrinsicElements {
22+
// div: {
23+
// [|nameRENAME|]?: string;
24+
// isOpen?: boolean;
25+
// };
1826
// span: { n: string; };
1927
// }
2028
// }

testdata/baselines/reference/submodule/fourslash/findRenameLocations/tsxRename2.baseline.jsonc.diff

Lines changed: 0 additions & 26 deletions
This file was deleted.

testdata/baselines/reference/submodule/fourslash/findRenameLocations/tsxRename3.baseline.jsonc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
// }
1010
//
1111
//
12-
// var x = <MyClass name='hello'/>;
12+
// var x = <MyClass [|nameRENAME|]='hello'/>;
1313

1414

1515

1616
// === findRenameLocations ===
1717
// === /file.tsx ===
18-
// --- (line: 10) skipped ---
18+
// --- (line: 5) skipped ---
19+
// }
20+
// class MyClass {
21+
// props: {
22+
// [|nameRENAME|]?: string;
23+
// size?: number;
1924
// }
2025
//
2126
//

testdata/baselines/reference/submodule/fourslash/findRenameLocations/tsxRename3.baseline.jsonc.diff

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)