File tree Expand file tree Collapse file tree 3 files changed +40
-13
lines changed
Service/SuggestionCommandHandler
SuggestionWidget/FeatureReducers
Tool/Sources/CommandHandler Expand file tree Collapse file tree 3 files changed +40
-13
lines changed Original file line number Diff line number Diff line change @@ -498,17 +498,28 @@ struct PseudoCommandHandler: CommandHandler {
498498 }
499499 }
500500
501- func presentFile( at fileURL: URL , line: Int = 0 ) async {
501+ func presentFile( at fileURL: URL , line: Int ? ) async {
502502 let terminal = Terminal ( )
503503 do {
504- _ = try await terminal. runCommand (
505- " /bin/bash " ,
506- arguments: [
507- " -c " ,
508- " xed -l \( line) ${TARGET_FILE} " ,
509- ] ,
510- environment: [ " TARGET_FILE " : fileURL. path] ,
511- )
504+ if let line {
505+ _ = try await terminal. runCommand (
506+ " /bin/bash " ,
507+ arguments: [
508+ " -c " ,
509+ " xed -l \( line) ${TARGET_FILE} " ,
510+ ] ,
511+ environment: [ " TARGET_FILE " : fileURL. path] ,
512+ )
513+ } else {
514+ _ = try await terminal. runCommand (
515+ " /bin/bash " ,
516+ arguments: [
517+ " -c " ,
518+ " xed ${TARGET_FILE} " ,
519+ ] ,
520+ environment: [ " TARGET_FILE " : fileURL. path] ,
521+ )
522+ }
512523 } catch {
513524 print ( error)
514525 }
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import Preferences
88import PromptToCodeCustomization
99import PromptToCodeService
1010import SuggestionBasic
11+ import XcodeInspector
1112
1213@Reducer
1314public struct PromptToCodePanel {
@@ -247,7 +248,13 @@ public struct PromptToCodePanel {
247248
248249 case . acceptButtonTapped:
249250 state. hasEnded = true
251+ let url = state. promptToCodeState. source. documentURL
252+ let startLine = state. snippetPanels. first? . snippet. attachedRange. start. line ?? 0
250253 return . run { _ in
254+ let activeDocumentURL = await XcodeInspector . shared. safe. activeDocumentURL
255+ if activeDocumentURL != url {
256+ await commandHandler. presentFile ( at: url, line: startLine)
257+ }
251258 await commandHandler. acceptModification ( )
252259 activatePreviousActiveXcode ( )
253260 }
@@ -257,7 +264,7 @@ public struct PromptToCodePanel {
257264 await commandHandler. acceptModification ( )
258265 activateThisApp ( )
259266 }
260-
267+
261268 case let . statusUpdated( status) :
262269 state. promptToCodeState. status = status
263270 return . none
Original file line number Diff line number Diff line change @@ -39,7 +39,16 @@ public protocol CommandHandler {
3939
4040 // MARK: Others
4141
42- func presentFile( at fileURL: URL , line: Int ) async
42+ func presentFile( at fileURL: URL , line: Int ? ) async
43+
44+ func presentFile( at fileURL: URL ) async
45+ }
46+
47+ public extension CommandHandler {
48+ /// Default implementation for `presentFile(at:line:)`.
49+ func presentFile( at fileURL: URL ) async {
50+ await presentFile ( at: fileURL, line: nil )
51+ }
4352}
4453
4554public struct CommandHandlerDependencyKey : DependencyKey {
@@ -117,7 +126,7 @@ public final class UniversalCommandHandler: CommandHandler {
117126 commandHandler. toast ( string, as: type)
118127 }
119128
120- public func presentFile( at fileURL: URL , line: Int ) async {
129+ public func presentFile( at fileURL: URL , line: Int ? ) async {
121130 await commandHandler. presentFile ( at: fileURL, line: line)
122131 }
123132}
@@ -175,7 +184,7 @@ struct NOOPCommandHandler: CommandHandler {
175184 print ( " toast " )
176185 }
177186
178- func presentFile( at fileURL: URL , line: Int ) async {
187+ func presentFile( at fileURL: URL , line: Int ? ) async {
179188 print ( " present file " )
180189 }
181190}
You can’t perform that action at this time.
0 commit comments