Skip to content

Commit 837c2da

Browse files
committed
Change currentDirectoryPath to currentDirectoryURL
1 parent fbf5644 commit 837c2da

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

Core/Sources/ChatPlugin/TerminalChatPlugin.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ public actor TerminalChatPlugin: ChatPlugin {
3434
}
3535

3636
do {
37+
let fileURL = XcodeInspector.shared.realtimeActiveDocumentURL
38+
let projectURL = XcodeInspector.shared.realtimeActiveProjectURL
3739

38-
guard let fileURL = XcodeInspector.shared.realtimeActiveDocumentURL,
39-
let projectURL = XcodeInspector.shared.realtimeActiveProjectURL
40-
else { return }
40+
var environment = [String: String]()
41+
if let fileURL {
42+
environment["FILE_PATH"] = fileURL.path
43+
}
44+
if let projectURL {
45+
environment["PROJECT_ROOT"] = projectURL.path
46+
}
4147

4248
await chatGPTService.memory.mutateHistory { history in
4349
history.append(
@@ -56,11 +62,8 @@ public actor TerminalChatPlugin: ChatPlugin {
5662
let output = terminal.streamCommand(
5763
shell,
5864
arguments: ["-i", "-l", "-c", content],
59-
currentDirectoryPath: projectURL.path,
60-
environment: [
61-
"PROJECT_ROOT": projectURL.path,
62-
"FILE_PATH": fileURL.path,
63-
]
65+
currentDirectoryURL: projectURL,
66+
environment: environment
6467
)
6568

6669
for try await content in output {

Core/Sources/ChatPlugins/ShortcutChatPlugin/ShortcutChatPlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public actor ShortcutChatPlugin: ChatPlugin {
7676
_ = try await terminal.runCommand(
7777
shell,
7878
arguments: ["-i", "-l", "-c", command],
79-
currentDirectoryPath: "/",
79+
currentDirectoryURL: nil,
8080
environment: [:]
8181
)
8282

Core/Sources/ChatPlugins/ShortcutChatPlugin/ShortcutInputChatPlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public actor ShortcutInputChatPlugin: ChatPlugin {
7676
_ = try await terminal.runCommand(
7777
shell,
7878
arguments: ["-i", "-l", "-c", command],
79-
currentDirectoryPath: "/",
79+
currentDirectoryURL: nil,
8080
environment: [:]
8181
)
8282

Tool/Sources/GitHubCopilotService/GitHubCopilotInstallationManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public struct GitHubCopilotInstallationManager {
104104
_ = try await terminal.runCommand(
105105
"/usr/bin/unzip",
106106
arguments: [targetURL.path],
107-
currentDirectoryPath: urls.executableURL.path,
107+
currentDirectoryURL: urls.executableURL,
108108
environment: [:]
109109
)
110110

Tool/Sources/GitIgnoreCheck/GitIgnoreCheck.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public struct DefaultGitIgnoredChecker: GitIgnoredChecker {
5555
let result = try await terminal.runCommand(
5656
"/bin/bash",
5757
arguments: ["-c", "git check-ignore \"\(fileURL.path)\""],
58-
currentDirectoryPath: gitFolderURL.path,
58+
currentDirectoryURL: gitFolderURL,
5959
environment: [:]
6060
)
6161
if result.isEmpty { return false }
@@ -77,7 +77,7 @@ public struct DefaultGitIgnoredChecker: GitIgnoredChecker {
7777
let result = try await terminal.runCommand(
7878
"/bin/bash",
7979
arguments: ["-c", "git check-ignore \(filePaths)"],
80-
currentDirectoryPath: gitFolderURL.path,
80+
currentDirectoryURL: gitFolderURL,
8181
environment: [:]
8282
)
8383
return result

Tool/Sources/Terminal/Terminal.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ public protocol TerminalType {
55
func streamCommand(
66
_ command: String,
77
arguments: [String],
8-
currentDirectoryPath: String,
8+
currentDirectoryURL: URL?,
99
environment: [String: String]
1010
) -> AsyncThrowingStream<String, Error>
1111

1212
func runCommand(
1313
_ command: String,
1414
arguments: [String],
15-
currentDirectoryPath: String,
15+
currentDirectoryURL: URL?,
1616
environment: [String: String]
1717
) async throws -> String
1818

@@ -44,15 +44,15 @@ public final class Terminal: TerminalType, @unchecked Sendable {
4444
public func streamCommand(
4545
_ command: String = "/bin/bash",
4646
arguments: [String],
47-
currentDirectoryPath: String = "/",
47+
currentDirectoryURL: URL? = nil,
4848
environment: [String: String]
4949
) -> AsyncThrowingStream<String, Error> {
5050
self.process?.terminate()
5151
let process = Process()
5252
self.process = process
5353

5454
process.launchPath = command
55-
process.currentDirectoryPath = currentDirectoryPath
55+
process.currentDirectoryURL = currentDirectoryURL
5656
process.arguments = arguments
5757
process.environment = getEnvironmentVariables()
5858
.merging(environment, uniquingKeysWith: { $1 })
@@ -128,12 +128,12 @@ public final class Terminal: TerminalType, @unchecked Sendable {
128128
public func runCommand(
129129
_ command: String = "/bin/bash",
130130
arguments: [String],
131-
currentDirectoryPath: String = "/",
131+
currentDirectoryURL: URL? = nil,
132132
environment: [String: String]
133133
) async throws -> String {
134134
let process = Process()
135135
process.launchPath = command
136-
process.currentDirectoryPath = currentDirectoryPath
136+
process.currentDirectoryURL = currentDirectoryURL
137137
process.arguments = arguments
138138
process.environment = getEnvironmentVariables()
139139
.merging(environment, uniquingKeysWith: { $1 })

0 commit comments

Comments
 (0)