Skip to content

Commit a8c1bd0

Browse files
committed
Merge branch 'release/0.32.0'
2 parents 6fe8e7d + 5627c03 commit a8c1bd0

File tree

52 files changed

+1004
-230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1004
-230
lines changed

Copilot for Xcode.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
C89E75C32A46FB32000DD64F /* AppDelegate+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89E75C22A46FB32000DD64F /* AppDelegate+Menu.swift */; };
4444
C8C8B60929AFA35F00034BEE /* CopilotForXcodeExtensionService.app in Embed XPCService */ = {isa = PBXBuildFile; fileRef = C861E60E2994F6070056CB02 /* CopilotForXcodeExtensionService.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
4545
C8DCF00029CE11D500FDDDD7 /* ChatWithSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8DCEFFF29CE11D500FDDDD7 /* ChatWithSelection.swift */; };
46+
C8DD9CB12BC673F80036641C /* CloseIdleTabsCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8DD9CB02BC673F80036641C /* CloseIdleTabsCommand.swift */; };
4647
C8F1032B2A7A39D700D28F4F /* launchAgent.plist in Copy Launch Agent */ = {isa = PBXBuildFile; fileRef = C8F103292A7A365000D28F4F /* launchAgent.plist */; };
4748
/* End PBXBuildFile section */
4849

@@ -197,6 +198,7 @@
197198
C89E75C22A46FB32000DD64F /* AppDelegate+Menu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+Menu.swift"; sourceTree = "<group>"; };
198199
C8CD828229B88006008D044D /* TestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = TestPlan.xctestplan; sourceTree = "<group>"; };
199200
C8DCEFFF29CE11D500FDDDD7 /* ChatWithSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatWithSelection.swift; sourceTree = "<group>"; };
201+
C8DD9CB02BC673F80036641C /* CloseIdleTabsCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloseIdleTabsCommand.swift; sourceTree = "<group>"; };
200202
C8F103292A7A365000D28F4F /* launchAgent.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = launchAgent.plist; sourceTree = "<group>"; };
201203
/* End PBXFileReference section */
202204

