Skip to content

Commit 52e9360

Browse files
committed
Never use Apple Script to trigger real-time suggestion
1 parent 4420013 commit 52e9360

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

Core/Sources/Service/SuggestionCommandHandler/PseudoCommandHandler.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ private extension PseudoCommandHandler {
139139
func getFileContent() async
140140
-> (content: String, lines: [String], cursorPosition: CursorPosition)?
141141
{
142-
guard let xcode = ActiveApplicationMonitor.activeXcode else { return nil }
142+
guard let xcode = ActiveApplicationMonitor.activeXcode
143+
?? ActiveApplicationMonitor.latestXcode else { return nil }
143144
let application = AXUIElementCreateApplication(xcode.processIdentifier)
144145
guard let focusElement = application.focusedElement,
145146
focusElement.description == "Source Editor"
@@ -169,23 +170,24 @@ private extension PseudoCommandHandler {
169170

170171
@ServiceActor
171172
func getFilespace() async -> Filespace? {
172-
guard let fileURL = await getFileURL() else { return nil }
173-
for (_, workspace) in workspaces {
174-
if let space = workspace.filespaces[fileURL] { return space }
175-
}
176-
return nil
173+
guard
174+
let fileURL = await getFileURL(),
175+
let (_, filespace) = try? await Workspace
176+
.fetchOrCreateWorkspaceIfNeeded(fileURL: fileURL)
177+
else { return nil }
178+
return filespace
177179
}
178180

179181
@ServiceActor
180182
func getEditorContent() async -> EditorContent? {
181183
guard
182184
let filespace = await getFilespace(),
183-
let uti = filespace.uti,
184-
let tabSize = filespace.tabSize,
185-
let indentSize = filespace.indentSize,
186-
let usesTabsForIndentation = filespace.usesTabsForIndentation,
187185
let content = await getFileContent()
188186
else { return nil }
187+
let uti = filespace.uti ?? ""
188+
let tabSize = filespace.tabSize ?? 4
189+
let indentSize = filespace.indentSize ?? 4
190+
let usesTabsForIndentation = filespace.usesTabsForIndentation ?? false
189191
return .init(
190192
content: content.content,
191193
lines: content.lines,

0 commit comments

Comments
 (0)