Skip to content

Commit ff96656

Browse files
committed
Merge branch 'feature/what-happened' into develop
2 parents 348dc9a + 1e57d8d commit ff96656

24 files changed

Lines changed: 1467 additions & 845 deletions

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "Pro"]
2-
path = Pro
3-
url = git@github.com:intitni/CopilotForXcodePro.git

Copilot for Xcode.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@
205205
C8216B772980370100AD38C7 /* ReloadLaunchAgent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReloadLaunchAgent.swift; sourceTree = "<group>"; };
206206
C828B27D2B1F241500E7612A /* ExtensionPoint.appextensionpoint */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = ExtensionPoint.appextensionpoint; sourceTree = "<group>"; };
207207
C82E38492A1F025F00D4EADF /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
208-
C83E5DED2A38CD8C0071506D /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
209208
C8520300293C4D9000460097 /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
210209
C8520308293D805800460097 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
211210
C861A6A229E5503F005C41A3 /* PromptToCodeCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromptToCodeCommand.swift; sourceTree = "<group>"; };
@@ -335,7 +334,6 @@
335334
C887BC832965D96000931567 /* DEVELOPMENT.md */,
336335
C8520308293D805800460097 /* README.md */,
337336
C82E38492A1F025F00D4EADF /* LICENSE */,
338-
C83E5DED2A38CD8C0071506D /* Makefile */,
339337
C8F103292A7A365000D28F4F /* launchAgent.plist */,
340338
C8738B6D2BE4F3E800609E7F /* bridgeLaunchAgent.plist */,
341339
C81E867D296FE4420026E908 /* Version.xcconfig */,

Core/Package.swift

Lines changed: 71 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,6 @@
44
import Foundation
55
import PackageDescription
66

7-
// MARK: - Pro
8-
9-
extension [Target.Dependency] {
10-
func pro(_ targetNames: [String]) -> [Target.Dependency] {
11-
if isProIncluded {
12-
// include the pro package
13-
return self + targetNames.map { Target.Dependency.product(name: $0, package: "Pro") }
14-
}
15-
return self
16-
}
17-
}
18-
19-
extension [Package.Dependency] {
20-
var pro: [Package.Dependency] {
21-
if isProIncluded {
22-
// include the pro package
23-
return self + [.package(path: "../Pro/Pro")]
24-
}
25-
return self
26-
}
27-
}
28-
29-
let isProIncluded: Bool = {
30-
func isProIncluded(file: StaticString = #file) -> Bool {
31-
let filePath = "\(file)"
32-
let fileURL = URL(fileURLWithPath: filePath)
33-
let rootURL = fileURL
34-
.deletingLastPathComponent()
35-
.deletingLastPathComponent()
36-
let confURL = rootURL.appendingPathComponent("PLUS")
37-
if !FileManager.default.fileExists(atPath: confURL.path) {
38-
return false
39-
}
40-
do {
41-
if let content = try String(
42-
data: Data(contentsOf: confURL),
43-
encoding: .utf8
44-
) {
45-
if content.hasPrefix("YES") {
46-
return true
47-
}
48-
}
49-
return false
50-
} catch {
51-
return false
52-
}
53-
}
54-
55-
return isProIncluded()
56-
}()
57-
587
// MARK: - Package
598

