@@ -14,6 +14,7 @@ import Csourcekitd
14
14
import Foundation
15
15
import IndexStoreDB
16
16
package import LanguageServerProtocol
17
+ import LanguageServerProtocolExtensions
17
18
import SKLogging
18
19
import SKUtilities
19
20
import SemanticIndex
@@ -451,11 +452,11 @@ extension SwiftLanguageService {
451
452
package struct CrossLanguageName : Sendable {
452
453
/// The name of the symbol in clang languages or `nil` if the symbol is defined in Swift, doesn't have any references
453
454
/// from clang languages and thus hasn't been translated.
454
- fileprivate let clangName : String ?
455
+ package let clangName : String ?
455
456
456
457
/// The name of the symbol in Swift or `nil` if the symbol is defined in clang, doesn't have any references from
457
458
/// Swift and thus hasn't been translated.
458
- fileprivate let swiftName : String ?
459
+ package let swiftName : String ?
459
460
460
461
fileprivate var compoundSwiftName : CompoundDeclName ? {
461
462
if let swiftName {
@@ -465,10 +466,10 @@ package struct CrossLanguageName: Sendable {
465
466
}
466
467
467
468
/// the language that the symbol is defined in.
468
- fileprivate let definitionLanguage : Language
469
+ package let definitionLanguage : Language
469
470
470
471
/// The name of the symbol in the language that it is defined in.
471
- var definitionName : String ? {
472
+ package var definitionName : String ? {
472
473
switch definitionLanguage {
473
474
case . c, . cpp, . objective_c, . objective_cpp:
474
475
return clangName
@@ -576,20 +577,10 @@ extension SourceKitLSPServer {
576
577
}
577
578
let definitionDocumentUri = definitionOccurrence. location. documentUri
578
579
579
- guard
580
- let definitionLanguageService = await self . languageService (
581
- for: definitionDocumentUri,
582
- definitionLanguage,
583
- in: workspace
584
- )
585
- else {
586
- throw ResponseError . unknown ( " Failed to get language service for the document defining \( usr) " )
587
- }
588
-
589
580
let definitionName = overrideName ?? definitionSymbol. name
590
581
591
- switch definitionLanguageService {
592
- case is ClangLanguageService :
582
+ switch definitionLanguage . semanticKind {
583
+ case . clang :
593
584
let swiftName : String ?
594
585
if let swiftReference = await getReferenceFromSwift ( usr: usr, index: index, workspace: workspace) {
595
586
let isObjectiveCSelector = definitionLanguage == . objective_c && definitionSymbol. kind. isMethod
@@ -604,7 +595,16 @@ extension SourceKitLSPServer {
604
595
swiftName = nil
605
596
}
606
597
return CrossLanguageName ( clangName: definitionName, swiftName: swiftName, definitionLanguage: definitionLanguage)
607
- case let swiftLanguageService as SwiftLanguageService :
598
+ case . swift:
599
+ guard
600
+ let swiftLanguageService = await self . languageService (
601
+ for: definitionDocumentUri,
602
+ definitionLanguage,
603
+ in: workspace
604
+ ) as? SwiftLanguageService
605
+ else {
606
+ throw ResponseError . unknown ( " Failed to get language service for the document defining \( usr) " )
607
+ }
608
608
// Continue iteration if the symbol provider is not clang.
609
609
// If we terminate early by returning `false` from the closure, `forEachSymbolOccurrence` returns `true`,
610
610
// indicating that we have found a reference from clang.
@@ -1358,71 +1358,6 @@ extension SwiftLanguageService {
1358
1358
1359
1359
// MARK: - Clang
1360
1360
1361
- extension ClangLanguageService {
1362
- func rename( _ renameRequest: RenameRequest ) async throws -> ( edits: WorkspaceEdit , usr: String ? ) {
1363
- async let edits = forwardRequestToClangd ( renameRequest)
1364
- let symbolInfoRequest = SymbolInfoRequest (
1365
- textDocument: renameRequest. textDocument,
1366
- position: renameRequest. position
1367
- )
1368
- let symbolDetail = try await forwardRequestToClangd ( symbolInfoRequest) . only
1369
- return ( try await edits ?? WorkspaceEdit ( ) , symbolDetail? . usr)
1370
- }
1371
-
1372
- func editsToRename(
1373
- locations renameLocations: [ RenameLocation ] ,
1374
- in snapshot: DocumentSnapshot ,
1375
- oldName oldCrossLanguageName: CrossLanguageName ,
1376
- newName newCrossLanguageName: CrossLanguageName
1377
- ) async throws -> [ TextEdit ] {
1378
- let positions = [
1379
- snapshot. uri: renameLocations. compactMap { snapshot. position ( of: $0) }
1380
- ]
1381
- guard
1382
- let oldName = oldCrossLanguageName. clangName,
1383
- let newName = newCrossLanguageName. clangName
1384
- else {
1385
- throw ResponseError . unknown (
1386
- " Failed to rename \( snapshot. uri. forLogging) because the clang name for rename is unknown "
1387
- )
1388
- }
1389
- let request = IndexedRenameRequest (
1390
- textDocument: TextDocumentIdentifier ( snapshot. uri) ,
1391
- oldName: oldName,
1392
- newName: newName,
1393
- positions: positions
1394
- )
1395
- do {
1396
- let edits = try await forwardRequestToClangd ( request)
1397
- return edits? . changes ? [ snapshot. uri] ?? [ ]
1398
- } catch {
1399
- logger. error ( " Failed to get indexed rename edits: \( error. forLogging) " )
1400
- return [ ]
1401
- }
1402
- }
1403
-
1404
- package func prepareRename(
1405
- _ request: PrepareRenameRequest
1406
- ) async throws -> ( prepareRename: PrepareRenameResponse , usr: String ? ) ? {
1407
- guard let prepareRename = try await forwardRequestToClangd ( request) else {
1408
- return nil
1409
- }
1410
- let symbolInfo = try await forwardRequestToClangd (
1411
- SymbolInfoRequest ( textDocument: request. textDocument, position: request. position)
1412
- )
1413
- return ( prepareRename, symbolInfo. only? . usr)
1414
- }
1415
-
1416
- package func editsToRenameParametersInFunctionBody(
1417
- snapshot: DocumentSnapshot ,
1418
- renameLocation: RenameLocation ,
1419
- newName: CrossLanguageName
1420
- ) async -> [ TextEdit ] {
1421
- // When renaming a clang function name, we don't need to rename any references to the arguments.
1422
- return [ ]
1423
- }
1424
- }
1425
-
1426
1361
fileprivate extension SyntaxProtocol {
1427
1362
/// Returns the parent node and casts it to the specified type.
1428
1363
func parent< S: SyntaxProtocol > ( as syntaxType: S . Type ) -> S ? {
0 commit comments