Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
29bce2f
Merge tag '0.31.0' into develop
intitni Mar 8, 2024
d41469b
Merge tag '0.31.1' into develop
intitni Mar 13, 2024
432c72e
Remove the snapshot check when getting suggestions manually
intitni Mar 13, 2024
986afee
Merge branch 'feature/remove-snapshot-check-fetching-suggestion-manua…
intitni Mar 13, 2024
e27b1ab
Prevent sending discard suggestion action when there is no suggestion…
intitni Mar 13, 2024
ec69b12
Rename methods
intitni Mar 13, 2024
f15a747
Remove unneeded calls
intitni Mar 13, 2024
8e690b3
Fix that triggering the menubar dismisses suggestions
intitni Mar 13, 2024
e6ca4d4
Merge branch 'feature/fix-command-dismiss-suggestions' into develop
intitni Mar 13, 2024
48ce998
Add feature flags
intitni Mar 13, 2024
f6b04ed
Change runloop and mode according to flags
intitni Mar 13, 2024
ce40906
Merge branch 'feature/ax-notification-out-of-main-thread' into develop
intitni Mar 13, 2024
014023a
Update
intitni Mar 13, 2024
72fb69a
Update texts
intitni Mar 13, 2024
a7d1e74
Bump version to 0.31.2
intitni Mar 13, 2024
1ba39c7
Remove a feature flag
intitni Mar 14, 2024
c56de95
Update
intitni Mar 14, 2024
9f25f49
Update UI to look better in light mode
intitni Mar 14, 2024
bd5064e
Update suggestion panel corner radius to match Xcode completion panel
intitni Mar 14, 2024
d98a483
Adjust chat panel UI
intitni Mar 14, 2024
0144241
Improve scroll to bottom behavior of chat panel
intitni Mar 14, 2024
03890a8
Update
intitni Mar 14, 2024
db6907f
Bump build number
intitni Mar 14, 2024
38c3ee8
Adjust style
intitni Mar 14, 2024
4d1ae7c
Add todo
intitni Mar 14, 2024
c7d426f
Bump build number
intitni Mar 14, 2024
79e1e9b
Update appcast.xml
intitni Mar 14, 2024
205bbd0
Merge branch 'release/0.31.2'
intitni Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion Core/Sources/ChatGPTChatTab/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,13 @@ struct Chat: ReducerProtocol {
cancellable.cancel()
}
}
for await _ in stream {
let debouncedHistoryChange = TimedDebounceFunction(duration: 0.2) {
await send(.historyChanged)
}

for await _ in stream {
await debouncedHistoryChange()
}
}.cancellable(id: CancelID.observeHistoryChange(id), cancelInFlight: true)

case .observeIsReceivingMessageChange:
Expand Down Expand Up @@ -450,3 +454,33 @@ struct ChatMenu: ReducerProtocol {
}
}

private actor TimedDebounceFunction {
let duration: TimeInterval
let block: () async -> Void

var task: Task<Void, Error>?
var lastFireTime: Date = .init(timeIntervalSince1970: 0)

init(duration: TimeInterval, block: @escaping () async -> Void) {
self.duration = duration
self.block = block
}

func callAsFunction() async {
task?.cancel()
if lastFireTime.timeIntervalSinceNow < -duration {
await fire()
task = nil
} else {
task = Task.detached { [weak self, duration] in
try await Task.sleep(nanoseconds: UInt64(duration * 1_000_000_000))
await self?.fire()
}
}
}

func fire() async {
lastFireTime = Date()
await block()
}
}
19 changes: 16 additions & 3 deletions Core/Sources/ChatGPTChatTab/ChatPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct ChatPanel: View {
Divider()
ChatPanelInputArea(chat: chat)
}
.background(.regularMaterial)
.background(.clear)
.onAppear { chat.send(.appear) }
}
}
Expand Down Expand Up @@ -86,13 +86,23 @@ struct ChatPanelMessages: View {
}
.modify { view in
if #available(macOS 13.0, *) {
view.listRowSeparator(.hidden).listSectionSeparator(.hidden)
view
.listRowSeparator(.hidden)
.listSectionSeparator(.hidden)
} else {
view
}
}
}
.listStyle(.plain)
.listRowBackground(EmptyView())
.modify { view in
if #available(macOS 13.0, *) {
view.scrollContentBackground(.hidden)
} else {
view
}
}
.coordinateSpace(name: scrollSpace)
.preference(
key: ListHeightPreferenceKey.self,
Expand Down Expand Up @@ -218,7 +228,10 @@ struct ChatPanelMessages: View {
if isInitialLoad {
isInitialLoad = false
}
scrollToBottom()
Task {
await Task.yield()
scrollToBottom()
}
}
}
}
Expand Down
58 changes: 56 additions & 2 deletions Core/Sources/ChatGPTChatTab/Styles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension Color {
if appearance.isDarkMode {
return #colorLiteral(red: 0.1580096483, green: 0.1730263829, blue: 0.2026666105, alpha: 1)
}
return .white
return #colorLiteral(red: 0.9896564803, green: 0.9896564803, blue: 0.9896564803, alpha: 1)
}))
}