@@ -264,6 +266,7 @@
264266
C800DBB0294C624D00B04CAC /* PrefetchSuggestionsCommand.swift */,
265267
C8758E6F29F04BFF00D29C1C /* CustomCommand.swift */,
266268
C8DCEFFF29CE11D500FDDDD7 /* ChatWithSelection.swift */,
269+
C8DD9CB02BC673F80036641C /* CloseIdleTabsCommand.swift */,
267270
C861A6A229E5503F005C41A3 /* PromptToCodeCommand.swift */,
268271
C81458972939EFDC00135263 /* Info.plist */,
269272
C81458982939EFDC00135263 /* EditorExtension.entitlements */,
@@ -448,7 +451,7 @@
448451
isa = PBXProject;
449452
attributes = {
450453
BuildIndependentTargetsInParallel = 1;
451-
LastSwiftUpdateCheck = 1420;
454+
LastSwiftUpdateCheck = 1520;
452455
LastUpgradeCheck = 1410;
453456
TargetAttributes = {
454457
C814588B2939EFDC00135263 = {
@@ -525,6 +528,7 @@
525528
files = (
526529
C8DCF00029CE11D500FDDDD7 /* ChatWithSelection.swift in Sources */,
527530
C81458942939EFDC00135263 /* SourceEditorExtension.swift in Sources */,
531+
C8DD9CB12BC673F80036641C /* CloseIdleTabsCommand.swift in Sources */,
528532
C8758E7029F04BFF00D29C1C /* CustomCommand.swift in Sources */,
529533
C8758E7229F04CF100D29C1C /* SeparatorCommand.swift in Sources */,
530534
C861A6A329E5503F005C41A3 /* PromptToCodeCommand.swift in Sources */,

Core/Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ let package = Package(
8989
],
9090
dependencies: [
9191
.package(path: "../Tool"),
92-
.package(url: "https://github.com/apple/swift-async-algorithms", from: "0.1.0"),
92+
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.0.0"),
9393
.package(url: "https://github.com/gonzalezreal/swift-markdown-ui", from: "2.1.0"),
9494
.package(url: "https://github.com/sparkle-project/Sparkle", from: "2.0.0"),
9595
.package(url: "https://github.com/pointfreeco/swift-parsing", from: "0.12.1"),
@@ -113,7 +113,9 @@ let package = Package(
113113
.product(name: "SuggestionModel", package: "Tool"),
114114
.product(name: "Logger", package: "Tool"),
115115
.product(name: "Preferences", package: "Tool"),
116-
]
116+
].pro([
117+
"ProClient",
118+
])
117119
),
118120
.target(
119121
name: "Service",

Core/Sources/ChatGPTChatTab/ChatPanel.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,19 +533,22 @@ struct ChatPanel_EmptyChat_Preview: PreviewProvider {
533533

534534
struct ChatCodeSyntaxHighlighter: CodeSyntaxHighlighter {
535535
let brightMode: Bool
536-
let fontSize: Double
536+
let font: NSFont
537+
let colorChange: Color?
537538

538-
init(brightMode: Bool, fontSize: Double) {
539+
init(brightMode: Bool, font: NSFont, colorChange: Color?) {
539540
self.brightMode = brightMode
540-
self.fontSize = fontSize
541+
self.font = font
542+
self.colorChange = colorChange
541543
}
542544

543545
func highlightCode(_ content: String, language: String?) -> Text {
544546
let content = highlightedCodeBlock(
545547
code: content,
546548
language: language ?? "",
549+
scenario: "chat",
547550
brightMode: brightMode,
548-
fontSize: fontSize
551+
font: font
549552
)
550553
return Text(AttributedString(content))
551554
}

Core/Sources/ChatGPTChatTab/Styles.swift

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ extension View {
4646
.padding(.top, 14)
4747
}
4848

49-
func codeBlockStyle(_ configuration: CodeBlockConfiguration) -> some View {
50-
background(Color(nsColor: .textBackgroundColor).opacity(0.7))
49+
func codeBlockStyle(
50+
_ configuration: CodeBlockConfiguration,
51+
backgroundColor: Color,
52+
labelColor: Color
53+
) -> some View {
54+
background(backgroundColor)
5155
.clipShape(RoundedRectangle(cornerRadius: 6))
5256
.overlay(alignment: .top) {
5357
HStack(alignment: .center) {
5458
Text(configuration.language ?? "code")
55-
.foregroundStyle(.tertiary)
59+
.foregroundStyle(labelColor)
5660
.font(.callout)
5761
.padding(.leading, 8)
5862
.lineLimit(1)
@@ -63,12 +67,76 @@ extension View {
6367
}
6468
}
6569
}
70+
.overlay {
71+
RoundedRectangle(cornerRadius: 6).stroke(Color.primary.opacity(0.05), lineWidth: 1)
72+
}
6673
.markdownMargin(top: 4, bottom: 16)
6774
}
6875
}
6976

77+
struct ThemedMarkdownText: View {
78+
@AppStorage(\.syncChatCodeHighlightTheme) var syncCodeHighlightTheme
79+
@AppStorage(\.codeForegroundColorLight) var codeForegroundColorLight
80+
@AppStorage(\.codeBackgroundColorLight) var codeBackgroundColorLight
81+
@AppStorage(\.codeForegroundColorDark) var codeForegroundColorDark
82+
@AppStorage(\.codeBackgroundColorDark) var codeBackgroundColorDark
83+
@AppStorage(\.chatFontSize) var chatFontSize
84+
@AppStorage(\.chatCodeFont) var chatCodeFont
85+
@Environment(\.colorScheme) var colorScheme
86+
87+
let text: String
88+
89+
init(_ text: String) {
90+
self.text = text
91+
}
92+
93+
var body: some View {
94+
Markdown(text)
95+
.textSelection(.enabled)
96+
.markdownTheme(.custom(
97+
fontSize: chatFontSize,
98+
codeBlockBackgroundColor: {
99+
if syncCodeHighlightTheme {
100+
if colorScheme == .light, let color = codeBackgroundColorLight.value {
101+
return color.swiftUIColor
102+
} else if let color = codeBackgroundColorDark.value {
103+
return color.swiftUIColor
104+
}
105+
}
106+
107+
return Color(nsColor: .textBackgroundColor).opacity(0.7)
108+
}(),
109+
codeBlockLabelColor: {
110+
if syncCodeHighlightTheme {
111+
if colorScheme == .light,
112+
let color = codeForegroundColorLight.value
113+
{
114+
return color.swiftUIColor.opacity(0.5)
115+
} else if let color = codeForegroundColorDark.value {
116+
return color.swiftUIColor.opacity(0.5)
117+
}
118+
}
119+
return Color.secondary.opacity(0.7)
120+
}()
121+
))
122+
.markdownCodeSyntaxHighlighter(
123+
ChatCodeSyntaxHighlighter(
124+
brightMode: colorScheme != .dark,
125+
font: chatCodeFont.value.nsFont,
126+
colorChange: colorScheme == .dark
127+
? codeForegroundColorDark.value?.swiftUIColor
128+
: codeForegroundColorLight.value?.swiftUIColor
129+
)
130+
)
131+
}
132+
}
133+
70134
extension MarkdownUI.Theme {
71-
static func custom(fontSize: Double) -> MarkdownUI.Theme {
135+
static func custom(
136+
fontSize: Double,
137+
codeBlockBackgroundColor: Color,
138+
codeBlockLabelColor: Color
139+
) -> MarkdownUI.Theme {
72140
.gitHub.text {
73141
ForegroundColor(.primary)
74142
BackgroundColor(Color.clear)
@@ -80,14 +148,22 @@ extension MarkdownUI.Theme {
80148
if wrapCode {
81149
configuration.label
82150
.codeBlockLabelStyle()
83-
.codeBlockStyle(configuration)
151+
.codeBlockStyle(
152+
configuration,
153+
backgroundColor: codeBlockBackgroundColor,
154+
labelColor: codeBlockLabelColor
155+
)
84156
} else {
85157
ScrollView(.horizontal) {
86158
configuration.label
87159
.codeBlockLabelStyle()
88160
}
89161
.workaroundForVerticalScrollingBugInMacOS()
90-
.codeBlockStyle(configuration)
162+
.codeBlockStyle(
163+
configuration,
164+
backgroundColor: codeBlockBackgroundColor,
165+
labelColor: codeBlockLabelColor
166+
)
91167
}
92168
}
93169
}
@@ -109,14 +185,22 @@ extension MarkdownUI.Theme {
109185
if wrapCode {
110186
configuration.label
111187
.codeBlockLabelStyle()
112-
.codeBlockStyle(configuration)
188+
.codeBlockStyle(
189+
configuration,
190+
backgroundColor: Color(nsColor: .textBackgroundColor).opacity(0.7),
191+
labelColor: Color.secondary.opacity(0.7)
192+
)
113193
} else {
114194
ScrollView(.horizontal) {
115195
configuration.label
116196
.codeBlockLabelStyle()
117197
}
118198
.workaroundForVerticalScrollingBugInMacOS()
119-
.codeBlockStyle(configuration)
199+
.codeBlockStyle(
200+
configuration,
201+
backgroundColor: Color(nsColor: .textBackgroundColor).opacity(0.7),
202+
labelColor: Color.secondary.opacity(0.7)
203+
)
120204
}
121205
}
122206
.table { configuration in

Core/Sources/ChatGPTChatTab/Views/BotMessage.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ struct BotMessage: View {
1111
let references: [DisplayedChatMessage.Reference]
1212
let chat: StoreOf<Chat>
1313
@Environment(\.colorScheme) var colorScheme
14-
@AppStorage(\.chatFontSize) var chatFontSize
15-
@AppStorage(\.chatCodeFontSize) var chatCodeFontSize
1614

1715
@State var isReferencesPresented = false
1816
@State var isReferencesHovered = false
@@ -45,15 +43,7 @@ struct BotMessage: View {
4543
}
4644
}
4745

48-
Markdown(text)
49-
.textSelection(.enabled)
50-
.markdownTheme(.custom(fontSize: chatFontSize))
51-
.markdownCodeSyntaxHighlighter(
52-
ChatCodeSyntaxHighlighter(
53-
brightMode: colorScheme != .dark,
54-
fontSize: chatCodeFontSize
55-
)
56-
)
46+
ThemedMarkdownText(text)
5747
}
5848
.frame(alignment: .trailing)
5949
.padding()

Core/Sources/ChatGPTChatTab/Views/UserMessage.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,9 @@ struct UserMessage: View {
99
let text: String
1010
let chat: StoreOf<Chat>
1111
@Environment(\.colorScheme) var colorScheme
12-
@AppStorage(\.chatFontSize) var chatFontSize
13-
@AppStorage(\.chatCodeFontSize) var chatCodeFontSize
1412

1513
var body: some View {
16-
Markdown(text)
17-
.textSelection(.enabled)
18-
.markdownTheme(.custom(fontSize: chatFontSize))
19-
.markdownCodeSyntaxHighlighter(
20-
ChatCodeSyntaxHighlighter(
21-
brightMode: colorScheme != .dark,
22-
fontSize: chatCodeFontSize
23-
)
24-
)
14+
ThemedMarkdownText(text)
2515
.frame(alignment: .leading)
2616
.padding()
2717
.background {

Core/Sources/HostApp/AccountSettings/ChatModelManagement/ChatModelEdit.swift

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import AIModel
2-
import Toast
32
import ComposableArchitecture
43
import Dependencies
54
import Keychain
65
import OpenAIService
76
import Preferences
87
import SwiftUI
8+
import Toast
99

1010
struct ChatModelEdit: ReducerProtocol {
1111
struct State: Equatable, Identifiable {
@@ -16,6 +16,7 @@ struct ChatModelEdit: ReducerProtocol {
1616
@BindingState var supportsFunctionCalling: Bool = true
1717
@BindingState var modelName: String = ""
1818
@BindingState var ollamaKeepAlive: String = ""
19+
@BindingState var apiVersion: String = ""
1920
var apiKeyName: String { apiKeySelection.apiKeyName }
2021
var baseURL: String { baseURLSelection.baseURL }
2122
var isFullURL: Bool { baseURLSelection.isFullURL }
@@ -47,6 +48,7 @@ struct ChatModelEdit: ReducerProtocol {
4748
toast($0, $1, "ChatModelEdit")
4849
}
4950
}
51+
5052
@Dependency(\.apiKeyKeychain) var keychain
5153

5254
var body: some ReducerProtocol<State, Action> {
@@ -77,19 +79,7 @@ struct ChatModelEdit: ReducerProtocol {
7779
case .testButtonClicked:
7880
guard !state.isTesting else { return .none }
7981
state.isTesting = true
80-
let model = ChatModel(
81-
id: state.id,
82-
name: state.name,
83-
format: state.format,
84-
info: .init(
85-
apiKeyName: state.apiKeyName,
86-
baseURL: state.baseURL,
87-
isFullURL: state.isFullURL,
88-
maxTokens: state.maxTokens,
89-
supportsFunctionCalling: state.supportsFunctionCalling,
90-
modelName: state.modelName
91-
)
92-
)
82+
let model = ChatModel(state: state)
9383
return .run { send in
9484
do {
9585
let service = ChatGPTService(
@@ -194,6 +184,7 @@ extension ChatModelEdit.State {
194184
supportsFunctionCalling: model.info.supportsFunctionCalling,
195185
modelName: model.info.modelName,
196186
ollamaKeepAlive: model.info.ollamaInfo.keepAlive,
187+
apiVersion: model.info.googleGenerativeAIInfo.apiVersion,
197188
apiKeySelection: .init(
198189
apiKeyName: model.info.apiKeyName,
199190
apiKeyManagement: .init(availableAPIKeyNames: [model.info.apiKeyName])
@@ -223,7 +214,8 @@ extension ChatModel {
223214
}
224215
}(),
225216
modelName: state.modelName.trimmingCharacters(in: .whitespacesAndNewlines),
226-
ollamaInfo: .init(keepAlive: state.ollamaKeepAlive)
217+
ollamaInfo: .init(keepAlive: state.ollamaKeepAlive),
218+
googleGenerativeAIInfo: .init(apiVersion: state.apiVersion)
227219
)
228220
)
229221
}

Core/Sources/HostApp/AccountSettings/ChatModelManagement/ChatModelEditView.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ struct ChatModelEditView: View {
328328

329329
@ViewBuilder
330330
var googleAI: some View {
331+
baseURLTextField(prompt: Text("https://generativelanguage.googleapis.com")) {
332+
Text("/v1")
333+
}
334+
331335
apiKeyNamePicker
332336

333337
WithViewStore(
@@ -353,6 +357,10 @@ struct ChatModelEditView: View {
353357
}
354358

355359
maxTokensTextField
360+
361+
WithViewStore(store, removeDuplicates: { $0.apiVersion == $1.apiVersion }) { viewStore in
362+
TextField("API Version", text: viewStore.$apiVersion, prompt: Text("v1"))
363+
}
356364
}
357365

358366
@ViewBuilder
@@ -392,7 +400,7 @@ struct ChatModelEditView: View {
392400
baseURLTextField(prompt: Text("https://api.anthropic.com")) {
393401
Text("/v1/messages")
394402
}
395-
403+
396404
apiKeyNamePicker
397405

398406
WithViewStore(
@@ -421,7 +429,7 @@ struct ChatModelEditView: View {
421429
.frame(width: 20)
422430
}
423431
}
424-
432+
425433
maxTokensTextField
426434

427435
VStack(alignment: .leading, spacing: 8) {

0 commit comments

Comments
 (0)