Skip to content

Commit 2f80cca

Browse files
authored
Merge pull request #1005 from ahoppen/ahoppen/global-rename-review
Address review comments from #993
2 parents e4c2a3f + f88c241 commit 2f80cca

File tree

3 files changed

+170
-126
lines changed

3 files changed

+170
-126
lines changed

Sources/SKTestSupport/MultiFileTestWorkspace.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import SKCore
1717
/// The location of a test file within test workspace.
1818
public struct RelativeFileLocation: Hashable, ExpressibleByStringLiteral {
1919
/// The subdirectories in which the file is located.
20-
let directories: [String]
20+
public let directories: [String]
2121

2222
/// The file's name.
23-
let fileName: String
23+
public let fileName: String
2424

2525
public init(directories: [String] = [], _ fileName: String) {
2626
self.directories = directories

Sources/SourceKitLSP/Rename.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,7 @@ extension SourceKitServer {
298298

299299
// Determine the local edits and the USR to rename
300300
let renameResult = try await languageService.rename(request)
301-
var edits = renameResult.edits
302-
if edits.changes == nil {
303-
// Make sure `edits.changes` is non-nil so we can force-unwrap it below.
304-
edits.changes = [:]
305-
}
301+
var changes = renameResult.edits.changes ?? [:]
306302

307303
if let usr = renameResult.usr, let oldName = renameResult.oldName, let index = workspace.index {
308304
// If we have a USR + old name, perform an index lookup to find workspace-wide symbols to rename.
@@ -324,7 +320,7 @@ extension SourceKitServer {
324320
await withTaskGroup(of: (DocumentURI, [TextEdit])?.self) { taskGroup in
325321
for (url, renameLocations) in locationsByFile {
326322
let uri = DocumentURI(url)
327-
if edits.changes![uri] != nil {
323+
if changes[uri] != nil {
328324
// We already have edits for this document provided by the language service, so we don't need to compute
329325
// rename ranges for it.
330326
continue
@@ -358,11 +354,13 @@ extension SourceKitServer {
358354
}
359355
}
360356
for await case let (uri, textEdits)? in taskGroup where !textEdits.isEmpty {
361-
precondition(edits.changes![uri] == nil, "We should create tasks for URIs that already have edits")
362-
edits.changes![uri] = textEdits
357+
precondition(changes[uri] == nil, "We should not create tasks for URIs that already have edits")
358+
changes[uri] = textEdits
363359
}
364360
}
365361
}
362+
var edits = renameResult.edits
363+
edits.changes = changes
366364
return edits
367365
}
368366
}

0 commit comments

Comments
 (0)