Skip to content

Commit a14dcbd

Browse files
committed
Merge tag '0.30.1' into develop
2 parents eda2e8a + 077560c commit a14dcbd

14 files changed

Lines changed: 163 additions & 36 deletions

File tree

Core/Sources/SuggestionWidget/FeatureReducers/WidgetFeature.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ public struct WidgetFeature: ReducerProtocol {
350350
let documentURL = state.focusingDocumentURL
351351

352352
let notifications = app.axNotifications
353+
354+
#warning("TODO: Handling events outside of TCA because the fire rate is too high.")
353355

354356
return .run { send in
355357
await send(.observeEditorChange)
@@ -522,7 +524,6 @@ public struct WidgetFeature: ReducerProtocol {
522524
}
523525
}
524526

525-
#warning("TODO: control windows in their dedicated reducers.")
526527
case let .updateWindowOpacity(immediately):
527528
let isChatPanelDetached = state.chatPanelState.chatPanelInASeparateWindow
528529
let hasChat = !state.chatPanelState.chatTabGroup.tabInfo.isEmpty

Core/Sources/SuggestionWidget/SuggestionWidgetController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ public extension SuggestionWidgetController {
239239
store.send(.panel(.discardSuggestion))
240240
}
241241

242+
#warning("TODO: Make a progress controller that doesn't use TCA.")
242243
func markAsProcessing(_ isProcessing: Bool) {
243244
store.withState { state in
244245
if isProcessing, !state.circularWidgetState.isProcessing {

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ Since the app needs to manage license keys, it will send network request to `htt
364364

365365
- when you activate the license key
366366
- when you deactivate the license key
367+
- when you validate the license key manually
367368
- when you open the host app or the service app if a license key is available
368369
- every 24 hours if a license key is available
369370

TestPlan.xctestplan

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@
133133
"identifier" : "FocusedCodeFinderTests",
134134
"name" : "FocusedCodeFinderTests"
135135
}
136+
},
137+
{
138+
"target" : {
139+
"containerPath" : "container:Tool",
140+
"identifier" : "XcodeInspectorTests",
141+
"name" : "XcodeInspectorTests"
142+
}
136143
}
137144
],
138145
"version" : 1

Tool/Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ let package = Package(
175175
]
176176
),
177177

178+
.testTarget(name: "XcodeInspectorTests", dependencies: ["XcodeInspector"]),
179+
178180
.target(name: "UserDefaultsObserver"),
179181

180182
.target(

Tool/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/ActiveDocumentChatContextCollector.swift

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,28 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
4545
var functions = [any ChatGPTFunction]()
4646

4747
if !isSensitive {
48+
var functionPrompt = """
49+
ONLY call it when one of the following conditions are satisfied:
50+
- the user ask you about specific line from the latest message, \
51+
which is not included in the focused range.
52+
"""
53+
54+
if let annotations = context.focusedContext?.otherLineAnnotations,
55+
!annotations.isEmpty
56+
{
57+
functionPrompt += """
58+
59+
- the user ask about annotations at line \(
60+
Set(annotations.map(\.line)).map(String.init).joined(separator: ",")
61+
).
62+
"""
63+
}
64+
65+
print(functionPrompt)
66+
4867
functions.append(GetCodeCodeAroundLineFunction(
4968
contextCollector: self,
50-
additionalDescription: "You already have the code in focusing range, don't get it again!"
69+
additionalDescription: functionPrompt
5170
))
5271
}
5372

@@ -91,54 +110,54 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
91110
let relativePath = "Document Relative Path: \(context.relativePath)"
92111
let language = "Language: \(context.language.rawValue)"
93112

94-
let focusingContextExplanation =
113+
let focusedContextExplanation =
95114
"Below is the code inside the active document that the user is looking at right now:"
96115

97-
if let focusingContext = context.focusedContext {
98-
let codeContext = focusingContext.context.isEmpty || isSensitive
116+
if let focusedContext = context.focusedContext {
117+
let codeContext = focusedContext.context.isEmpty || isSensitive
99118
? ""
100119
: """
101-
Focusing Context:
120+
Focused Context:
102121
```
103-
\(focusingContext.context.map(\.signature).joined(separator: "\n"))
122+
\(focusedContext.context.map(\.signature).joined(separator: "\n"))
104123
```
105124
"""
106125

107-
let codeRange = "Focusing Range [line, character]: \(focusingContext.codeRange)"
126+
let codeRange = "Focused Range [line, character]: \(focusedContext.codeRange)"
108127

109128
let code = context.selectionRange.isEmpty && isSensitive
110129
? """
111130
The file is in gitignore, you can't read the file.
112131
Ask the user to select the code in the editor to get help. Also tell them the file is in gitignore.
113132
"""
114133
: """
115-
Focusing Code (from line \(
116-
focusingContext.codeRange.start.line + 1
117-
) to line \(focusingContext.codeRange.end.line + 1)):
134+
Focused Code (from line \(
135+
focusedContext.codeRange.start.line + 1
136+
) to line \(focusedContext.codeRange.end.line + 1)):
118137
```\(context.language.rawValue)
119-
\(focusingContext.code)
138+
\(focusedContext.code)
120139
```
121140
"""
122141

123-
let fileAnnotations = focusingContext.otherLineAnnotations.isEmpty || isSensitive
142+
let fileAnnotations = focusedContext.otherLineAnnotations.isEmpty || isSensitive
124143
? ""
125144
: """
126145
Out-of-scope Annotations:\"""
127-
(They are not inside the focusing code. You can get the code at the line for details)
146+
(The related code are not inside the focused code.)
128147
\(
129-
focusingContext.otherLineAnnotations
148+
focusedContext.otherLineAnnotations
130149
.map(convertAnnotationToText)
131150
.joined(separator: "\n")
132151
)
133152
\"""
134153
"""
135154

136-
let codeAnnotations = focusingContext.lineAnnotations.isEmpty || isSensitive
155+
let codeAnnotations = focusedContext.lineAnnotations.isEmpty || isSensitive
137156
? ""
138157
: """
139-
Annotations Inside Focusing Range:\"""
158+
Annotations Inside Focused Range:\"""
140159
\(
141-
focusingContext.lineAnnotations
160+
focusedContext.lineAnnotations
142161
.map(convertAnnotationToText)
143162
.joined(separator: "\n")
144163
)
@@ -149,7 +168,7 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
149168
start,
150169
relativePath,
151170
language,
152-
focusingContextExplanation,
171+
focusedContextExplanation,
153172
codeContext,
154173
codeRange,
155174
code,

Tool/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/Functions/GetCodeCodeAroundLineFunction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct GetCodeCodeAroundLineFunction: ChatGPTFunction {
3232
}
3333

3434
var description: String {
35-
"Get the code at the given line. You must ONLY call it when the user give you a specific line or the user ask about an out of scope annotation. \n\(additionalDescription)"
35+
"Get the code at the given line. \(additionalDescription)"
3636
}
3737

3838
var argumentSchema: JSONSchemaValue { [

Tool/Sources/WorkspaceSuggestionService/Filespace+SuggestionService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SuggestionModel
33
import Workspace
44

55
public struct FilespaceSuggestionSnapshot: Equatable {
6+
#warning("TODO: Can we remove it?")
67
public var linesHash: Int
78
public var cursorPosition: CursorPosition
89

Tool/Sources/XcodeInspector/SourceEditor.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,24 @@ extension SourceEditor {
121121
private var sourceSelectedTextRange: ClosedRange<Int>?
122122
private var cachedSelections = [CursorRange]()
123123

124+
init(
125+
sourceContent: String? = nil,
126+
cachedLines: [String] = [String](),
127+
sourceSelectedTextRange: ClosedRange<Int>? = nil,
128+
cachedSelections: [CursorRange] = [CursorRange]()
129+
) {
130+
self.sourceContent = sourceContent
131+
self.cachedLines = cachedLines
132+
self.sourceSelectedTextRange = sourceSelectedTextRange
133+
self.cachedSelections = cachedSelections
134+
}
135+
124136
func get(content: String, selectedTextRange: ClosedRange<Int>?) -> (
125137
lines: [String],
126138
selections: [CursorRange]
127139
) {
128140
Self.queue.sync {
129-
let contentMatch = content.hashValue == sourceContent?.hashValue
141+
let contentMatch = content == sourceContent
130142
let selectedRangeMatch = selectedTextRange == sourceSelectedTextRange
131143
let lines: [String] = {
132144
if contentMatch {

Tool/Sources/XcodeInspector/XcodeInspector.swift

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ 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")
3839
public var focusedEditorContent: EditorInformation? {
3940
guard let documentURL = XcodeInspector.shared.realtimeActiveDocumentURL,
4041
let workspaceURL = XcodeInspector.shared.realtimeActiveWorkspaceURL,
@@ -214,6 +215,7 @@ public final class XcodeInspector: ObservableObject {
214215
let sequence = NSWorkspace.shared.notificationCenter
215216
.notifications(named: .accessibilityAPIMalfunctioning)
216217
for await notification in sequence {
218+
try Task.checkCancellation()
217219
guard let self else { return }
218220
await self
219221
.recoverFromAccessibilityMalfunctioning(notification.object as? String)
@@ -296,10 +298,10 @@ public final class XcodeInspector: ObservableObject {
296298
}
297299

298300
activeXcodeObservations.insert(malfunctionCheck)
299-
301+
300302
checkForAccessibilityMalfunction("Reactivate Xcode")
301303
}
302-
304+
303305
xcode.$completionPanel.receive(on: DispatchQueue.main).sink { [weak self] element in
304306
self?.completionPanel = element
305307
}.store(in: &activeXcodeCancellable)
@@ -320,7 +322,7 @@ public final class XcodeInspector: ObservableObject {
320322
self?.focusedWindow = window
321323
}.store(in: &activeXcodeCancellable)
322324
}
323-
325+
324326
private var lastRecoveryFromAccessibilityMalfunctioningTimeStamp = Date()
325327

326328
@MainActor
@@ -339,23 +341,24 @@ public final class XcodeInspector: ObservableObject {
339341
{
340342
NSWorkspace.shared.notificationCenter.post(
341343
name: .accessibilityAPIMalfunctioning,
342-
object: "Element Inconsistency: \(source)"
344+
object: "Element Inconsistency: \(source)"
343345
)
344346
}
345347
}
346348
}
347-
349+
348350
@MainActor
349351
private func recoverFromAccessibilityMalfunctioning(_ source: String?) {
352+
let message = """
353+
Accessibility API malfunction detected: \
354+
\(source ?? "").
355+
Resetting active Xcode.
356+
"""
357+
350358
if UserDefaults.shared.value(for: \.toastForTheReasonWhyXcodeInspectorNeedsToBeRestarted) {
351-
toast.toast(
352-
content: """
353-
Accessibility API malfunction detected: \
354-
\(source ?? "").
355-
Resetting active Xcode.
356-
""",
357-
type: .warning
358-
)
359+
toast.toast(content: message, type: .warning)
360+
} else {
361+
Logger.service.info(message)
359362
}
360363
if let activeXcode {
361364
lastRecoveryFromAccessibilityMalfunctioningTimeStamp = Date()

0 commit comments

Comments
 (0)