Skip to content

Commit 891b161

Browse files
committed
Merge tag '0.20.0' into develop
2 parents a6830bf + 746e6d5 commit 891b161

14 files changed

Lines changed: 71 additions & 44 deletions

File tree

Core/Sources/ChatContextCollectors/WebChatContextCollector/WebChatContextCollector.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ public final class WebChatContextCollector: ChatContextCollector {
2828

2929
extension WebChatContextCollector {
3030
static func detectLinks(from messages: [ChatMessage]) -> [String] {
31-
return messages.lazy.compactMap(\.content).map(detectLinks(from:)).flatMap { $0 }
31+
return messages.lazy
32+
.compactMap {
33+
$0.content ?? $0.functionCall?.arguments
34+
}
35+
.map(detectLinks(from:))
36+
.flatMap { $0 }
3237
}
33-
38+
3439
static func detectLinks(from content: String) -> [String] {
3540
var links = [String]()
3641
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)

Core/Sources/GitHubCopilotService/GitHubCopilotService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public final class GitHubCopilotSuggestionService: GitHubCopilotBaseService,
316316
if UserDefaults.shared.value(for: \.gitHubCopilotIgnoreTrailingNewLines) {
317317
var updated = $0
318318
var text = updated.text[...]
319-
while text.hasSuffix("\n") {
319+
while let last = text.last, last.isNewline || last.isWhitespace {
320320
text = text.dropLast(1)
321321
}
322322
updated.text = String(text)

Core/Sources/HostApp/AccountSettings/CopilotView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ struct CopilotView: View {
231231

232232
Form {
233233
Toggle(
234-
"Ignore Trailing New Lines",
234+
"Ignore Trailing New Lines and Whitespaces",
235235
isOn: $settings.gitHubCopilotIgnoreTrailingNewLines
236236
)
237237
Toggle("Verbose Log", isOn: $settings.gitHubCopilotVerboseLog)

Core/Sources/Service/GUI/GraphicalUserInterfaceController.swift.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ struct GUI: ReducerProtocol {
7474

7575
if let activeTab = state.chatTabGroup.activeChatTab as? ChatGPTChatTab {
7676
return .run { send in
77-
await stopAndHandleCommand(activeTab)
7877
await send(.openChatPanel(forceDetach: false))
78+
await stopAndHandleCommand(activeTab)
7979
}
8080
}
8181

@@ -85,15 +85,15 @@ struct GUI: ReducerProtocol {
8585
}) as? ChatGPTChatTab {
8686
state.chatTabGroup.selectedTabId = chatTab.id
8787
return .run { send in
88-
await stopAndHandleCommand(chatTab)
8988
await send(.openChatPanel(forceDetach: false))
89+
await stopAndHandleCommand(chatTab)
9090
}
9191
}
9292
let chatTab = ChatGPTChatTab()
9393
state.chatTabGroup.tabs.append(chatTab)
9494
return .run { send in
95-
await stopAndHandleCommand(chatTab)
9695
await send(.openChatPanel(forceDetach: false))
96+
await stopAndHandleCommand(chatTab)
9797
}
9898

9999
case .suggestionWidget:

Core/Sources/Service/SuggestionCommandHandler/WindowBaseCommandHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,9 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
237237
}
238238

239239
func chatWithSelection(editor: EditorContent) async throws -> UpdatedContent? {
240-
Task {
240+
Task { @MainActor in
241241
let viewStore = GraphicalUserInterfaceController.shared.viewStore
242+
viewStore.send(.createChatGPTChatTabIfNeeded)
242243
viewStore.send(.openChatPanel(forceDetach: false))
243244
}
244245
return nil

Core/Sources/Service/Workspace.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ final class Filespace {
105105
}
106106

107107
// finished typing the whole suggestion when the suggestion has only one line
108-
if editingLine == suggestionFirstLine, suggestionLines.count <= 1 {
108+
if editingLine.hasPrefix(suggestionFirstLine), suggestionLines.count <= 1 {
109109
reset()
110110
return false
111111
}

Core/Sources/SuggestionWidget/FeatureReducers/WidgetFeature.swift

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ public struct WidgetFeature: ReducerProtocol {
4949
isProcessingCounters: circularWidgetState.isProcessingCounters,
5050
isProcessing: circularWidgetState.isProcessing,
5151
isDisplayingContent: {
52-
if chatPanelState.isPanelDisplayed,
53-
!chatPanelState.chatTapGroup.tabs.isEmpty
54-
{
52+
if chatPanelState.isPanelDisplayed {
5553
return true
5654
}
5755
if panelState.sharedPanelState.isPanelDisplayed,
@@ -69,8 +67,7 @@ public struct WidgetFeature: ReducerProtocol {
6967
isContentEmpty: chatPanelState.chatTapGroup.tabs.isEmpty
7068
&& panelState.sharedPanelState.content == nil,
7169
isChatPanelDetached: chatPanelState.chatPanelInASeparateWindow,
72-
isChatOpen: chatPanelState.isPanelDisplayed
73-
&& !chatPanelState.chatTapGroup.tabs.isEmpty,
70+
isChatOpen: chatPanelState.isPanelDisplayed,
7471
animationProgress: circularWidgetState.animationProgress
7572
)
7673
}
@@ -227,7 +224,7 @@ public struct WidgetFeature: ReducerProtocol {
227224
// clicked
228225
// before the completion panel updates the location of the
229226
// suggestion panel
230-
try await Task.sleep(nanoseconds: 200_000_000)
227+
try await Task.sleep(nanoseconds: 400_000_000)
231228
}
232229
continuation.yield()
233230
}
@@ -253,7 +250,7 @@ public struct WidgetFeature: ReducerProtocol {
253250
else { continue }
254251
guard await windows.fullscreenDetector.isOnActiveSpace else { continue }
255252
let app = AXUIElementCreateApplication(activeXcode.processIdentifier)
256-
if let window = app.focusedWindow, window.isFullScreen {
253+
if let window = app.focusedWindow {
257254
await windows.orderFront()
258255
}
259256
}
@@ -549,10 +546,6 @@ public struct WidgetFeature: ReducerProtocol {
549546
suggestionWidgetControllerDependency.onOpenChatClicked()
550547
return .none
551548

552-
case let .runCustomCommandButtonClicked(command):
553-
suggestionWidgetControllerDependency.onCustomCommandClicked(command)
554-
return .none
555-
556549
default:
557550
return .none
558551
}

Core/Sources/XcodeInspector/XcodeInspector.swift

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import AXNotificationStream
55
import Combine
66
import Foundation
77

8-
#warning("MUSTDO: - store(in:) thread safe crash")
9-
108
public final class XcodeInspector: ObservableObject {
119
public static let shared = XcodeInspector()
1210

@@ -228,22 +226,26 @@ public final class XcodeAppInstanceInspector: AppInstanceInspector {
228226
uiElement: window
229227
)
230228
focusedWindow = window
231-
focusedWindowObservations.forEach { $0.cancel() }
232-
focusedWindowObservations.removeAll()
233-
234-
documentURL = window.documentURL
235-
projectURL = window.projectURL
236-
237-
window.$documentURL
238-
.filter { $0 != .init(fileURLWithPath: "/") }
239-
.sink { [weak self] url in
240-
self?.documentURL = url
241-
}.store(in: &focusedWindowObservations)
242-
window.$projectURL
243-
.filter { $0 != .init(fileURLWithPath: "/") }
244-
.sink { [weak self] url in
245-
self?.projectURL = url
246-
}.store(in: &focusedWindowObservations)
229+
230+
// should find a better solution to do this thread safe
231+
Task { @MainActor in
232+
focusedWindowObservations.forEach { $0.cancel() }
233+
focusedWindowObservations.removeAll()
234+
235+
documentURL = window.documentURL
236+
projectURL = window.projectURL
237+
238+
window.$documentURL
239+
.filter { $0 != .init(fileURLWithPath: "/") }
240+
.sink { [weak self] url in
241+
self?.documentURL = url
242+
}.store(in: &focusedWindowObservations)
243+
window.$projectURL
244+
.filter { $0 != .init(fileURLWithPath: "/") }
245+
.sink { [weak self] url in
246+
self?.projectURL = url
247+
}.store(in: &focusedWindowObservations)
248+
}
247249
} else {
248250
let window = XcodeWindowInspector(uiElement: window)
249251
focusedWindow = window

Core/Tests/ServiceTests/FilespaceSuggestionInvalidationTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
119119
XCTAssertNil(suggestion)
120120
}
121121

122+
func test_finish_typing_the_whole_single_line_suggestion_suggestion_is_incomplete_should_invalidate() async throws {
123+
let filespace = try await prepare(
124+
suggestionText: "hello man",
125+
cursorPosition: .init(line: 1, character: 0)
126+
)
127+
let isValid = await filespace.validateSuggestions(
128+
lines: ["\n", "hello man!!!!!\n", "\n"],
129+
cursorPosition: .init(line: 1, character: 9)
130+
)
131+
XCTAssertFalse(isValid)
132+
let suggestion = await filespace.presentingSuggestion
133+
XCTAssertNil(suggestion)
134+
}
135+
122136
func test_finish_typing_the_whole_multiple_line_suggestion_should_be_valid() async throws {
123137
let filespace = try await prepare(
124138
suggestionText: "hello man\nhow are you?",

Tool/Sources/LangChain/Chains/RetrievalQA.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public final class RetrievalQAChain: Chain {
2727
let embeddedQuestion = try await embedding.embed(query: input)
2828
let documents = try await vectorStore.searchWithDistance(
2929
embeddings: embeddedQuestion,
30-
count: 10
30+
count: 5
3131
)
3232
let refinementChain = RefineDocumentChain(chatModelFactory: chatModelFactory)
3333
let answer = try await refinementChain.run(

0 commit comments

Comments
 (0)