Skip to content

Commit ebb33b6

Browse files
committed
Just a bit more
1 parent 17f2964 commit ebb33b6

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

internal/ls/documenthighlights.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ func (l *LanguageService) ProvideDocumentHighlights(ctx context.Context, documen
4747
documentHighlights = l.getSyntacticDocumentHighlights(node, sourceFile)
4848
}
4949
// if nil is passed here we never generate an error, just pass an empty higlight
50-
resp := lsproto.DocumentHighlightsOrNull{DocumentHighlights: &documentHighlights}
51-
return resp, nil
50+
return lsproto.DocumentHighlightsOrNull{DocumentHighlights: &documentHighlights}, nil
5251
}
5352

5453
func (l *LanguageService) getSemanticDocumentHighlights(ctx context.Context, position int, node *ast.Node, program *compiler.Program, sourceFile *ast.SourceFile) []*lsproto.DocumentHighlight {

internal/ls/findallreferences.go

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,33 @@ func getPossibleSymbolReferencePositions(sourceFile *ast.SourceFile, symbolName
973973
return positions
974974
}
975975

976+
// findFirstJsxNode recursively searches for the first JSX element, self-closing element, or fragment
977+
func findFirstJsxNode(root *ast.Node) *ast.Node {
978+
var visit func(*ast.Node) *ast.Node
979+
visit = func(node *ast.Node) *ast.Node {
980+
// Check if this is a JSX node we're looking for
981+
switch node.Kind {
982+
case ast.KindJsxElement, ast.KindJsxSelfClosingElement, ast.KindJsxFragment:
983+
return node
984+
}
985+
986+
// Skip subtree if it doesn't contain JSX
987+
if node.SubtreeFacts()&ast.SubtreeContainsJsx == 0 {
988+
return nil
989+
}
990+
991+
// Traverse children to find JSX node
992+
var result *ast.Node
993+
node.ForEachChild(func(child *ast.Node) bool {
994+
result = visit(child)
995+
return result != nil // Stop if found
996+
})
997+
return result
998+
}
999+
1000+
return visit(root)
1001+
}
1002+
9761003
func getReferencesForNonModule(referencedFile *ast.SourceFile, program *compiler.Program) []*referenceEntry {
9771004
// !!! not implemented
9781005
return []*referenceEntry{}
@@ -1013,13 +1040,21 @@ func getReferencedSymbolsForModule(ctx context.Context, program *compiler.Progra
10131040
// import("foo") with no qualifier will reference the `export =` of the module, which may be referenced anyway.
10141041
return newNodeEntry(reference.literal)
10151042
case ModuleReferenceKindImplicit:
1016-
// For implicit references (e.g., JSX runtime imports), return the first statement or the whole file.
1017-
// We skip the complex JSX detection for now and just use the first statement or the file itself.
1043+
// For implicit references (e.g., JSX runtime imports), return the first JSX node,
1044+
// the first statement, or the whole file
10181045
var rangeNode *ast.Node
1019-
if reference.referencingFile.Statements != nil && len(reference.referencingFile.Statements.Nodes) > 0 {
1020-
rangeNode = reference.referencingFile.Statements.Nodes[0]
1021-
} else {
1022-
rangeNode = reference.referencingFile.AsNode()
1046+
1047+
// Skip the JSX search for tslib imports
1048+
if reference.literal.Text() != "tslib" {
1049+
rangeNode = findFirstJsxNode(reference.referencingFile.AsNode())
1050+
}
1051+
1052+
if rangeNode == nil {
1053+
if reference.referencingFile.Statements != nil && len(reference.referencingFile.Statements.Nodes) > 0 {
1054+
rangeNode = reference.referencingFile.Statements.Nodes[0]
1055+
} else {
1056+
rangeNode = reference.referencingFile.AsNode()
1057+
}
10231058
}
10241059
return newNodeEntry(rangeNode)
10251060
case ModuleReferenceKindReference:
@@ -1060,8 +1095,9 @@ func getReferencedSymbolsForModule(ctx context.Context, program *compiler.Progra
10601095
if ast.IsBinaryExpression(decl) && ast.IsPropertyAccessExpression(decl.AsBinaryExpression().Left) {
10611096
node = decl.AsBinaryExpression().Left.AsPropertyAccessExpression().Expression
10621097
} else if ast.IsExportAssignment(decl) {
1063-
// Find the export keyword - for now, just use the declaration itself
1064-
node = decl
1098+
// Find the export keyword
1099+
node = findChildOfKind(decl, ast.KindExportKeyword, sourceFile)
1100+
debug.Assert(node != nil, "Expected to find export keyword")
10651101
} else {
10661102
node = ast.GetNameOfDeclaration(decl)
10671103
if node == nil {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// === findAllReferences ===
99
// === /a.ts ===
1010
// type T = number;
11-
// /*FIND ALL REFS*/[|export = T;|]
11+
// /*FIND ALL REFS*/[|export|] = T;
1212

1313
// === /b.ts ===
1414
// import T = require("[|./a|]");
@@ -38,7 +38,7 @@
3838
// === findAllReferences ===
3939
// === /a.ts ===
4040
// type [|T|] = number;
41-
// [|export = [|T|];|]
41+
// [|export|] = [|T|];
4242

4343
// === /b.ts ===
4444
// import [|T|] = require("/*FIND ALL REFS*/[|./a|]");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// === findAllReferences ===
22
// === /packages/playwright-core/bundles/utils/node_modules/@types/debug/index.d.ts ===
33
// declare var [|debug|]: [|debug|].Debug & { debug: [|debug|].Debug; default: [|debug|].Debug };
4-
// [|export = [|debug|];|]
4+
// [|export|] = [|debug|];
55
// export as namespace debug;
66
// declare namespace [|debug|] {
77
// interface Debug {

0 commit comments

Comments
 (0)