Skip to content

Commit 036485a

Browse files
Fix: Delete SearchState.replaceRange, which was dead and thread-unsafe
The method had no callers anywhere in the repo, was internal to CESearch so nothing outside could reach it, witnessed no protocol requirement, and was not @objc, so no dynamic dispatch could find it either. It also built an NSAlert and called runModal() from a synchronous nonisolated method on a nonisolated class, which presents a modal alert from an arbitrary thread. Xcode 26 accepts this; the CI runner's Xcode 16.4 rejects it, correctly. The three other NSAlert sites in the packages all sit on @mainactor types and are unaffected. Removing this one leaves the file with no AppKit dependency, so that import goes too: its only other NS use, NSString.CompareOptions, is Foundation.
1 parent 87b373d commit 036485a

1 file changed

Lines changed: 0 additions & 58 deletions

File tree

‎CodeEditModules/Sources/CESearch/SearchState/SearchState+FindAndReplace.swift‎

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77

88
import Foundation
9-
import AppKit
109

1110
extension SearchState {
1211
/// Performs a search and replace operation in a collection of files based on the provided query.
@@ -107,63 +106,6 @@ extension SearchState {
107106
try updatedContent.write(to: fileURL, atomically: true, encoding: .utf8)
108107
}
109108

110-
/// Replaces a specified range of text within a file with a new string.
111-
///
112-
/// - Parameters:
113-
/// - file: The URL of the file to be modified.
114-
/// - searchTerm: The string to be replaced within the specified range.
115-
/// - replacingTerm: The string to replace the specified searchTerm.
116-
/// - keywordRange: The range within which the replacement should occur.
117-
///
118-
/// - Note: This function can be utilised for two specific use cases:
119-
/// 1. To replace a particular occurrence of a string within a file,
120-
/// provide the range of the keyword to be replaced.
121-
/// 2. To replace all occurrences of the string within the file,
122-
/// pass the start and end index covering the entire range.
123-
func replaceRange(
124-
file: URL,
125-
searchTerm: String,
126-
replacingTerm: String,
127-
keywordRange: Range<String.Index>
128-
) {
129-
guard let fileContent = try? String(contentsOf: file, encoding: .utf8) else {
130-
let alert = NSAlert()
131-
alert.messageText = "Error"
132-
alert.informativeText = "An error occurred while reading file contents of: \(file)"
133-
alert.alertStyle = .critical
134-
alert.addButton(withTitle: "OK")
135-
alert.runModal()
136-
137-
return
138-
}
139-
140-
var replaceOptions = NSString.CompareOptions()
141-
if selectedMode.second == .RegularExpression {
142-
replaceOptions = [.regularExpression]
143-
}
144-
if !caseSensitive {
145-
replaceOptions = [.caseInsensitive]
146-
}
147-
148-
let updatedContent = fileContent.replacingOccurrences(
149-
of: searchTerm,
150-
with: replacingTerm,
151-
options: replaceOptions,
152-
range: keywordRange
153-
)
154-
155-
do {
156-
try updatedContent.write(to: file, atomically: true, encoding: .utf8)
157-
} catch {
158-
let alert = NSAlert()
159-
alert.messageText = "Error"
160-
alert.informativeText = "An error occurred while writing to: \(error.localizedDescription)"
161-
alert.alertStyle = .critical
162-
alert.addButton(withTitle: "OK")
163-
alert.runModal()
164-
}
165-
}
166-
167109
func setStatus(_ status: FindNavigatorStatus) async {
168110
await MainActor.run {
169111
self.findNavigatorStatus = status

0 commit comments

Comments
 (0)