@@ -4,6 +4,7 @@ import AXExtension
44import AXNotificationStream
55import Combine
66import Foundation
7+ import SuggestionModel
78
89public final class XcodeInspector : ObservableObject {
910 public static let shared = XcodeInspector ( )
@@ -23,6 +24,41 @@ public final class XcodeInspector: ObservableObject {
2324 @Published public internal( set) var focusedElement : AXUIElement ?
2425 @Published public internal( set) var completionPanel : AXUIElement ?
2526
27+ public var focusedEditorContent : EditorInformation ? {
28+ let editorContent = XcodeInspector . shared. focusedEditor? . content
29+ let documentURL = XcodeInspector . shared. activeDocumentURL
30+ let projectURL = XcodeInspector . shared. activeProjectURL
31+ let language = languageIdentifierFromFileURL ( documentURL)
32+ let relativePath = documentURL. path
33+ . replacingOccurrences ( of: projectURL. path, with: " " )
34+
35+ if let editorContent, let range = editorContent. selections. first {
36+ let ( selectedContent, selectedLines) = EditorInformation . code (
37+ in: editorContent. lines,
38+ inside: range
39+ )
40+ return . init(
41+ editorContent: editorContent,
42+ selectedContent: selectedContent,
43+ selectedLines: selectedLines,
44+ documentURL: documentURL,
45+ projectURL: projectURL,
46+ relativePath: relativePath,
47+ language: language
48+ )
49+ }
50+
51+ return . init(
52+ editorContent: editorContent,
53+ selectedContent: " " ,
54+ selectedLines: [ ] ,
55+ documentURL: documentURL,
56+ projectURL: projectURL,
57+ relativePath: relativePath,
58+ language: language
59+ )
60+ }
61+
2662 public var realtimeActiveDocumentURL : URL {
2763 latestActiveXcode? . realtimeDocumentURL ?? URL ( fileURLWithPath: " / " )
2864 }
0 commit comments