Skip to content

Commit 3250b31

Browse files
committed
more
1 parent 4980bf4 commit 3250b31

9 files changed

+83
-9
lines changed

internal/ls/documenthighlights.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ 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-
return lsproto.DocumentHighlightsOrNull{DocumentHighlights: &documentHighlights}, nil
50+
resp := lsproto.DocumentHighlightsOrNull{DocumentHighlights: &documentHighlights}
51+
return resp, nil
5152
}
5253

5354
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: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ func (l *LanguageService) getReferencedSymbolsForNode(ctx context.Context, posit
621621
}
622622

623623
if moduleSymbol := checker.GetMergedSymbol(resolvedRef.file.Symbol); moduleSymbol != nil {
624-
return getReferencedSymbolsForModule(program, moduleSymbol /*excludeImportTypeOfExportEquals*/, false, sourceFiles, sourceFilesSet)
624+
return getReferencedSymbolsForModule(ctx, program, moduleSymbol /*excludeImportTypeOfExportEquals*/, false, sourceFiles, sourceFilesSet)
625625
}
626626

627627
// !!! not implemented
@@ -669,11 +669,11 @@ func (l *LanguageService) getReferencedSymbolsForNode(ctx context.Context, posit
669669
}
670670

671671
if symbol.Name == ast.InternalSymbolNameExportEquals {
672-
return getReferencedSymbolsForModule(program, symbol.Parent, false /*excludeImportTypeOfExportEquals*/, sourceFiles, sourceFilesSet)
672+
return getReferencedSymbolsForModule(ctx, program, symbol.Parent, false /*excludeImportTypeOfExportEquals*/, sourceFiles, sourceFilesSet)
673673
}
674674

675675
moduleReferences := l.getReferencedSymbolsForModuleIfDeclaredBySourceFile(ctx, symbol, program, sourceFiles, checker, options, sourceFilesSet) // !!! cancellationToken
676-
if moduleReferences != nil && symbol.Flags&ast.SymbolFlagsTransient != 0 {
676+
if moduleReferences != nil && symbol.Flags&ast.SymbolFlagsTransient == 0 {
677677
return moduleReferences
678678
}
679679

@@ -696,7 +696,7 @@ func (l *LanguageService) getReferencedSymbolsForModuleIfDeclaredBySourceFile(ct
696696
}
697697
exportEquals := symbol.Exports[ast.InternalSymbolNameExportEquals]
698698
// If exportEquals != nil, we're about to add references to `import("mod")` anyway, so don't double-count them.
699-
moduleReferences := getReferencedSymbolsForModule(program, symbol, exportEquals != nil, sourceFiles, sourceFilesSet)
699+
moduleReferences := getReferencedSymbolsForModule(ctx, program, symbol, exportEquals != nil, sourceFiles, sourceFilesSet)
700700
if exportEquals == nil || !sourceFilesSet.Has(moduleSourceFileName) {
701701
return moduleReferences
702702
}
@@ -975,13 +975,14 @@ func getMergedAliasedSymbolOfNamespaceExportDeclaration(node *ast.Node, symbol *
975975
return nil
976976
}
977977

978-
func getReferencedSymbolsForModule(program *compiler.Program, symbol *ast.Symbol, excludeImportTypeOfExportEquals bool, sourceFiles []*ast.SourceFile, sourceFilesSet *collections.Set[string]) []*SymbolAndEntries {
978+
func getReferencedSymbolsForModule(ctx context.Context, program *compiler.Program, symbol *ast.Symbol, excludeImportTypeOfExportEquals bool, sourceFiles []*ast.SourceFile, sourceFilesSet *collections.Set[string]) []*SymbolAndEntries {
979979
debug.Assert(symbol.ValueDeclaration != nil)
980980

981-
checker, done := program.GetTypeChecker(nil)
981+
checker, done := program.GetTypeChecker(ctx)
982982
defer done()
983983

984-
references := core.MapNonNil(findModuleReferences(program, sourceFiles, symbol, checker), func(reference ModuleReference) *referenceEntry {
984+
moduleRefs := findModuleReferences(program, sourceFiles, symbol, checker)
985+
references := core.MapNonNil(moduleRefs, func(reference ModuleReference) *referenceEntry {
985986
switch reference.kind {
986987
case ModuleReferenceKindImport:
987988
parent := reference.literal.Parent
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// === documentHighlights ===
22
// === /b.ts ===
3-
// import { x } from "/*HIGHLIGHTS*/./a";
3+
// import { x } from "/*HIGHLIGHTS*/[|./a|]";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// === findAllReferences ===
2+
// === /foo.ts ===
3+
// export function foo() { return "foo"; }
4+
// /*FIND ALL REFS*/import("./foo")
5+
// var x = import("./foo")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// === findAllReferences ===
2+
// === /node_modules/@types/three/index.d.ts ===
3+
// export * from "./three-core";
4+
// export as namespace /*FIND ALL REFS*/[|THREE|];
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// === findAllReferences ===
2+
// === /a.ts ===
3+
// type /*FIND ALL REFS*/[|T|] = number;
4+
// export = T;
5+
6+
7+
8+
// === findAllReferences ===
9+
// === /a.ts ===
10+
// type T = number;
11+
// /*FIND ALL REFS*/export = T;
12+
13+
14+
15+
// === findAllReferences ===
16+
// === /a.ts ===
17+
// type T = number;
18+
// export = /*FIND ALL REFS*/[|T|];
19+
20+
// === /b.ts ===
21+
// import [|T|] = require("./a");
22+
23+
24+
25+
// === findAllReferences ===
26+
// === /a.ts ===
27+
// type [|T|] = number;
28+
// export = [|T|];
29+
30+
// === /b.ts ===
31+
// import /*FIND ALL REFS*/[|T|] = require("./a");
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// === findAllReferences ===
2+
// === /findAllRefsForDefaultExport03.ts ===
3+
// /*FIND ALL REFS*/function f() {
4+
// return 100;
5+
// }
6+
//
7+
// // --- (line: 5) skipped ---
8+
9+
10+
11+
// === findAllReferences ===
12+
// === /findAllRefsForDefaultExport03.ts ===
13+
// function /*FIND ALL REFS*/[|f|]() {
14+
// return 100;
15+
// }
16+
//
17+
// export default [|f|];
18+
//
19+
// var x: typeof [|f|];
20+
//
21+
// var y = [|f|]();
22+
//
23+
// namespace [|f|] {
24+
// var local = 100;
25+
// }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// === findAllReferences ===
2+
// === /a.js ===
3+
// /*FIND ALL REFS*/const b = require("./b");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// === findAllReferences ===
2+
// === /b.ts ===
3+
// /*FIND ALL REFS*/const x: typeof import("./a") = { x: 0 };
4+
// const y: typeof import("./a") = { x: 0 };

0 commit comments

Comments
 (0)