Skip to content

Commit 4963f78

Browse files
committed
Merge tag '0.23.0' into develop
2 parents 4fddb24 + f91cbe5 commit 4963f78

File tree

16 files changed

+113
-52
lines changed

16 files changed

+113
-52
lines changed

Core/Sources/HostApp/AccountSettings/SharedModelManagement/BaseURLPicker.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ struct BaseURLPicker: View {
1414
selection: viewStore.$baseURL,
1515
content: {
1616
if !viewStore.state.availableBaseURLs
17-
.contains(viewStore.state.baseURL)
17+
.contains(viewStore.state.baseURL),
18+
!viewStore.state.baseURL.isEmpty
1819
{
1920
Text("Custom Value").tag(viewStore.state.baseURL)
2021
}
2122

23+
Text("Empty (Default Value)").tag("")
24+
2225
ForEach(viewStore.state.availableBaseURLs, id: \.self) { baseURL in
2326
Text(baseURL).tag(baseURL)
2427
}

Core/Sources/HostApp/AccountSettings/SharedModelManagement/BaseURLSelection.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ struct BaseURLSelection: ReducerProtocol {
3131
case .refreshAvailableBaseURLNames:
3232
let chatModels = userDefaults.value(for: \.chatModels)
3333
let embeddingModels = userDefaults.value(for: \.embeddingModels)
34-
let allBaseURLs = Set(
34+
var allBaseURLs = Set(
3535
chatModels.map(\.info.baseURL)
3636
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
3737
+ embeddingModels.map(\.info.baseURL)
3838
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
3939
)
40+
allBaseURLs.remove("")
4041
state.availableBaseURLs = Array(allBaseURLs).sorted()
4142
return .none
4243

Core/Sources/HostApp/DebugView.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ struct DebugSettingsView: View {
5858
Toggle(isOn: $settings.useUserDefaultsBaseAPIKeychain) {
5959
Text("Store API keys in UserDefaults")
6060
}
61+
62+
Button("Reset Migration Version to 0") {
63+
UserDefaults.shared.set(nil, forKey: "OldMigrationVersion")
64+
}
65+
66+
Button("Reset 0.23.0 migration") {
67+
UserDefaults.shared.set("239", forKey: "OldMigrationVersion")
68+
UserDefaults.shared.set(nil, forKey: "MigrateTo240Finished")
69+
UserDefaults.shared.set(nil, forKey: "ChatModels")
70+
UserDefaults.shared.set(nil, forKey: "EmbeddingModels")
71+
}
6172
}
6273
}
6374
.padding()

Core/Sources/PromptToCodeService/OpenAIPromptToCodeService.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
136136
}()
137137

138138
let annotations = isDetached
139-
? []
139+
? ""
140140
: extractAnnotations(editorInformation: editor, source: source)
141141

142142
let firstMessage: String? = {
@@ -148,17 +148,15 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
148148
\(code)
149149
```
150150
151-
line annotations found:
152-
\(annotations.map { "- \($0)" }.joined(separator: "\n"))
151+
\(annotations)
153152
"""
154153
default:
155154
return """
156155
```
157156
\(code)
158157
```
159158
160-
line annotations found:
161-
\(annotations.map { "- \($0)" }.joined(separator: "\n"))
159+
\(annotations)
162160
"""
163161
}
164162
}()
@@ -274,9 +272,9 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
274272
func extractAnnotations(
275273
editorInformation: EditorInformation,
276274
source: PromptToCodeSource
277-
) -> [String] {
278-
guard let annotations = editorInformation.editorContent?.lineAnnotations else { return [] }
279-
return annotations
275+
) -> String {
276+
guard let annotations = editorInformation.editorContent?.lineAnnotations else { return "" }
277+
let all = annotations
280278
.lazy
281279
.filter { annotation in
282280
annotation.line >= source.range.start.line + 1
@@ -285,6 +283,11 @@ public final class OpenAIPromptToCodeService: PromptToCodeServiceType {
285283
let relativeLine = annotation.line - source.range.start.line
286284
return "line \(relativeLine): \(annotation.type) \(annotation.message)"
287285
}
286+
guard !all.isEmpty else { return "" }
287+
return """
288+
line annotations found:
289+
\(annotations.map { "- \($0)" }.joined(separator: "\n"))
290+
"""
288291
}
289292
}
290293

Core/Sources/ServiceUpdateMigration/ServiceUpdateMigrator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct ServiceUpdateMigrator {
2222
}
2323

2424
func migrate(from oldVersion: String, to currentVersion: String) async throws {
25-
guard let old = Int(oldVersion) else { return }
25+
guard let old = Int(oldVersion), old != 0 else { return }
2626
if old <= 135 {
2727
try migrateFromLowerThanOrEqualToVersion135()
2828
}

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCode.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public struct PromptToCode: ReducerProtocol {
105105
self.generateDescriptionRequirement = generateDescriptionRequirement
106106
self.isAttachedToSelectionRange = isAttachedToSelectionRange
107107
self.commandName = commandName
108+
109+
if selectionRange?.isEmpty ?? true {
110+
self.isAttachedToSelectionRange = false
111+
}
108112
}
109113
}
110114

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCodeGroup.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import ComposableArchitecture
22
import Foundation
33
import PromptToCodeService
44
import SuggestionModel
5+
import Environment
56

67
public struct PromptToCodeGroup: ReducerProtocol {
78
public struct State: Equatable {
@@ -130,7 +131,9 @@ public struct PromptToCodeGroup: ReducerProtocol {
130131
switch action {
131132
case .cancelButtonTapped:
132133
state.promptToCodes.remove(id: id)
133-
return .none
134+
return .run { _ in
135+
try await Environment.makeXcodeActive()
136+
}
134137
default:
135138
return .none
136139
}

Core/Sources/SuggestionWidget/FeatureReducers/WidgetFeature.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public struct WidgetFeature: ReducerProtocol {
7979
)
8080
}
8181
}
82+
83+
var lastUpdateWindowOpacityTime = Date(timeIntervalSince1970: 0)
8284

8385
public init() {}
8486
}
@@ -109,6 +111,7 @@ public struct WidgetFeature: ReducerProtocol {
109111
case updateWindowLocation(animated: Bool)
110112
case updateWindowOpacity
111113
case updateFocusingDocumentURL
114+
case updateWindowOpacityFinished
112115

113116
case panel(PanelFeature.Action)
114117
case chatPanel(ChatPanelFeature.Action)
@@ -513,9 +516,12 @@ public struct WidgetFeature: ReducerProtocol {
513516
case .updateWindowOpacity:
514517
let isChatPanelDetached = state.chatPanelState.chatPanelInASeparateWindow
515518
let hasChat = !state.chatPanelState.chatTabGroup.tabInfo.isEmpty
516-
return .run { _ in
517-
try await mainQueue.sleep(for: .seconds(0.2))
518-
Task { @MainActor in
519+
let shouldDebounce = Date().timeIntervalSince(state.lastUpdateWindowOpacityTime) < 1
520+
return .run { send in
521+
if shouldDebounce {
522+
try await mainQueue.sleep(for: .seconds(0.2))
523+
}
524+
let task = Task { @MainActor in
519525
if let app = activeApplicationMonitor.activeApplication, app.isXcode {
520526
let application = AXUIElementCreateApplication(app.processIdentifier)
521527
/// We need this to hide the windows when Xcode is minimized.
@@ -564,8 +570,14 @@ public struct WidgetFeature: ReducerProtocol {
564570
}
565571
}
566572
}
573+
_ = await task.value
574+
await send(.updateWindowOpacityFinished)
567575
}
568576
.cancellable(id: DebounceKey.updateWindowOpacity, cancelInFlight: true)
577+
578+
case .updateWindowOpacityFinished:
579+
state.lastUpdateWindowOpacityTime = Date()
580+
return .none
569581

570582
case .circularWidget:
571583
return .none

Core/Sources/SuggestionWidget/SuggestionPanelContent/PromptToCodePanel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ extension PromptToCodePanel {
7878
}
7979
}.foregroundColor(.primary)
8080
} else {
81-
Text("text selection").foregroundColor(.secondary)
81+
Text("current selection").foregroundColor(.secondary)
8282
}
8383
}
8484
.padding(2)

DEVELOPMENT.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,20 @@ The `ExtensionService` is a program that operates in the background and performs
1818

1919
Most of the logics are implemented inside the package `Core` and `Tool`.
2020

21-
- The `CopilotService` is responsible for communicating with the GitHub Copilot LSP.
2221
- The `Service` is responsible for handling the requests from the `EditorExtension`, communicating with the `CopilotService`, update the code blocks and present the GUI.
2322
- The `Client` is basically just a wrapper around the XPCService
2423
- The `SuggestionInjector` is responsible for injecting the suggestions into the code. Used in comment mode to present the suggestions, and all modes to accept suggestions.
25-
- The `Environment` contains some swappable global functions. It is used to make testing easier.
26-
- The `SuggestionWidget` is responsible for presenting the suggestions in floating widget mode.
24+
- The `SuggestionWidget` is responsible for the UI of the widgets.
2725

2826
## Building and Archiving the App
2927

3028
1. Update the xcconfig files, launchAgent.plist, and Tool/Configs/Configurations.swift.
3129
2. Build or archive the Copilot for Xcode target.
3230
3. If Xcode complains that the pro package doesn't exist, please remove the package from the project, and update the last function in Core/Package.swift to return false.
3331

34-
## Testing Extension
32+
## Testing Source Editor Extension
3533

36-
Just run both the `ExtensionService` and the `EditorExtension` Target.
34+
Just run both the `ExtensionService` and the `EditorExtension` Target. Read [Testing Your Source Editor Extension](https://developer.apple.com/documentation/xcodekit/testing_your_source_editor_extension) for more details.
3735

3836
## SwiftUI Previews
3937

0 commit comments

Comments
 (0)