@@ -291,6 +291,16 @@ private extension RenameLocation.Usage {
291
291
}
292
292
}
293
293
294
+ private extension IndexSymbolKind {
295
+ var isMethod : Bool {
296
+ switch self {
297
+ case . instanceMethod, . classMethod, . staticMethod:
298
+ return true
299
+ default : return false
300
+ }
301
+ }
302
+ }
303
+
294
304
// MARK: - Name translation
295
305
296
306
extension SwiftLanguageServer {
@@ -321,7 +331,8 @@ extension SwiftLanguageServer {
321
331
322
332
/// Translate a Swift name to the corresponding C/C++/ObjectiveC name.
323
333
///
324
- /// This invokes the clang importer to perform the name translation.
334
+ /// This invokes the clang importer to perform the name translation, based on the `position` and `uri` at which the
335
+ /// Swift symbol is defined.
325
336
///
326
337
/// - Parameters:
327
338
/// - position: The position at which the Swift name is defined
@@ -520,7 +531,12 @@ public actor TranslatableName {
520
531
/// - Note: The symbol translation from clang to Swift requires a Swift location at which the clang symbol is
521
532
/// (probably so that sourcekitd can access the necessary AST context and get the clang importer to translate the
522
533
/// name). But the output does not actually matter on the specific position and URI. We can thus cache the result.
523
- /// Ideally, sourcekitd wouldn't need a position and URI to translate a clang name to Swift.
534
+ /// Ideally, sourcekitd wouldn't need a position and URI to translate a clang name to Swift
535
+
536
+ /// - Note: The symbol translation from Clang to Swift requires a location in Swift in which the symbol is referenced.
537
+ /// This is used both to retrieve the clang importer and to grab the underlying clang decl.
538
+ /// The exact reference used doesn't matter though, so we can cache the result across calls, regardless of the
539
+ /// position passed (assuming it is the same underlying symbol).
524
540
func swiftName(
525
541
at position: Position ,
526
542
in snapshot: DocumentSnapshot ,
@@ -568,9 +584,7 @@ extension SourceKitServer {
568
584
}
569
585
let definitionDocumentUri = DocumentURI ( URL ( fileURLWithPath: definitionSymbol. location. path) )
570
586
571
- let isObjectiveCSelector =
572
- definitionLanguage == . objective_c
573
- && ( definitionSymbol. symbol. kind == . instanceMethod || definitionSymbol. symbol. kind == . classMethod)
587
+ let isObjectiveCSelector = definitionLanguage == . objective_c && definitionSymbol. symbol. kind. isMethod
574
588
575
589
guard
576
590
let nativeLanguageService = await self . languageService (
@@ -931,7 +945,7 @@ extension SwiftLanguageServer {
931
945
newName newTranslatableName: TranslatableName
932
946
) async throws -> [ TextEdit ] {
933
947
// Pick any location for the name translation.
934
- // They should all refer to the same declaration, so sourcekitd doens 't care which one we pick.
948
+ // They should all refer to the same declaration, so sourcekitd doesn 't care which one we pick.
935
949
guard let renameLocationForNameTranslation = renameLocations. first else {
936
950
return [ ]
937
951
}
0 commit comments