@@ -962,17 +962,21 @@ package actor BuildServerManager: QueueBasedMessageHandler {
962962 return locations. map { locationAdjustedForCopiedFiles ( $0) }
963963 }
964964
965+ /// Check if the URI has been copied during the preparation phase. If so, return the original source URI.
966+ private func uriAdjustedForCopiedFiles( _ uri: DocumentURI ) -> DocumentURI {
967+ return cachedCopiedFileMap [ uri] ?? uri
968+ }
969+
970+ // ahopen: I don’t think any of these functions need to be async.
965971 package func workspaceEditAdjustedForCopiedFiles( _ workspaceEdit: WorkspaceEdit ? ) async -> WorkspaceEdit ? {
966972 guard var edit = workspaceEdit else {
967973 return nil
968974 }
969975 if let changes = edit. changes {
970976 var newChanges : [ DocumentURI : [ TextEdit ] ] = [ : ]
971977 for (uri, edits) in changes {
972- let newUri = self . locationAdjustedForCopiedFiles (
973- Location ( uri: uri, range: Position ( line: 0 , utf16index: 0 ) ..< Position ( line: 0 , utf16index: 0 ) )
974- ) . uri
975- newChanges [ newUri, default: [ ] ] . append ( contentsOf: edits)
978+ let newUri = self . uriAdjustedForCopiedFiles ( uri)
979+ newChanges [ newUri, default: [ ] ] += edits
976980 }
977981 edit. changes = newChanges
978982 }
@@ -981,32 +985,17 @@ package actor BuildServerManager: QueueBasedMessageHandler {
981985 for change in documentChanges {
982986 switch change {
983987 case . textDocumentEdit( var textEdit) :
984- let newUri = self . locationAdjustedForCopiedFiles (
985- Location ( uri: textEdit. textDocument. uri, range: Position ( line: 0 , utf16index: 0 ) ..< Position ( line: 0 , utf16index: 0 ) )
986- ) . uri
987- textEdit. textDocument. uri = newUri
988+ textEdit. textDocument. uri = self . uriAdjustedForCopiedFiles ( textEdit. textDocument. uri)
988989 newDocumentChanges. append ( . textDocumentEdit( textEdit) )
989990 case . createFile( var create) :
990- let newUri = self . locationAdjustedForCopiedFiles (
991- Location ( uri: create. uri, range: Position ( line: 0 , utf16index: 0 ) ..< Position ( line: 0 , utf16index: 0 ) )
992- ) . uri
993- create. uri = newUri
991+ create. uri = self . uriAdjustedForCopiedFiles ( create. uri)
994992 newDocumentChanges. append ( . createFile( create) )
995993 case . renameFile( var rename) :
996- let newOldUri = self . locationAdjustedForCopiedFiles (
997- Location ( uri: rename. oldUri, range: Position ( line: 0 , utf16index: 0 ) ..< Position ( line: 0 , utf16index: 0 ) )
998- ) . uri
999- let newNewUri = self . locationAdjustedForCopiedFiles (
1000- Location ( uri: rename. newUri, range: Position ( line: 0 , utf16index: 0 ) ..< Position ( line: 0 , utf16index: 0 ) )
1001- ) . uri
1002- rename. oldUri = newOldUri
1003- rename. newUri = newNewUri
994+ rename. oldUri = self . uriAdjustedForCopiedFiles ( rename. oldUri)
995+ rename. newUri = self . uriAdjustedForCopiedFiles ( rename. newUri)
1004996 newDocumentChanges. append ( . renameFile( rename) )
1005997 case . deleteFile( var delete) :
1006- let newUri = self . locationAdjustedForCopiedFiles (
1007- Location ( uri: delete. uri, range: Position ( line: 0 , utf16index: 0 ) ..< Position ( line: 0 , utf16index: 0 ) )
1008- ) . uri
1009- delete. uri = newUri
998+ delete. uri = self . uriAdjustedForCopiedFiles ( delete. uri)
1010999 newDocumentChanges. append ( . deleteFile( delete) )
10111000 }
10121001 }
@@ -1021,33 +1010,35 @@ package actor BuildServerManager: QueueBasedMessageHandler {
10211010 }
10221011 switch response {
10231012 case . locations( let locations) :
1024- let remappedLocations = await self . locationsAdjustedForCopiedFiles ( locations)
1013+ let remappedLocations = self . locationsAdjustedForCopiedFiles ( locations)
10251014 return . locations( remappedLocations)
10261015 case . locationLinks( let locationLinks) :
10271016 var remappedLinks : [ LocationLink ] = [ ]
10281017 for link in locationLinks {
1029- let newUri = self . locationAdjustedForCopiedFiles ( Location ( uri: link. targetUri, range: link. targetRange) ) . uri
1018+ let adjustedTargetLocation = self . locationAdjustedForCopiedFiles ( Location ( uri: link. targetUri, range: link. targetRange) )
1019+ let adjustedTargetSelectionLocation = self . locationAdjustedForCopiedFiles ( Location ( uri: link. targetUri, range: link. targetSelectionRange) )
10301020 remappedLinks. append ( LocationLink (
10311021 originSelectionRange: link. originSelectionRange,
1032- targetUri: newUri ,
1033- targetRange: link . targetRange ,
1034- targetSelectionRange: link . targetSelectionRange
1022+ targetUri: adjustedTargetLocation . uri ,
1023+ targetRange: adjustedTargetLocation . range ,
1024+ targetSelectionRange: adjustedTargetSelectionLocation . range
10351025 ) )
10361026 }
10371027 return . locationLinks( remappedLinks)
10381028 }
10391029 }
10401030
10411031 package func typeHierarchyItemAdjustedForCopiedFiles( _ item: TypeHierarchyItem ) async -> TypeHierarchyItem {
1042- let adjustedLocation = await self . locationAdjustedForCopiedFiles ( Location ( uri: item. uri, range: item. range) )
1032+ let adjustedLocation = self . locationAdjustedForCopiedFiles ( Location ( uri: item. uri, range: item. range) )
1033+ let adjustedSelectionLocation = self . locationAdjustedForCopiedFiles ( Location ( uri: item. uri, range: item. selectionRange) )
10431034 return TypeHierarchyItem (
10441035 name: item. name,
10451036 kind: item. kind,
10461037 tags: item. tags,
10471038 detail: item. detail,
10481039 uri: adjustedLocation. uri,
10491040 range: adjustedLocation. range,
1050- selectionRange: item . selectionRange ,
1041+ selectionRange: adjustedSelectionLocation . range ,
10511042 data: item. data
10521043 )
10531044 }
0 commit comments