Skip to content

Commit

Permalink
Merge branch 'release/0.30.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
intitni committed Jan 22, 2024
2 parents 431231a + 1ad6a58 commit 381005f
Show file tree
Hide file tree
Showing 79 changed files with 2,133 additions and 1,216 deletions.
6 changes: 0 additions & 6 deletions Core/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ let package = Package(
.product(name: "Workspace", package: "Tool"),
.product(name: "UserDefaultsObserver", package: "Tool"),
.product(name: "AppMonitoring", package: "Tool"),
.product(name: "Environment", package: "Tool"),
.product(name: "SuggestionModel", package: "Tool"),
.product(name: "ChatTab", package: "Tool"),
.product(name: "Logger", package: "Tool"),
Expand All @@ -152,7 +151,6 @@ let package = Package(
.product(name: "XPCShared", package: "Tool"),
.product(name: "SuggestionProvider", package: "Tool"),
.product(name: "SuggestionModel", package: "Tool"),
.product(name: "Environment", package: "Tool"),
.product(name: "Preferences", package: "Tool"),
]
),
Expand Down Expand Up @@ -206,7 +204,6 @@ let package = Package(
dependencies: [
.product(name: "FocusedCodeFinder", package: "Tool"),
.product(name: "SuggestionModel", package: "Tool"),
.product(name: "Environment", package: "Tool"),
.product(name: "OpenAIService", package: "Tool"),
.product(name: "AppMonitoring", package: "Tool"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
Expand Down Expand Up @@ -234,7 +231,6 @@ let package = Package(

.product(name: "ChatContextCollector", package: "Tool"),
.product(name: "AppMonitoring", package: "Tool"),
.product(name: "Environment", package: "Tool"),
.product(name: "Parsing", package: "swift-parsing"),
.product(name: "OpenAIService", package: "Tool"),
.product(name: "Preferences", package: "Tool"),
Expand All @@ -246,7 +242,6 @@ let package = Package(
.target(
name: "ChatPlugin",
dependencies: [
.product(name: "Environment", package: "Tool"),
.product(name: "OpenAIService", package: "Tool"),
.product(name: "Terminal", package: "Tool"),
]
Expand Down Expand Up @@ -277,7 +272,6 @@ let package = Package(
.product(name: "UserDefaultsObserver", package: "Tool"),
.product(name: "SharedUIComponents", package: "Tool"),
.product(name: "AppMonitoring", package: "Tool"),
.product(name: "Environment", package: "Tool"),
.product(name: "ChatTab", package: "Tool"),
.product(name: "Logger", package: "Tool"),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
Expand Down
1 change: 0 additions & 1 deletion Core/Sources/ChatPlugin/AITerminalChatPlugin.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Environment
import Foundation
import OpenAIService
import Terminal
Expand Down
26 changes: 13 additions & 13 deletions Core/Sources/ChatPlugin/TerminalChatPlugin.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Environment
import Foundation
import OpenAIService
import Terminal
import XcodeInspector

public actor TerminalChatPlugin: ChatPlugin {
public static var command: String { "run" }
Expand Down Expand Up @@ -34,13 +34,16 @@ public actor TerminalChatPlugin: ChatPlugin {
}

do {
let fileURL = try await Environment.fetchCurrentFileURL()
let projectURL = try await {
if let url = try await Environment.fetchCurrentProjectRootURLFromXcode() {
return url
}
return try await Environment.guessProjectRootURLForFile(fileURL)
}()
let fileURL = XcodeInspector.shared.realtimeActiveDocumentURL
let projectURL = XcodeInspector.shared.realtimeActiveProjectURL

var environment = [String: String]()
if let fileURL {
environment["FILE_PATH"] = fileURL.path
}
if let projectURL {
environment["PROJECT_ROOT"] = projectURL.path
}

await chatGPTService.memory.mutateHistory { history in
history.append(
Expand All @@ -59,11 +62,8 @@ public actor TerminalChatPlugin: ChatPlugin {
let output = terminal.streamCommand(
shell,
arguments: ["-i", "-l", "-c", content],
currentDirectoryPath: projectURL.path,
environment: [
"PROJECT_ROOT": projectURL.path,
"FILE_PATH": fileURL.path,
]
currentDirectoryURL: projectURL,
environment: environment
)

for try await content in output {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ChatPlugin
import Environment
import Foundation
import OpenAIService

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ChatPlugin
import Environment
import Foundation
import OpenAIService

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ChatPlugin
import Environment
import Foundation
import OpenAIService
import Parsing
Expand Down Expand Up @@ -77,7 +76,7 @@ public actor ShortcutChatPlugin: ChatPlugin {
_ = try await terminal.runCommand(
shell,
arguments: ["-i", "-l", "-c", command],
currentDirectoryPath: "/",
currentDirectoryURL: nil,
environment: [:]
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ChatPlugin
import Environment
import Foundation
import OpenAIService
import Parsing
Expand Down Expand Up @@ -77,7 +76,7 @@ public actor ShortcutInputChatPlugin: ChatPlugin {
_ = try await terminal.runCommand(
shell,
arguments: ["-i", "-l", "-c", command],
currentDirectoryPath: "/",
currentDirectoryURL: nil,
environment: [:]
)

Expand Down
72 changes: 72 additions & 0 deletions Core/Sources/HostApp/CustomCommandSettings/CustomCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ struct CustomCommandFeature: ReducerProtocol {
case editCommand(CustomCommand)
case editCustomCommand(EditCustomCommand.Action)
case deleteCommand(CustomCommand)
case exportCommand(CustomCommand)
case importCommand(at: URL)
case importCommandClicked
}

@Dependency(\.toast) var toast
Expand Down Expand Up @@ -49,6 +52,75 @@ struct CustomCommandFeature: ReducerProtocol {
return .none
case .editCustomCommand:
return .none
case let .exportCommand(command):
return .run { _ in
do {
let data = try JSONEncoder().encode(command)
let filename = "CustomCommand-\(command.name).json"

let url = await withCheckedContinuation { continuation in
Task { @MainActor in
let panel = NSSavePanel()
panel.canCreateDirectories = true
panel.nameFieldStringValue = filename
let result = await panel.begin()
switch result {
case .OK:
continuation.resume(returning: panel.url)
default:
continuation.resume(returning: nil)
}
}
}

if let url {
try data.write(to: url)
toast("Saved!", .info)
}

} catch {
toast(error.localizedDescription, .error)
}
}

case let .importCommand(url):
if !isFeatureAvailable(\.unlimitedCustomCommands),
settings.customCommands.count >= 10
{
toast("Upgrade to Plus to add more commands", .info)
return .none
}

do {
let data = try Data(contentsOf: url)
var command = try JSONDecoder().decode(CustomCommand.self, from: data)
command.commandId = UUID().uuidString
settings.customCommands.append(command)
toast("Imported custom command \(command.name)!", .info)
} catch {
toast("Failed to import command: \(error.localizedDescription)", .error)
}
return .none

case .importCommandClicked:
return .run { send in
let url = await withCheckedContinuation { continuation in
Task { @MainActor in
let panel = NSOpenPanel()
panel.allowedContentTypes = [.json]
let result = await panel.begin()
if result == .OK {
continuation.resume(returning: panel.url)
} else {
continuation.resume(returning: nil)
}
}
}

if let url {
await send(.importCommand(at: url))
}
}
}
}.ifLet(\.editCustomCommand, action: /Action.editCustomCommand) {
EditCustomCommand(settings: settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PlusFeatureFlag
import Preferences
import SharedUIComponents
import SwiftUI
import Toast

extension List {
@ViewBuilder
Expand Down Expand Up @@ -51,7 +52,7 @@ struct CustomCommandView: View {
@ViewBuilder
var leftPane: some View {
List {
ForEach(settings.customCommands, id: \.name) { command in
ForEach(settings.customCommands, id: \.commandId) { command in
CommandButton(store: store, command: command)
}
.onMove(perform: { indices, newOffset in
Expand Down Expand Up @@ -92,6 +93,33 @@ struct CustomCommandView: View {
}
.buttonStyle(.plain)
.padding()
.contextMenu {
Button("Import") {
store.send(.importCommandClicked)
}
}
}
.onDrop(of: [.json], delegate: FileDropDelegate(store: store, toast: toast))
}

struct FileDropDelegate: DropDelegate {
let store: StoreOf<CustomCommandFeature>
let toast: (String, ToastType) -> Void
func performDrop(info: DropInfo) -> Bool {
let jsonFiles = info.itemProviders(for: [.json])
for file in jsonFiles {
file.loadInPlaceFileRepresentation(forTypeIdentifier: "public.json") { url, _, error in
Task { @MainActor in
if let url {
store.send(.importCommand(at: url))
} else if let error {
toast(error.localizedDescription, .error)
}
}
}
}

return !jsonFiles.isEmpty
}
}

Expand Down Expand Up @@ -143,6 +171,10 @@ struct CustomCommandView: View {
Button("Remove") {
store.send(.deleteCommand(command))
}

Button("Export") {
store.send(.exportCommand(command))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct SuggestionSettingsView: View {
var suggestionDisplayCompactMode
@AppStorage(\.acceptSuggestionWithTab)
var acceptSuggestionWithTab
@AppStorage(\.dismissSuggestionWithEsc)
var dismissSuggestionWithEsc
@AppStorage(\.isSuggestionSenseEnabled)
var isSuggestionSenseEnabled

Expand Down Expand Up @@ -185,6 +187,10 @@ struct SuggestionSettingsView: View {
Text("Accept Suggestion with Tab")
}
}

Toggle(isOn: $settings.dismissSuggestionWithEsc) {
Text("Dismiss Suggestion with ESC")
}
#endif

HStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ChatGPTChatTab
import ChatTab
import ComposableArchitecture
import Dependencies
import Environment
import Preferences
import SuggestionModel
import SuggestionWidget
Expand Down
7 changes: 7 additions & 0 deletions Core/Sources/Service/GUI/WidgetDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ extension WidgetDataSource: SuggestionWidgetDataSource {
await handler.acceptSuggestion()
NSWorkspace.activatePreviousActiveXcode()
}
},
onDismissSuggestionTapped: {
Task {
let handler = PseudoCommandHandler()
await handler.dismissSuggestion()
NSWorkspace.activatePreviousActiveXcode()
}
}
)
}
Expand Down
Loading

0 comments on commit 381005f

Please sign in to comment.