609
let package = Package(
@@ -101,6 +50,8 @@ let package = Package(
10150
// quick hack to support custom UserDefaults
10251
// https://github.com/sindresorhus/KeyboardShortcuts
10352
.package(url: "https://github.com/intitni/KeyboardShortcuts", branch: "main"),
53+
.package(url: "https://github.com/intitni/CGEventOverride", from: "1.2.1"),
54+
.package(url: "https://github.com/intitni/Highlightr", branch: "master"),
10455
].pro,
10556
targets: [
10657
// MARK: - Main
@@ -127,6 +78,8 @@ let package = Package(
12778
"ServiceUpdateMigration",
12879
"ChatGPTChatTab",
12980
"PlusFeatureFlag",
81+
"KeyBindingManager",
82+
"XcodeThemeController",
13083
.product(name: "XPCShared", package: "Tool"),
13184
.product(name: "SuggestionProvider", package: "Tool"),
13285
.product(name: "Workspace", package: "Tool"),
@@ -377,6 +330,73 @@ let package = Package(
377330
],
378331
path: "Sources/ChatContextCollectors/SystemInfoChatContextCollector"
379332
),
333+
334+
// MARK: Key Binding
335+
336+
.target(
337+
name: "KeyBindingManager",
338+
dependencies: [
339+
.product(name: "Workspace", package: "Tool"),
340+
.product(name: "Preferences", package: "Tool"),
341+
.product(name: "Logger", package: "Tool"),
342+
.product(name: "CGEventOverride", package: "CGEventOverride"),
343+
.product(name: "AppMonitoring", package: "Tool"),
344+
.product(name: "UserDefaultsObserver", package: "Tool"),
345+
]
346+
),
347+
.testTarget(
348+
name: "KeyBindingManagerTests",
349+
dependencies: ["KeyBindingManager"]
350+
),
351+
352+
// MARK: Theming
353+
354+
.target(
355+
name: "XcodeThemeController",
356+
dependencies: [
357+
.product(name: "Preferences", package: "Tool"),
358+
.product(name: "AppMonitoring", package: "Tool"),
359+
.product(name: "Highlightr", package: "Highlightr"),
360+
]
361+
),
362+
380363
]
381364
)
382365

366+
extension [Target.Dependency] {
367+
func pro(_ targetNames: [String]) -> [Target.Dependency] {
368+
if isProIncluded {
369+
// include the pro package
370+
return self + targetNames.map { Target.Dependency.product(name: $0, package: "Pro") }
371+
}
372+
return self
373+
}
374+
}
375+
376+
extension [Package.Dependency] {
377+
var pro: [Package.Dependency] {
378+
if isProIncluded {
379+
// include the pro package
380+
return self + [.package(path: "../../CopilotForXcodePro/Pro")]
381+
}
382+
return self
383+
}
384+
}
385+
386+
let isProIncluded: Bool = {
387+
func isProIncluded(file: StaticString = #file) -> Bool {
388+
let filePath = "\(file)"
389+
let fileURL = URL(fileURLWithPath: filePath)
390+
let rootURL = fileURL
391+
.deletingLastPathComponent()
392+
.deletingLastPathComponent()
393+
.deletingLastPathComponent()
394+
let confURL = rootURL.appendingPathComponent("PLUS")
395+
if !FileManager.default.fileExists(atPath: confURL.path) {
396+
return false
397+
}
398+
return true
399+
}
400+
401+
return isProIncluded()
402+
}()

Core/Sources/ChatGPTChatTab/Chat.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ChatBasic
12
import ChatService
23
import ComposableArchitecture
34
import Foundation
@@ -48,7 +49,7 @@ public struct DisplayedChatMessage: Equatable {
4849
self.id = id
4950
self.role = role
5051
self.text = text
51-
self.markdownContent = .init(text)
52+
markdownContent = .init(text)
5253
self.references = references
5354
}
5455
}

Core/Sources/HostApp/FeatureSettings/Chat/ChatSettingsGeneralSectionView.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,8 @@ struct ChatSettingsGeneralSectionView: View {
235235
Text("Wrap text in code block")
236236
}
237237

238-
#if canImport(ProHostApp)
239-
240238
CodeHighlightThemePicker(scenario: .chat)
241239

242-
#endif
243-
244240
Toggle(isOn: $settings.disableFloatOnTopWhenTheChatPanelIsDetached) {
245241
Text("Disable always-on-top when the chat panel is detached")
246242
}

Core/Sources/HostApp/FeatureSettings/PromptToCodeSettingsView.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ struct PromptToCodeSettingsView: View {
9595
Text("Wrap code")
9696
}
9797

98-
#if canImport(ProHostApp)
99-
10098
CodeHighlightThemePicker(scenario: .promptToCode)
101-
102-
#endif
10399

