Skip to content

Commit dd95c9a

Browse files
committed
Merge branch 'feature/remove-environment-dot-swift' into develop
2 parents a377916 + 837c2da commit dd95c9a

34 files changed

Lines changed: 99 additions & 234 deletions

Core/Package.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ let package = Package(
129129
.product(name: "Workspace", package: "Tool"),
130130
.product(name: "UserDefaultsObserver", package: "Tool"),
131131
.product(name: "AppMonitoring", package: "Tool"),
132-
.product(name: "Environment", package: "Tool"),
133132
.product(name: "SuggestionModel", package: "Tool"),
134133
.product(name: "ChatTab", package: "Tool"),
135134
.product(name: "Logger", package: "Tool"),
@@ -152,7 +151,6 @@ let package = Package(
152151
.product(name: "XPCShared", package: "Tool"),
153152
.product(name: "SuggestionProvider", package: "Tool"),
154153
.product(name: "SuggestionModel", package: "Tool"),
155-
.product(name: "Environment", package: "Tool"),
156154
.product(name: "Preferences", package: "Tool"),
157155
]
158156
),
@@ -206,7 +204,6 @@ let package = Package(
206204
dependencies: [
207205
.product(name: "FocusedCodeFinder", package: "Tool"),
208206
.product(name: "SuggestionModel", package: "Tool"),
209-
.product(name: "Environment", package: "Tool"),
210207
.product(name: "OpenAIService", package: "Tool"),
211208
.product(name: "AppMonitoring", package: "Tool"),
212209
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
@@ -234,7 +231,6 @@ let package = Package(
234231

235232
.product(name: "ChatContextCollector", package: "Tool"),
236233
.product(name: "AppMonitoring", package: "Tool"),
237-
.product(name: "Environment", package: "Tool"),
238234
.product(name: "Parsing", package: "swift-parsing"),
239235
.product(name: "OpenAIService", package: "Tool"),
240236
.product(name: "Preferences", package: "Tool"),
@@ -246,7 +242,6 @@ let package = Package(
246242
.target(
247243
name: "ChatPlugin",
248244
dependencies: [
249-
.product(name: "Environment", package: "Tool"),
250245
.product(name: "OpenAIService", package: "Tool"),
251246
.product(name: "Terminal", package: "Tool"),
252247
]
@@ -277,7 +272,6 @@ let package = Package(
277272
.product(name: "UserDefaultsObserver", package: "Tool"),
278273
.product(name: "SharedUIComponents", package: "Tool"),
279274
.product(name: "AppMonitoring", package: "Tool"),
280-
.product(name: "Environment", package: "Tool"),
281275
.product(name: "ChatTab", package: "Tool"),
282276
.product(name: "Logger", package: "Tool"),
283277
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),

Core/Sources/ChatPlugin/AITerminalChatPlugin.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Environment
21
import Foundation
32
import OpenAIService
43
import Terminal

Core/Sources/ChatPlugin/TerminalChatPlugin.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Environment
21
import Foundation
32
import OpenAIService
43
import Terminal
4+
import XcodeInspector
55

66
public actor TerminalChatPlugin: ChatPlugin {
77
public static var command: String { "run" }
@@ -34,13 +34,16 @@ public actor TerminalChatPlugin: ChatPlugin {
3434
}
3535

3636
do {
37-
let fileURL = try await Environment.fetchCurrentFileURL()
38-
let projectURL = try await {
39-
if let url = try await Environment.fetchCurrentProjectRootURLFromXcode() {
40-
return url
41-
}
42-
return try await Environment.guessProjectRootURLForFile(fileURL)
43-
}()
37+
let fileURL = XcodeInspector.shared.realtimeActiveDocumentURL
38+
let projectURL = XcodeInspector.shared.realtimeActiveProjectURL
39+
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+
}
4447

4548
await chatGPTService.memory.mutateHistory { history in
4649
history.append(
@@ -59,11 +62,8 @@ public actor TerminalChatPlugin: ChatPlugin {
5962
let output = terminal.streamCommand(
6063
shell,
6164
arguments: ["-i", "-l", "-c", content],
62-
currentDirectoryPath: projectURL.path,
63-
environment: [
64-
"PROJECT_ROOT": projectURL.path,
65-
"FILE_PATH": fileURL.path,
66-
]
65+
currentDirectoryURL: projectURL,
66+
environment: environment
6767
)
6868

6969
for try await content in output {

Core/Sources/ChatPlugins/MathChatPlugin/MathChatPlugin.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import ChatPlugin
2-
import Environment
32
import Foundation
43
import OpenAIService
54

Core/Sources/ChatPlugins/SearchChatPlugin/SearchChatPlugin.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import ChatPlugin
2-
import Environment
32
import Foundation
43
import OpenAIService
54

Core/Sources/ChatPlugins/ShortcutChatPlugin/ShortcutChatPlugin.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import ChatPlugin
2-
import Environment
32
import Foundation
43
import OpenAIService
54
import Parsing
@@ -77,7 +76,7 @@ public actor ShortcutChatPlugin: ChatPlugin {
7776
_ = try await terminal.runCommand(
7877
shell,
7978
arguments: ["-i", "-l", "-c", command],
80-
currentDirectoryPath: "/",
79+
currentDirectoryURL: nil,
8180
environment: [:]
8281
)
8382

Core/Sources/ChatPlugins/ShortcutChatPlugin/ShortcutInputChatPlugin.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import ChatPlugin
2-
import Environment
32
import Foundation
43
import OpenAIService
54
import Parsing
@@ -77,7 +76,7 @@ public actor ShortcutInputChatPlugin: ChatPlugin {
7776
_ = try await terminal.runCommand(
7877
shell,
7978
arguments: ["-i", "-l", "-c", command],
80-
currentDirectoryPath: "/",
79+
currentDirectoryURL: nil,
8180
environment: [:]
8281
)
8382

Core/Sources/Service/GUI/GraphicalUserInterfaceController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import ChatGPTChatTab
55
import ChatTab
66
import ComposableArchitecture
77
import Dependencies
8-
import Environment
98
import Preferences
109
import SuggestionModel
1110
import SuggestionWidget

Core/Sources/Service/RealtimeSuggestionController.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import AppKit
33
import AsyncAlgorithms
44
import AXExtension
55
import AXNotificationStream
6-
import Environment
76
import Foundation
87
import Logger
98
import Preferences
@@ -90,7 +89,7 @@ public actor RealtimeSuggestionController {
9089

9190
Task { // Notify suggestion service for open file.
9291
try await Task.sleep(nanoseconds: 500_000_000)
93-
let fileURL = try await Environment.fetchCurrentFileURL()
92+
guard let fileURL = XcodeInspector.shared.realtimeActiveDocumentURL else { return }
9493
_ = try await Service.shared.workspacePool
9594
.fetchOrCreateWorkspaceAndFilespace(fileURL: fileURL)
9695
}
@@ -108,7 +107,7 @@ public actor RealtimeSuggestionController {
108107
)
109108

110109
editorObservationTask = Task { [weak self] in
111-
let fileURL = try await Environment.fetchCurrentFileURL()
110+
guard let fileURL = XcodeInspector.shared.realtimeActiveDocumentURL else { return }
112111
if let sourceEditor = await self?.sourceEditor {
113112
await PseudoCommandHandler().invalidateRealtimeSuggestionsIfNeeded(
114113
fileURL: fileURL,
@@ -141,7 +140,7 @@ public actor RealtimeSuggestionController {
141140

142141
Task { @WorkspaceActor in // Get cache ready for real-time suggestions.
143142
guard UserDefaults.shared.value(for: \.preCacheOnFileOpen) else { return }
144-
let fileURL = try await Environment.fetchCurrentFileURL()
143+
guard let fileURL = XcodeInspector.shared.realtimeActiveDocumentURL else { return }
145144
let (_, filespace) = try await Service.shared.workspacePool
146145
.fetchOrCreateWorkspaceAndFilespace(fileURL: fileURL)
147146

@@ -171,7 +170,7 @@ public actor RealtimeSuggestionController {
171170
else { return }
172171

173172
if UserDefaults.shared.value(for: \.disableSuggestionFeatureGlobally),
174-
let fileURL = try? await Environment.fetchCurrentFileURL(),
173+
let fileURL = XcodeInspector.shared.activeDocumentURL,
175174
let (workspace, _) = try? await Service.shared.workspacePool
176175
.fetchOrCreateWorkspaceAndFilespace(fileURL: fileURL)
177176
{
@@ -210,7 +209,7 @@ public actor RealtimeSuggestionController {
210209
}
211210

212211
func notifyEditingFileChange(editor: AXUIElement) async {
213-
guard let fileURL = try? await Environment.fetchCurrentFileURL(),
212+
guard let fileURL = XcodeInspector.shared.activeDocumentURL,
214213
let (workspace, _) = try? await Service.shared.workspacePool
215214
.fetchOrCreateWorkspaceAndFilespace(fileURL: fileURL)
216215
else { return }

Core/Sources/Service/SuggestionCommandHandler/PseudoCommandHandler.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ActiveApplicationMonitor
22
import AppKit
3-
import Environment
43
import Preferences
54
import SuggestionInjector
65
import SuggestionModel
@@ -324,14 +323,14 @@ extension PseudoCommandHandler {
324323
return (content, split, [range], range.start)
325324
}
326325

327-
func getFileURL() async -> URL? {
328-
try? await Environment.fetchCurrentFileURL()
326+
func getFileURL() -> URL? {
327+
XcodeInspector.shared.realtimeActiveDocumentURL
329328
}
330329

331330
@WorkspaceActor
332331
func getFilespace() async -> Filespace? {
333332
guard
334-
let fileURL = await getFileURL(),
333+
let fileURL = getFileURL(),
335334
let (_, filespace) = try? await Service.shared.workspacePool
336335
.fetchOrCreateWorkspaceAndFilespace(fileURL: fileURL)
337336
else { return nil }

0 commit comments

Comments
 (0)