Skip to content

Commit 9090237

Browse files
committed
Add focusedEditorContent to XcodeInspector
1 parent 22019c5 commit 9090237

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

Core/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/GetEditorInfo.swift

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,6 @@ import SuggestionModel
33
import XcodeInspector
44

55
func getEditorInformation() -> EditorInformation? {
6-
guard !XcodeInspector.shared.xcodes.isEmpty else { return nil }
7-
8-
let editorContent = XcodeInspector.shared.focusedEditor?.content
9-
let documentURL = XcodeInspector.shared.activeDocumentURL
10-
let projectURL = XcodeInspector.shared.activeProjectURL
11-
let language = languageIdentifierFromFileURL(documentURL)
12-
let relativePath = documentURL.path
13-
.replacingOccurrences(of: projectURL.path, with: "")
14-
15-
if let editorContent, let range = editorContent.selections.first {
16-
let (selectedContent, selectedLines) = EditorInformation.code(
17-
in: editorContent.lines,
18-
inside: range
19-
)
20-
return .init(
21-
editorContent: editorContent,
22-
selectedContent: selectedContent,
23-
selectedLines: selectedLines,
24-
documentURL: documentURL,
25-
projectURL: projectURL,
26-
relativePath: relativePath,
27-
language: language
28-
)
29-
}
30-
31-
return .init(
32-
editorContent: editorContent,
33-
selectedContent: "",
34-
selectedLines: [],
35-
documentURL: documentURL,
36-
projectURL: projectURL,
37-
relativePath: relativePath,
38-
language: language
39-
)
6+
return XcodeInspector.shared.focusedEditorContent
407
}
418

Tool/Sources/XcodeInspector/XcodeInspector.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import AXExtension
44
import AXNotificationStream
55
import Combine
66
import Foundation
7+
import SuggestionModel
78

89
public 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

Comments
 (0)