-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathConversationCodeReviewFeature.swift
More file actions
92 lines (73 loc) · 2.69 KB
/
ConversationCodeReviewFeature.swift
File metadata and controls
92 lines (73 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import ComposableArchitecture
import ChatService
import Foundation
import ConversationServiceProvider
import GitHelper
import LanguageServerProtocol
import Terminal
import Combine
@MainActor
public class CodeReviewStateService: ObservableObject {
public static let shared = CodeReviewStateService()
public let fileClickedEvent = PassthroughSubject<Void, Never>()
private init() { }
func notifyFileClicked() {
fileClickedEvent.send()
}
}
@Reducer
public struct ConversationCodeReviewFeature {
@ObservableState
public struct State: Equatable {
public init() { }
}
public enum Action: Equatable {
case request(GitDiffGroup)
case accept(id: String, selectedFiles: [DocumentUri])
case cancel(id: String)
case onFileClicked(URL, Int)
}
public let service: ChatService
public var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .request(let group):
return .run { _ in
try await service.requestCodeReview(group)
}
case let .accept(id, selectedFileUris):
return .run { _ in
await service.acceptCodeReview(id, selectedFileUris: selectedFileUris)
}
case .cancel(let id):
return .run { _ in
await service.cancelCodeReview(id)
}
// lineNumber: 0-based
case .onFileClicked(let fileURL, let lineNumber):
return .run { _ in
if FileManager.default.fileExists(atPath: fileURL.path) {
let terminal = Terminal()
do {
_ = try await terminal.runCommand(
"/bin/bash",
arguments: [
"-c",
"xed -l \(lineNumber+1) \"${TARGET_REVIEW_FILE}\""
],
environment: [
"TARGET_REVIEW_FILE": fileURL.path
]
)
} catch {
print(error)
}
}
Task { @MainActor in
CodeReviewStateService.shared.notifyFileClicked()
}
}
}
}
}
}