Expand All @@ -18,7 +18,7 @@ extension Color {
if appearance.isDarkMode {
return #colorLiteral(red: 0.2284317913, green: 0.2145925438, blue: 0.3214019983, alpha: 1)
}
return #colorLiteral(red: 0.896820749, green: 0.8709097223, blue: 0.9766687925, alpha: 1)
return #colorLiteral(red: 0.9458052187, green: 0.9311983998, blue: 0.9906365955, alpha: 1)
}))
}
}
Expand Down Expand Up @@ -92,6 +92,60 @@ extension MarkdownUI.Theme {
}
}

static func instruction(fontSize: Double) -> MarkdownUI.Theme {
.gitHub.text {
ForegroundColor(.primary)
BackgroundColor(Color.clear)
FontSize(fontSize)
}
.code {
FontFamilyVariant(.monospaced)
FontSize(.em(0.85))
BackgroundColor(Color.secondary.opacity(0.2))
}
.codeBlock { configuration in
let wrapCode = UserDefaults.shared.value(for: \.wrapCodeInChatCodeBlock)

if wrapCode {
configuration.label
.codeBlockLabelStyle()
.codeBlockStyle(configuration)
} else {
ScrollView(.horizontal) {
configuration.label
.codeBlockLabelStyle()
}
.workaroundForVerticalScrollingBugInMacOS()
.codeBlockStyle(configuration)
}
}
.table { configuration in
configuration.label
.fixedSize(horizontal: false, vertical: true)
.markdownTableBorderStyle(.init(
color: .init(nsColor: .separatorColor),
strokeStyle: .init(lineWidth: 1)
))
.markdownTableBackgroundStyle(
.alternatingRows(Color.secondary.opacity(0.1), Color.secondary.opacity(0.2))
)
.markdownMargin(top: 0, bottom: 16)
}
.tableCell { configuration in
configuration.label
.markdownTextStyle {
if configuration.row == 0 {
FontWeight(.semibold)
}
BackgroundColor(nil)
}
.fixedSize(horizontal: false, vertical: true)
.padding(.vertical, 6)
.padding(.horizontal, 13)
.relativeLineSpacing(.em(0.25))
}
}

