Skip to content

Commit 35d3895

Browse files
committed
Add completionPanel to XcodeAppInstanceInspector
1 parent c30d18a commit 35d3895

4 files changed

Lines changed: 44 additions & 3 deletions

File tree

Core/Sources/AXExtension/AXUIElement.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public extension AXUIElement {
6363
var isEnabled: Bool {
6464
(try? copyValue(key: kAXEnabledAttribute)) ?? false
6565
}
66+
67+
var isHidden: Bool {
68+
(try? copyValue(key: kAXHiddenAttribute)) ?? false
69+
}
6670
}
6771

6872
// MARK: - Rect

Core/Sources/AXNotificationStream/AXNotificationStream.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public final class AXNotificationStream: AsyncSequence {
66
public typealias Stream = AsyncStream<Element>
77
public typealias Continuation = Stream.Continuation
88
public typealias AsyncIterator = Stream.AsyncIterator
9-
public typealias Element = (name: String, info: CFDictionary)
9+
public typealias Element = (name: String, element: AXUIElement, info: CFDictionary)
1010

1111
private var continuation: Continuation
1212
private let stream: Stream
@@ -48,7 +48,7 @@ public final class AXNotificationStream: AsyncSequence {
4848
) {
4949
guard let pointer = pointer?.assumingMemoryBound(to: Continuation.self)
5050
else { return }
51-
pointer.pointee.yield((notificationName as String, userInfo))
51+
pointer.pointee.yield((notificationName as String, element, userInfo))
5252
}
5353

5454
_ = AXObserverCreateWithInfoCallback(

Core/Sources/XcodeInspector/SourceEditor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class SourceEditor {
1616
public var cursorPosition: CursorPosition
1717
/// Line annotations of the source editor.
1818
public var lineAnnotations: [String]
19-
19+
2020
public var selectedContent: String {
2121
if let range = selections.first {
2222
let startIndex = min(

Core/Sources/XcodeInspector/XcodeInspector.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
167167
@Published public var documentURL: URL = .init(fileURLWithPath: "/")
168168
@Published public var projectURL: URL = .init(fileURLWithPath: "/")
169169
@Published public var workspaces = [WorkspaceIdentifier: WorkspaceInfo]()
170+
@Published public private(set) var completionPanel: AXUIElement?
171+
170172
var _version: String?
171173
public var version: String? {
172174
if let _version { return _version }
@@ -232,6 +234,41 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
232234
}
233235

234236
longRunningTasks.insert(updateTabsTask)
237+
238+
completionPanel = appElement.firstChild { element in
239+
element.identifier == "_XC_COMPLETION_TABLE_"
240+
}?.parent
241+
242+
let completionPanelTask = Task {
243+
let stream = AXNotificationStream(
244+
app: runningApplication,
245+
element: appElement,
246+
notificationNames: kAXCreatedNotification, kAXUIElementDestroyedNotification
247+
)
248+
249+
for await event in stream {
250+
let isCompletionPanel = {
251+
event.element.firstChild { element in
252+
element.identifier == "_XC_COMPLETION_TABLE_"
253+
} != nil
254+
}
255+
switch event.name {
256+
case kAXCreatedNotification:
257+
if isCompletionPanel() {
258+
completionPanel = event.element
259+
}
260+
case kAXUIElementDestroyedNotification:
261+
if isCompletionPanel() {
262+
completionPanel = nil
263+
}
264+
default: break
265+
}
266+
267+
try Task.checkCancellation()
268+
}
269+
}
270+
271+
longRunningTasks.insert(completionPanelTask)
235272
}
236273

237274
func observeFocusedWindow() {

0 commit comments

Comments
 (0)