Skip to content

Commit 774216b

Browse files
committed
Support jump to specific line of reference file
1 parent 1925397 commit 774216b

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

Core/Sources/ChatGPTChatTab/Chat.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ public struct DisplayedChatMessage: Equatable {
1717
public var title: String
1818
public var subtitle: String
1919
public var uri: String
20+
public var startLine: Int?
2021

21-
public init(title: String, subtitle: String, uri: String) {
22+
public init(title: String, subtitle: String, uri: String, startLine: Int?) {
2223
self.title = title
2324
self.subtitle = subtitle
2425
self.uri = uri
26+
self.startLine = startLine
2527
}
2628
}
2729

@@ -98,7 +100,7 @@ struct Chat: ReducerProtocol {
98100
case observeExtraSystemPromptChange(UUID)
99101
case observeDefaultScopesChange(UUID)
100102
}
101-
103+
102104
@Dependency(\.openURL) var openURL
103105

104106
var body: some ReducerProtocol<State, Action> {
@@ -166,7 +168,8 @@ struct Chat: ReducerProtocol {
166168
do {
167169
_ = try await terminal.runCommand(
168170
"/bin/bash",
169-
arguments: ["-c", "xed -l 0 \"\(reference.uri)\""],
171+
arguments: ["-c",
172+
"xed -l \(reference.startLine ?? 0) \"\(reference.uri)\""],
170173
environment: [:]
171174
)
172175
} catch {
@@ -291,7 +294,12 @@ struct Chat: ReducerProtocol {
291294
}(),
292295
text: message.summary ?? message.content ?? "",
293296
references: message.references.map {
294-
.init(title: $0.title, subtitle: $0.subTitle, uri: $0.uri)
297+
.init(
298+
title: $0.title,
299+
subtitle: $0.subTitle,
300+
uri: $0.uri,
301+
startLine: $0.startLine
302+
)
295303
}
296304
)
297305
}

Core/Sources/ChatGPTChatTab/ChatPanel.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ struct ChatPanel_Preview: PreviewProvider {
439439
.init(
440440
title: "Hello Hello Hello Hello",
441441
subtitle: "Hi Hi Hi Hi",
442-
uri: "https://google.com"
442+
uri: "https://google.com",
443+
startLine: nil
443444
),
444445
]
445446
),

Core/Sources/ChatGPTChatTab/Views/BotMessage.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ struct ReferenceList: View {
142142
.init(
143143
title: "ReferenceList",
144144
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
145-
uri: "https://google.com"
145+
uri: "https://google.com",
146+
startLine: nil
146147
),
147148
.init(
148149
title: "BotMessage.swift:100-102",
149150
subtitle: "/Core/Sources/ChatGPTChatTab/Views",
150-
uri: "https://google.com"
151+
uri: "https://google.com",
152+
startLine: nil
151153
),
152154
],
153155
chat: .init(initialState: .init(), reducer: Chat(service: .init()))
@@ -161,32 +163,38 @@ struct ReferenceList: View {
161163
.init(
162164
title: "ReferenceList",
163165
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
164-
uri: "https://google.com"
166+
uri: "https://google.com",
167+
startLine: nil
165168
),
166169
.init(
167170
title: "BotMessage.swift:100-102",
168171
subtitle: "/Core/Sources/ChatGPTChatTab/Views",
169-
uri: "https://google.com"
172+
uri: "https://google.com",
173+
startLine: nil
170174
),
171175
.init(
172176
title: "ReferenceList",
173177
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
174-
uri: "https://google.com"
178+
uri: "https://google.com",
179+
startLine: nil
175180
),
176181
.init(
177182
title: "ReferenceList",
178183
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
179-
uri: "https://google.com"
184+
uri: "https://google.com",
185+
startLine: nil
180186
),
181187
.init(
182188
title: "ReferenceList",
183189
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
184-
uri: "https://google.com"
190+
uri: "https://google.com",
191+
startLine: nil
185192
),
186193
.init(
187194
title: "ReferenceList",
188195
subtitle: "/Core/Sources/ChatGPTChatTab/Views/BotMessage.swift:100",
189-
uri: "https://google.com"
196+
uri: "https://google.com",
197+
startLine: nil
190198
),
191199
], chat: .init(initialState: .init(), reducer: Chat(service: .init())))
192200
}

0 commit comments

Comments
 (0)