@@ -500,7 +500,7 @@ extension SourceKitLSPServer {
500
500
) async -> ( swiftLanguageService: SwiftLanguageService , snapshot: DocumentSnapshot , location: SymbolLocation ) ? {
501
501
var reference : SymbolOccurrence ? = nil
502
502
index. forEachSymbolOccurrence ( byUSR: usr, roles: renameRoles) {
503
- if index . unchecked . symbolProvider ( for : $0. location . path ) == . swift {
503
+ if $0. symbolProvider == . swift {
504
504
reference = $0
505
505
// We have found a reference from Swift. Stop iteration.
506
506
return false
@@ -631,7 +631,7 @@ extension SourceKitLSPServer {
631
631
// If we terminate early by returning `false` from the closure, `forEachSymbolOccurrence` returns `true`,
632
632
// indicating that we have found a reference from clang.
633
633
let hasReferenceFromClang = !index. forEachSymbolOccurrence ( byUSR: usr, roles: renameRoles) {
634
- return index . unchecked . symbolProvider ( for : $0. location . path ) != . clang
634
+ return $0. symbolProvider != . clang
635
635
}
636
636
let clangName : String ?
637
637
if hasReferenceFromClang {
@@ -730,29 +730,7 @@ extension SourceKitLSPServer {
730
730
731
731
// If we have a USR + old name, perform an index lookup to find workspace-wide symbols to rename.
732
732
// First, group all occurrences of that USR by the files they occur in.
733
- var locationsByFile : [ URL : [ RenameLocation ] ] = [ : ]
734
-
735
- actor LanguageServerTypesCache {
736
- let index : UncheckedIndex
737
- var languageServerTypesCache : [ URL : LanguageServerType ? ] = [ : ]
738
-
739
- init ( index: UncheckedIndex ) {
740
- self . index = index
741
- }
742
-
743
- func languageServerType( for url: URL ) -> LanguageServerType ? {
744
- if let cachedValue = languageServerTypesCache [ url] {
745
- return cachedValue
746
- }
747
- let serverType = LanguageServerType (
748
- symbolProvider: index. symbolProvider ( for: url. path)
749
- )
750
- languageServerTypesCache [ url] = serverType
751
- return serverType
752
- }
753
- }
754
-
755
- let languageServerTypesCache = LanguageServerTypesCache ( index: index. unchecked)
733
+ var locationsByFile : [ URL : ( renameLocations: [ RenameLocation ] , symbolProvider: SymbolProviderKind ) ] = [ : ]
756
734
757
735
let usrsToRename = overridingAndOverriddenUsrs ( of: usr, index: index)
758
736
let occurrencesToRename = usrsToRename. flatMap { index. occurrences ( ofUSR: $0, roles: renameRoles) }
@@ -767,19 +745,16 @@ extension SourceKitLSPServer {
767
745
// perform an indexed rename for it.
768
746
continue
769
747
}
770
- switch await languageServerTypesCache . languageServerType ( for : url ) {
748
+ switch occurrence . symbolProvider {
771
749
case . swift:
772
750
// sourcekitd only produces AST-based results for the direct calls to this USR. This is because the Swift
773
751
// AST only has upwards references to superclasses and overridden methods, not the other way round. It is
774
752
// thus not possible to (easily) compute an up-down closure like described in `overridingAndOverriddenUsrs`.
775
753
// We thus need to perform an indexed rename for other, related USRs.
776
754
break
777
- case . clangd :
755
+ case . clang :
778
756
// clangd produces AST-based results for the entire class hierarchy, so nothing to do.
779
757
continue
780
- case nil :
781
- // Unknown symbol provider
782
- continue
783
758
}
784
759
}
785
760
@@ -788,26 +763,40 @@ extension SourceKitLSPServer {
788
763
utf8Column: occurrence. location. utf8Column,
789
764
usage: RenameLocation . Usage ( roles: occurrence. roles)
790
765
)
791
- locationsByFile [ url, default: [ ] ] . append ( renameLocation)
766
+ if let existingLocations = locationsByFile [ url] {
767
+ if existingLocations. symbolProvider != occurrence. symbolProvider {
768
+ logger. fault (
769
+ """
770
+ Found mismatching symbol providers for \( DocumentURI ( url) . forLogging) : \
771
+ \( String ( describing: existingLocations. symbolProvider) , privacy: . public) vs \
772
+ \( String ( describing: occurrence. symbolProvider) , privacy: . public)
773
+ """
774
+ )
775
+ }
776
+ locationsByFile [ url] = ( existingLocations. renameLocations + [ renameLocation] , occurrence. symbolProvider)
777
+ } else {
778
+ locationsByFile [ url] = ( [ renameLocation] , occurrence. symbolProvider)
779
+ }
792
780
}
793
781
794
782
// Now, call `editsToRename(locations:in:oldName:newName:)` on the language service to convert these ranges into
795
783
// edits.
796
784
let urisAndEdits =
797
785
await locationsByFile
798
- . concurrentMap { ( url: URL , renameLocations: [ RenameLocation ] ) -> ( DocumentURI , [ TextEdit ] ) ? in
786
+ . concurrentMap {
787
+ (
788
+ url: URL ,
789
+ value: ( renameLocations: [ RenameLocation ] , symbolProvider: SymbolProviderKind )
790
+ ) -> ( DocumentURI , [ TextEdit ] ) ? in
799
791
let uri = DocumentURI ( url)
800
792
let language : Language
801
- switch await languageServerTypesCache . languageServerType ( for : url ) {
802
- case . clangd :
793
+ switch value . symbolProvider {
794
+ case . clang :
803
795
// Technically, we still don't know the language of the source file but defaulting to C is sufficient to
804
796
// ensure we get the clang toolchain language server, which is all we care about.
805
797
language = . c
806
798
case . swift:
807
799
language = . swift
808
- case nil :
809
- logger. error ( " Failed to determine symbol provider for \( uri. forLogging) " )
810
- return nil
811
800
}
812
801
// Create a document snapshot to operate on. If the document is open, load it from the document manager,
813
802
// otherwise conjure one from the file on disk. We need the file in memory to perform UTF-8 to UTF-16 column
@@ -823,13 +812,13 @@ extension SourceKitLSPServer {
823
812
var edits : [ TextEdit ] =
824
813
await orLog ( " Getting edits for rename location " ) {
825
814
return try await languageService. editsToRename (
826
- locations: renameLocations,
815
+ locations: value . renameLocations,
827
816
in: snapshot,
828
817
oldName: oldName,
829
818
newName: newName
830
819
)
831
820
} ?? [ ]
832
- for location in renameLocations where location. usage == . definition {
821
+ for location in value . renameLocations where location. usage == . definition {
833
822
edits += await languageService. editsToRenameParametersInFunctionBody (
834
823
snapshot: snapshot,
835
824
renameLocation: location,
0 commit comments