static func functionCall(fontSize: Double) -> MarkdownUI.Theme {
.gitHub.text {
ForegroundColor(.secondary)
Expand Down
2 changes: 1 addition & 1 deletion Core/Sources/ChatGPTChatTab/Views/BotMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct BotMessage: View {
.stroke(Color(nsColor: .separatorColor), lineWidth: 1)
}
.padding(.leading, 8)
.shadow(color: .black.opacity(0.1), radius: 2)
.shadow(color: .black.opacity(0.05), radius: 6)
.contextMenu {
Button("Copy") {
NSPasteboard.general.clearContents()
Expand Down
2 changes: 1 addition & 1 deletion Core/Sources/ChatGPTChatTab/Views/Instructions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct Instruction: View {
func body(content: Content) -> some View {
content
.textSelection(.enabled)
.markdownTheme(.custom(fontSize: chatFontSize))
.markdownTheme(.instruction(fontSize: chatFontSize))
.opacity(0.8)
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
Expand Down
2 changes: 1 addition & 1 deletion Core/Sources/ChatGPTChatTab/Views/UserMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct UserMessage: View {
}
.padding(.leading)
.padding(.trailing, 8)
.shadow(color: .black.opacity(0.1), radius: 2)
.shadow(color: .black.opacity(0.05), radius: 6)
.frame(maxWidth: .infinity, alignment: .trailing)
.contextMenu {
Button("Copy") {
Expand Down
11 changes: 11 additions & 0 deletions Core/Sources/HostApp/DebugView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ final class DebugSettings: ObservableObject {
var restartXcodeInspectorIfAccessibilityAPIIsMalfunctioningNoTimer
@AppStorage(\.toastForTheReasonWhyXcodeInspectorNeedsToBeRestarted)
var toastForTheReasonWhyXcodeInspectorNeedsToBeRestarted
@AppStorage(\.observeToAXNotificationWithDefaultMode)
var observeToAXNotificationWithDefaultMode
init() {}
}

Expand Down Expand Up @@ -116,8 +118,17 @@ struct DebugSettingsView: View {
UserDefaults.shared.set(nil, forKey: "ChatModels")
UserDefaults.shared.set(nil, forKey: "EmbeddingModels")
}

Group {
Toggle(
isOn: $settings.observeToAXNotificationWithDefaultMode
) {
Text("Observe to AXNotification with default mode")
}
}
}
}
.frame(maxWidth: .infinity)
.padding()
}
}
Expand Down
8 changes: 4 additions & 4 deletions Core/Sources/HostApp/FeatureSettings/ChatSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ struct ChatSettingsView: View {
"Preferred Chat Model",
selection: $settings.preferredChatModelIdForSenseScope
) {
Text("None").tag("")
Text("Use the default model").tag("")

if !settings.chatModels
.contains(where: {
Expand Down Expand Up @@ -364,7 +364,7 @@ struct ChatSettingsView: View {
"Preferred Chat Model",
selection: $settings.preferredChatModelIdForProjectScope
) {
Text("None").tag("")
Text("Use the default model").tag("")

if !settings.chatModels
.contains(where: {
Expand All @@ -390,7 +390,7 @@ struct ChatSettingsView: View {

SubSection(
title: Text("Web Scope"),
description: "Allow the bot to search on Bing or read a web page."
description: "Allow the bot to search on Bing or read a web page. The current implementation requires function calling."
) {
Form {
Toggle(isOn: $settings.enableWebScopeByDefaultInChatContext) {
Expand All @@ -401,7 +401,7 @@ struct ChatSettingsView: View {
"Preferred Chat Model",
selection: $settings.preferredChatModelIdForWebScope
) {
Text("None").tag("")
Text("Use the default model").tag("")

if !settings.chatModels
.contains(where: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {

try Task.checkCancellation()

let snapshot = FilespaceSuggestionSnapshot(
linesHash: editor.lines.hashValue,
cursorPosition: editor.cursorPosition
)

// There is no need to regenerate suggestions for the same editor content.
guard filespace.suggestionSourceSnapshot != snapshot else { return }

try await workspace.generateSuggestions(
forFileAt: fileURL,
editor: editor
Expand Down
1 change: 0 additions & 1 deletion Core/Sources/SuggestionWidget/ChatWindowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ struct ChatWindowView: View {
}
.xcodeStyleFrame(cornerRadius: 10)
.ignoresSafeArea(edges: .top)
.background(.regularMaterial)
.onChange(of: viewStore.state.isPanelDisplayed) { isDisplayed in
toggleVisibility(isDisplayed)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ public struct PanelFeature: ReducerProtocol {
return .none

case .switchToAnotherEditorAndUpdateContent:
state.content.error = nil
state.content.suggestion = nil
return .run { send in
guard let fileURL = await xcodeInspector.safe.realtimeActiveDocumentURL
else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public struct PromptToCode: ReducerProtocol {
generateDescriptionRequirement: copiedState
.generateDescriptionRequirement
)
#warning("TODO: make the action call debounced.")
for try await fragment in stream {
try Task.checkCancellation()
await send(.modifyCodeChunkReceived(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,7 @@ public struct WidgetFeature: ReducerProtocol {
}.cancellable(id: CancelID.observeUserDefaults, cancelInFlight: true)

case .updateActiveApplication:
return .run { send in
if let app = await xcodeInspector.safe.activeApplication, app.isXcode {
await send(.panel(.switchToAnotherEditorAndUpdateContent))
}
}
return .none

case .updateColorScheme:
let widgetColorScheme = UserDefaults.shared.value(for: \.widgetColorScheme)
Expand Down
22 changes: 16 additions & 6 deletions Core/Sources/SuggestionWidget/Styles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension Color {
if appearance.isDarkMode {
return #colorLiteral(red: 0.2284317913, green: 0.2145925438, blue: 0.3214019983, alpha: 1)
}
return #colorLiteral(red: 0.896820749, green: 0.8709097223, blue: 0.9766687925, alpha: 1)
return #colorLiteral(red: 0.9458052187, green: 0.9311983998, blue: 0.9906365955, alpha: 1)
}))
}
}
Expand All @@ -45,12 +45,16 @@ extension NSAppearance {
}
}

extension View {
func xcodeStyleFrame(cornerRadius: Double = 8) -> some View {
clipShape(RoundedRectangle(cornerRadius: cornerRadius, style: .continuous))
.overlay(
struct XcodeLikeFrame<Content: View>: View {
@Environment(\.colorScheme) var colorScheme
let content: Content
let cornerRadius: Double

var body: some View {
content.clipShape(RoundedRectangle(cornerRadius: cornerRadius, style: .continuous))
.background(
RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)
.stroke(Color.black.opacity(0.3), style: .init(lineWidth: 1))
.fill(Material.bar)
)
.overlay(
RoundedRectangle(cornerRadius: max(0, cornerRadius - 1), style: .continuous)
Expand All @@ -60,6 +64,12 @@ extension View {
}
}

extension View {
func xcodeStyleFrame(cornerRadius: Double? = nil) -> some View {
XcodeLikeFrame(content: self, cornerRadius: cornerRadius ?? 10)
}
}

extension MarkdownUI.Theme {
static func custom(fontSize: Double) -> MarkdownUI.Theme {
.gitHub.text {
Expand Down
Loading