Skip to content

Commit 49cea92

Browse files
committed
Addressed PR issues
1 parent 6b31c32 commit 49cea92

File tree

6 files changed

+56
-34
lines changed

6 files changed

+56
-34
lines changed

CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+Find.swift

+11-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ extension WorkspaceDocument.SearchState {
129129
)
130130

131131
if let result = result {
132-
await MainActor.run {
133-
self.tempSearchResults.append(result)
134-
}
132+
await self.appendNewResultsToTempResults(newResult: result)
135133
}
136134
evaluateResultGroup.leave()
137135
}
@@ -356,6 +354,16 @@ extension WorkspaceDocument.SearchState {
356354
}
357355
}
358356

357+
/// Evaluates a matched file to determine if it contains any search matches.
358+
/// Requires a file score from the search model.
359+
///
360+
/// Evaluates the file's contents asynchronously.
361+
///
362+
/// - Parameters:
363+
/// - fileURL: The `URL` of the file to evaluate.
364+
/// - fileScore: The file's score from a ``SearchIndexer``
365+
/// - regexPattern: The pattern to evaluate against the file's contents.
366+
/// - Returns: `nil` if there are no relevant search matches, or a search result if matches are found.
359367
private func evaluateSearchResult(
360368
fileURL: URL,
361369
fileScore: Float,

CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabCloseButton.swift

+15
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,18 @@ struct EditorTabCloseButton: View {
104104
}
105105
}
106106
}
107+
108+
@available(macOS 14.0, *)
109+
#Preview {
110+
@Previewable @State var closeButtonGestureActive: Bool = false
111+
@Previewable @State var isHoveringClose: Bool = false
112+
113+
return EditorTabCloseButton(
114+
isActive: false,
115+
isHoveringTab: false,
116+
isDragging: false,
117+
closeAction: { print("Close tab") },
118+
closeButtonGestureActive: $closeButtonGestureActive,
119+
isHoveringClose: $isHoveringClose
120+
)
121+
}

CodeEdit/Features/OpenQuickly/Views/OpenQuicklyView.swift

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
import SwiftUI
99

10+
extension URL: @retroactive Identifiable {
11+
public var id: String {
12+
absoluteString
13+
}
14+
}
15+
1016
struct OpenQuicklyView: View {
1117
@EnvironmentObject private var workspace: WorkspaceDocument
1218

CodeEdit/Features/Welcome/Views/WelcomeView.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct WelcomeView: View {
2727

2828
@State var showGitClone = false
2929

30-
@State private var showCheckoutBranchItem: IdentifiableURL?
30+
@State var showCheckoutBranchItem: URL?
3131

3232
@State var isHovering: Bool = false
3333

@@ -122,16 +122,16 @@ struct WelcomeView: View {
122122
.sheet(isPresented: $showGitClone) {
123123
GitCloneView(
124124
openBranchView: { url in
125-
showCheckoutBranchItem = IdentifiableURL(url: url)
125+
showCheckoutBranchItem = url
126126
},
127127
openDocument: { url in
128128
openDocument(url, dismissWindow)
129129
}
130130
)
131131
}
132-
.sheet(item: $showCheckoutBranchItem) { wrapper in
132+
.sheet(item: $showCheckoutBranchItem) { url in
133133
GitCheckoutBranchView(
134-
repoLocalPath: wrapper.url,
134+
repoLocalPath: url,
135135
openDocument: { url in
136136
openDocument(url, dismissWindow)
137137
}

CodeEdit/Utils/ShellClient/Models/ShellClient.swift

+10-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
import Combine
99
import Foundation
1010

11+
/// Errors that can occur during shell operations
12+
enum ShellClientError: Error {
13+
case failedToDecodeOutput
14+
case taskTerminated(code: Int)
15+
}
16+
1117
/// Shell Client
1218
/// Run commands in shell
1319
class ShellClient {
@@ -38,9 +44,7 @@ class ShellClient {
3844
try task.run()
3945
let data = pipe.fileHandleForReading.readDataToEndOfFile()
4046
guard let output = String(bytes: data, encoding: .utf8) else {
41-
throw NSError(domain: "ShellClient", code: -1, userInfo: [
42-
NSLocalizedDescriptionKey: "Failed to decode command output"
43-
])
47+
throw ShellClientError.failedToDecodeOutput
4448
}
4549
return output
4650
}
@@ -71,6 +75,7 @@ class ShellClient {
7175
return
7276
}
7377
guard let output = String(bytes: data, encoding: .utf8) else {
78+
subject.send(completion: .finished)
7479
return
7580
}
7681
output.split(whereSeparator: \.isNewline)
@@ -92,19 +97,15 @@ class ShellClient {
9297
let data = fileHandle.availableData
9398
if !data.isEmpty {
9499
guard let output = String(bytes: data, encoding: .utf8) else {
95-
continuation.finish(throwing: NSError(
96-
domain: "ShellClient",
97-
code: -1,
98-
userInfo: [NSLocalizedDescriptionKey: "Failed to decode command output"]
99-
))
100+
continuation.finish(throwing: ShellClientError.failedToDecodeOutput)
100101
return
101102
}
102103
output.split(whereSeparator: \.isNewline)
103104
.forEach({ continuation.yield(String($0)) })
104105
} else {
105106
if !task.isRunning && task.terminationStatus != 0 {
106107
continuation.finish(
107-
throwing: NSError(domain: "ShellClient", code: Int(task.terminationStatus))
108+
throwing: ShellClientError.taskTerminated(code: Int(task.terminationStatus))
108109
)
109110
} else {
110111
continuation.finish()

CodeEditTests/Features/TerminalEmulator/Shell/ShellTests.swift

+10-18
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class ShellTests: XCTestCase {
2424
super.tearDown()
2525
}
2626

27-
func testExecuteCommandWithShellInitialization() {
27+
func testExecuteCommandWithShellInitialization() throws {
2828
let command = "echo $STATE"
2929
let environmentVariables = ["STATE": "Testing"]
3030
let shell: Shell = .bash
@@ -45,17 +45,13 @@ final class ShellTests: XCTestCase {
4545

4646
// Additional assertion to check output
4747
let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
48-
if let outputString = String(
49-
bytes: outputData,
50-
encoding: .utf8
51-
)?.trimmingCharacters(in: .whitespacesAndNewlines) {
52-
XCTAssertTrue(outputString.contains("Testing"))
53-
} else {
54-
XCTFail("Failed to decode output data")
55-
}
48+
let outputString = try XCTUnwrap(
49+
String(bytes: outputData, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
50+
)
51+
XCTAssertTrue(outputString.contains("Testing"))
5652
}
5753

58-
func testExecuteCommandWithShellOutput() {
54+
func testExecuteCommandWithShellOutput() throws {
5955
let command = "echo $STATE"
6056
let environmentVariables = ["STATE": "Testing"]
6157
let shell: Shell = .bash
@@ -69,14 +65,10 @@ final class ShellTests: XCTestCase {
6965
))
7066

7167
let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
72-
if let outputString = String(
73-
bytes: outputData,
74-
encoding: .utf8
75-
)?.trimmingCharacters(in: .whitespacesAndNewlines) {
76-
XCTAssertTrue(outputString.contains("Testing"))
77-
} else {
78-
XCTFail("Failed to decode output data")
79-
}
68+
let outputString = try XCTUnwrap(
69+
String(bytes: outputData, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
70+
)
71+
XCTAssertTrue(outputString.contains("Testing"))
8072
}
8173

8274
func testExecuteCommandWithExecutableOverrideAttempt() {

0 commit comments

Comments
 (0)