Skip to content

Commit 098e7e3

Browse files
committed
Make focusedEditorContent a function marked as expensive
1 parent e280dbd commit 098e7e3

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

Core/Sources/PromptToCodeService/OpenAIPromptToCodeService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
3131
return userPreferredLanguage.isEmpty ? "" : " in \(userPreferredLanguage)"
3232
}()
3333

34-
let editor: EditorInformation = XcodeInspector.shared.focusedEditorContent ?? .init(
34+
let editor: EditorInformation = XcodeInspector.shared.getFocusedEditorContent() ?? .init(
3535
editorContent: .init(
3636
content: source.content,
3737
lines: source.lines,

Pro

Submodule Pro updated from 4059899 to 8c9ccfa

Tool/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/GetEditorInfo.swift

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

55
func getEditorInformation() -> EditorInformation? {
6-
return XcodeInspector.shared.focusedEditorContent
6+
return XcodeInspector.shared.getFocusedEditorContent()
77
}
88

Tool/Sources/XcodeInspector/SourceEditor.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public class SourceEditor {
3030

3131
/// Get the content of the source editor.
3232
///
33-
/// - note: This method is expensive.
33+
/// - note: This method is expensive. It needs to convert index based ranges to line based
34+
/// ranges.
3435
public func getContent() -> Content {
3536
let content = element.value
3637
let selectionRange = element.selectedTextRange

Tool/Sources/XcodeInspector/XcodeInspector.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ public final class XcodeInspector: ObservableObject {
3535
@Published public fileprivate(set) var focusedElement: AXUIElement?
3636
@Published public fileprivate(set) var completionPanel: AXUIElement?
3737

38-
#warning("TODO: make it a function and mark it as expensive")
39-
public var focusedEditorContent: EditorInformation? {
38+
/// Get the content of the source editor.
39+
///
40+
/// - note: This method is expensive. It needs to convert index based ranges to line based
41+
/// ranges.
42+
public func getFocusedEditorContent() -> EditorInformation? {
4043
guard let documentURL = XcodeInspector.shared.realtimeActiveDocumentURL,
4144
let workspaceURL = XcodeInspector.shared.realtimeActiveWorkspaceURL,
4245
let projectURL = XcodeInspector.shared.activeProjectRootURL

0 commit comments

Comments
 (0)