104100
FontPicker(font: $settings.font) {
105101
Text("Font")

Core/Sources/HostApp/FeatureSettings/Suggestion/SuggestionSettingsGeneralSectionView.swift

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,28 +172,24 @@ struct SuggestionSettingsGeneralSectionView: View {
172172
Text("Real-time suggestion")
173173
}
174174

175-
#if canImport(ProHostApp)
176-
WithFeatureEnabled(\.tabToAcceptSuggestion) {
177-
Toggle(isOn: $settings.acceptSuggestionWithTab) {
178-
HStack {
179-
Text("Accept suggestion with Tab")
175+
Toggle(isOn: $settings.acceptSuggestionWithTab) {
176+
HStack {
177+
Text("Accept suggestion with Tab")
180178

181-
Button(action: {
182-
isTabToAcceptSuggestionModifierViewOpen = true
183-
}) {
184-
Image(systemName: "gearshape.fill")
185-
}
186-
.buttonStyle(.plain)
179+
Button(action: {
180+
isTabToAcceptSuggestionModifierViewOpen = true
181+
}) {
182+
Image(systemName: "gearshape.fill")
187183
}
188-
}.sheet(isPresented: $isTabToAcceptSuggestionModifierViewOpen) {
189-
TabToAcceptSuggestionModifierView()
184+
.buttonStyle(.plain)
190185
}
186+
}.sheet(isPresented: $isTabToAcceptSuggestionModifierViewOpen) {
187+
TabToAcceptSuggestionModifierView()
191188
}
192189

193190
Toggle(isOn: $settings.dismissSuggestionWithEsc) {
194191
Text("Dismiss suggestion with ESC")
195192
}
196-
#endif
197193

198194
HStack {
199195
Toggle(isOn: $settings.disableSuggestionFeatureGlobally) {
@@ -249,12 +245,8 @@ struct SuggestionSettingsGeneralSectionView: View {
249245
Text("Hide common preceding spaces")
250246
}
251247

252-
#if canImport(ProHostApp)
253-
254248
CodeHighlightThemePicker(scenario: .suggestion)
255249

256-
#endif
257-
258250
FontPicker(font: $settings.font) {
259251
Text("Font")
260252
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import Foundation
2+
import Preferences
3+
import SwiftUI
4+
5+
public struct CodeHighlightThemePicker: View {
6+
public enum Scenario {
7+
case suggestion
8+
case promptToCode
9+
case chat
10+
}
11+
12+
let scenario: Scenario
13+
14+
public init(scenario: Scenario) {
15+
self.scenario = scenario
16+
}
17+
18+
public var body: some View {
19+
switch scenario {
20+
case .suggestion:
21+
SuggestionThemePicker()
22+
case .promptToCode:
23+
PromptToCodeThemePicker()
24+
case .chat:
25+
ChatThemePicker()
26+
}
27+
}
28+
29+
struct SuggestionThemePicker: View {
30+
@AppStorage(\.syncSuggestionHighlightTheme) var sync: Bool
31+
var body: some View {
32+
SyncToggle(sync: $sync)
33+
}
34+
}
35+
36+
struct PromptToCodeThemePicker: View {
37+
@AppStorage(\.syncPromptToCodeHighlightTheme) var sync: Bool
38+
var body: some View {
39+
SyncToggle(sync: $sync)
40+
}
41+
}
42+
43+
struct ChatThemePicker: View {
44+
@AppStorage(\.syncChatCodeHighlightTheme) var sync: Bool
45+
var body: some View {
46+
SyncToggle(sync: $sync)
47+
}
48+
}
49+
50+
struct SyncToggle: View {
51+
@Binding var sync: Bool
52+
53+
var body: some View {
54+
VStack(alignment: .leading) {
55+
Toggle(isOn: $sync) {
56+
Text("Sync color scheme with Xcode")
57+
}
58+
59+
Text("To refresh the theme, you must activate the extension service app once.")
60+
.font(.footnote)
61+
.foregroundColor(.secondary)
62+
}
63+
}
64+
}
65+
}
66+
67+
#Preview {
68+
@State var sync = false
69+
return CodeHighlightThemePicker.SyncToggle(sync: $sync)
70+
}
71+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
import Workspace
3+
4+
public final class KeyBindingManager {
5+
let tabToAcceptSuggestion: TabToAcceptSuggestion
6+
7+
public init(
8+
workspacePool: WorkspacePool,
9+
acceptSuggestion: @escaping () -> Void,
10+
dismissSuggestion: @escaping () -> Void
11+
) {
12+
tabToAcceptSuggestion = .init(
13+
workspacePool: workspacePool,
14+
acceptSuggestion: acceptSuggestion,
15+
dismissSuggestion: dismissSuggestion
16+
)
17+
}
18+
19+
public func start() {
20+
tabToAcceptSuggestion.start()
21+
}
22+
23+
@MainActor
24+
public func stopForExit() {
25+
tabToAcceptSuggestion.stopForExit()
26+
}
27+
}
28+
29+

0 commit comments

Comments
 (0)