Skip to content

Commit eac534b

Browse files
committed
Fix that fetchFocusedElementURI returns incorrect result in some situations
1 parent 473f88f commit eac534b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Core/Sources/Environment/Environment.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,20 @@ public enum Environment {
116116

117117
let application = AXUIElementCreateApplication(xcode.processIdentifier)
118118
let focusedElement = application.focusedElement
119-
if focusedElement?.description != "Source Editor" {
119+
var windowElement: URL {
120120
let window = application.focusedWindow
121121
let id = window?.identifier.hashValue
122122
return URL(fileURLWithPath: "/xcode-focused-element/\(id ?? 0)")
123123
}
124+
if focusedElement?.description != "Source Editor" {
125+
return windowElement
126+
}
124127

125-
return try await fetchCurrentFileURL()
128+
do {
129+
return try await fetchCurrentFileURL()
130+
} catch {
131+
return windowElement
132+
}
126133
}
127134

128135
public static var createSuggestionService: (

0 commit comments

Comments
 (0)