@@ -163,7 +163,7 @@ final actor WorkDoneProgressState {
163
163
fileprivate enum TaskMetadata : DependencyTracker {
164
164
/// A task that changes the global configuration of sourcekit-lsp in any way.
165
165
///
166
- /// No other tasks must execute simulateneously with this task since they
166
+ /// No other tasks must execute simultaneously with this task since they
167
167
/// might be relying on this task to take effect.
168
168
case globalConfigurationChange
169
169
@@ -336,6 +336,8 @@ fileprivate enum TaskMetadata: DependencyTracker {
336
336
self = . freestanding
337
337
case is WorkspaceSymbolsRequest :
338
338
self = . freestanding
339
+ case is WorkspaceTestsRequest :
340
+ self = . freestanding
339
341
default :
340
342
logger. error (
341
343
"""
@@ -837,6 +839,8 @@ extension SourceKitServer: MessageHandler {
837
839
await request. reply { try await shutdown ( request. params) }
838
840
case let request as RequestAndReply < WorkspaceSymbolsRequest > :
839
841
await request. reply { try await workspaceSymbols ( request. params) }
842
+ case let request as RequestAndReply < WorkspaceTestsRequest > :
843
+ await request. reply { try await workspaceTests ( request. params) }
840
844
case let request as RequestAndReply < PollIndexRequest > :
841
845
await request. reply { try await pollIndex ( request. params) }
842
846
case let request as RequestAndReply < BarrierRequest > :
@@ -1499,7 +1503,7 @@ extension SourceKitServer {
1499
1503
guard matching. count >= minWorkspaceSymbolPatternLength else {
1500
1504
return [ ]
1501
1505
}
1502
- var symbolOccurenceResults : [ SymbolOccurrence ] = [ ]
1506
+ var symbolOccurrenceResults : [ SymbolOccurrence ] = [ ]
1503
1507
for workspace in workspaces {
1504
1508
workspace. index? . forEachCanonicalSymbolOccurrence (
1505
1509
containing: matching,
@@ -1511,48 +1515,35 @@ extension SourceKitServer {
1511
1515
guard !symbol. location. isSystem && !symbol. roles. contains ( . accessorOf) else {
1512
1516
return true
1513
1517
}
1514
- symbolOccurenceResults . append ( symbol)
1518
+ symbolOccurrenceResults . append ( symbol)
1515
1519
// FIXME: Once we have cancellation support, we should fetch all results and take the top
1516
1520
// `maxWorkspaceSymbolResults` symbols but bail if cancelled.
1517
1521
//
1518
1522
// Until then, take the first `maxWorkspaceSymbolResults` symbols to limit the impact of
1519
1523
// queries which match many symbols.
1520
- return symbolOccurenceResults . count < maxWorkspaceSymbolResults
1524
+ return symbolOccurrenceResults . count < maxWorkspaceSymbolResults
1521
1525
}
1522
1526
}
1523
- return symbolOccurenceResults
1527
+ return symbolOccurrenceResults
1524
1528
}
1525
1529
1526
1530
/// Handle a workspace/symbol request, returning the SymbolInformation.
1527
1531
/// - returns: An array with SymbolInformation for each matching symbol in the workspace.
1528
1532
func workspaceSymbols( _ req: WorkspaceSymbolsRequest ) async throws -> [ WorkspaceSymbolItem ] ? {
1529
- let symbols = findWorkspaceSymbols (
1530
- matching: req. query
1531
- ) . map ( { symbolOccurrence -> WorkspaceSymbolItem in
1532
- let symbolPosition = Position (
1533
- line: symbolOccurrence. location. line - 1 , // 1-based -> 0-based
1534
- // FIXME: we need to convert the utf8/utf16 column, which may require reading the file!
1535
- utf16index: symbolOccurrence. location. utf8Column - 1
1536
- )
1537
-
1538
- let symbolLocation = Location (
1539
- uri: DocumentURI ( URL ( fileURLWithPath: symbolOccurrence. location. path) ) ,
1540
- range: Range ( symbolPosition)
1541
- )
1542
-
1543
- return . symbolInformation(
1544
- SymbolInformation (
1545
- name: symbolOccurrence. symbol. name,
1546
- kind: symbolOccurrence. symbol. kind. asLspSymbolKind ( ) ,
1547
- deprecated: nil ,
1548
- location: symbolLocation,
1549
- containerName: symbolOccurrence. getContainerName ( )
1550
- )
1551
- )
1552
- } )
1533
+ let symbols = findWorkspaceSymbols ( matching: req. query) . map ( WorkspaceSymbolItem . init)
1553
1534
return symbols
1554
1535
}
1555
1536
1537
+ func workspaceTests( _ req: WorkspaceTestsRequest ) async throws -> [ WorkspaceSymbolItem ] ? {
1538
+ let testSymbols = workspaces. flatMap { ( workspace) -> [ SymbolOccurrence ] in
1539
+ guard let index = workspace. index else {
1540
+ return [ ]
1541
+ }
1542
+ return index. unitTests ( )
1543
+ }
1544
+ return testSymbols. map ( WorkspaceSymbolItem . init)
1545
+ }
1546
+
1556
1547
/// Forwards a SymbolInfoRequest to the appropriate toolchain service for this document.
1557
1548
func symbolInfo(
1558
1549
_ req: SymbolInfoRequest ,
@@ -2294,3 +2285,28 @@ fileprivate func transitiveSubtypeClosure(ofUsrs usrs: [String], index: IndexSto
2294
2285
}
2295
2286
return result
2296
2287
}
2288
+
2289
+ fileprivate extension WorkspaceSymbolItem {
2290
+ init ( _ symbolOccurrence: SymbolOccurrence ) {
2291
+ let symbolPosition = Position (
2292
+ line: symbolOccurrence. location. line - 1 , // 1-based -> 0-based
2293
+ // FIXME: we need to convert the utf8/utf16 column, which may require reading the file!
2294
+ utf16index: symbolOccurrence. location. utf8Column - 1
2295
+ )
2296
+
2297
+ let symbolLocation = Location (
2298
+ uri: DocumentURI ( URL ( fileURLWithPath: symbolOccurrence. location. path) ) ,
2299
+ range: Range ( symbolPosition)
2300
+ )
2301
+
2302
+ self = . symbolInformation(
2303
+ SymbolInformation (
2304
+ name: symbolOccurrence. symbol. name,
2305
+ kind: symbolOccurrence. symbol. kind. asLspSymbolKind ( ) ,
2306
+ deprecated: nil ,
2307
+ location: symbolLocation,
2308
+ containerName: symbolOccurrence. getContainerName ( )
2309
+ )
2310
+ )
2311
+ }
2312
+ }
0 commit comments