Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add support for Codeium chat #485

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# IDE
.idea

# Created by
https://www.toptal.com/developers/gitignore/api/xcode,macos,swift,swiftpackagemanager
# Edit at
Expand Down
28 changes: 22 additions & 6 deletions Copilot for Xcode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
C043C32B2BCA01DD0050406F /* OpenCodeiumChatCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C043C32A2BCA01DD0050406F /* OpenCodeiumChatCommand.swift */; };
C8009BFF2941C551007AA7E8 /* ToggleRealtimeSuggestionsCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8009BFE2941C551007AA7E8 /* ToggleRealtimeSuggestionsCommand.swift */; };
C8009C032941C576007AA7E8 /* RealtimeSuggestionCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8009C022941C576007AA7E8 /* RealtimeSuggestionCommand.swift */; };
C800DBB1294C624D00B04CAC /* PrefetchSuggestionsCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C800DBB0294C624D00B04CAC /* PrefetchSuggestionsCommand.swift */; };
Expand Down Expand Up @@ -149,6 +150,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
C043C32A2BCA01DD0050406F /* OpenCodeiumChatCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenCodeiumChatCommand.swift; sourceTree = "<group>"; };
C8009BFE2941C551007AA7E8 /* ToggleRealtimeSuggestionsCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToggleRealtimeSuggestionsCommand.swift; sourceTree = "<group>"; };
C8009C022941C576007AA7E8 /* RealtimeSuggestionCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RealtimeSuggestionCommand.swift; sourceTree = "<group>"; };
C800DBB0294C624D00B04CAC /* PrefetchSuggestionsCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefetchSuggestionsCommand.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -267,6 +269,7 @@
C861A6A229E5503F005C41A3 /* PromptToCodeCommand.swift */,
C81458972939EFDC00135263 /* Info.plist */,
C81458982939EFDC00135263 /* EditorExtension.entitlements */,
C043C32A2BCA01DD0050406F /* OpenCodeiumChatCommand.swift */,
);
path = EditorExtension;
sourceTree = "<group>";
Expand Down Expand Up @@ -449,7 +452,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1420;
LastUpgradeCheck = 1410;
LastUpgradeCheck = 1520;
TargetAttributes = {
C814588B2939EFDC00135263 = {
CreatedOnToolsVersion = 14.1;
Expand Down Expand Up @@ -537,6 +540,7 @@
C87B03A7293B261900C77EAE /* RejectSuggestionCommand.swift in Sources */,
C8009C032941C576007AA7E8 /* RealtimeSuggestionCommand.swift in Sources */,
C800DBB1294C624D00B04CAC /* PrefetchSuggestionsCommand.swift in Sources */,
C043C32B2BCA01DD0050406F /* OpenCodeiumChatCommand.swift in Sources */,
C81458962939EFDC00135263 /* GetSuggestionsCommand.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -596,7 +600,8 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = "$(APP_BUILD)";
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 7FZQCG2W63;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = EditorExtension/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "$(EXTESNION_BUNDLE_NAME)";
Expand All @@ -623,6 +628,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = "$(APP_BUILD)";
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = EditorExtension/Info.plist;
Expand Down Expand Up @@ -677,9 +683,11 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -738,9 +746,11 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down Expand Up @@ -768,8 +778,9 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = "$(APP_BUILD)";
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Copilot for Xcode/Preview Content\"";
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
DEVELOPMENT_TEAM = 7FZQCG2W63;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -800,6 +811,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = "$(APP_BUILD)";
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Copilot for Xcode/Preview Content\"";
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -825,7 +837,8 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 7FZQCG2W63;
ENABLE_HARDENED_RUNTIME = YES;
MACOSX_DEPLOYMENT_TARGET = 12.0;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -838,7 +851,8 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 7FZQCG2W63;
ENABLE_HARDENED_RUNTIME = YES;
MACOSX_DEPLOYMENT_TARGET = 12.0;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -856,7 +870,8 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = "$(APP_BUILD)";
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 7FZQCG2W63;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -888,6 +903,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = "$(APP_BUILD)";
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1520"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
55 changes: 41 additions & 14 deletions Copilot for Xcode.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
"version" : "1.0.2"
}
},
{
"identity" : "generative-ai-swift",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these changes do?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Package.resolved file is updated because I mostly develop in another workspace. Maybe it's better to just uncheck the file for this pull request if no dependency is added?

"kind" : "remoteSourceControl",
"location" : "https://github.com/google/generative-ai-swift",
"state" : {
"revision" : "f4a88085d5a6c1108f5a1aead83d19d02df8328d",
"version" : "0.4.9"
}
},
{
"identity" : "glob",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -54,6 +63,15 @@
"version" : "0.6.0"
}
},
{
"identity" : "keyboardshortcuts",
"kind" : "remoteSourceControl",
"location" : "https://github.com/intitni/KeyboardShortcuts",
"state" : {
"branch" : "main",
"revision" : "65fb410b0c6d3ed96623b460bab31ffce5f48b4d"
}
},
{
"identity" : "languageclient",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -99,6 +117,24 @@
"version" : "2.4.2"
}
},
{
"identity" : "sttextkitplus",
"kind" : "remoteSourceControl",
"location" : "https://github.com/krzyzanowskim/STTextKitPlus",
"state" : {
"revision" : "a57a2081e364c71b11e521ed8800481e8da300ac",
"version" : "0.1.0"
}
},
{
"identity" : "sttextview",
"kind" : "remoteSourceControl",
"location" : "https://github.com/krzyzanowskim/STTextView",
"state" : {
"revision" : "e9e54718b882115db69ec1e17ac1bec844906cd9",
"version" : "0.9.0"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -203,8 +239,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"branch" : "main",
"revision" : "aa3b1e187c9cc568f9d1abc47feb11f6b044d284"
"revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version" : "509.0.2"
}
},
{
Expand All @@ -219,10 +255,10 @@
{
"identity" : "swifttreesitter",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ChimeHQ/SwiftTreeSitter",
"location" : "https://github.com/intitni/SwiftTreeSitter.git",
"state" : {
"revision" : "df25a52f72ebc5b50ae20d26d1363793408bb28b",
"version" : "0.7.1"
"branch" : "main",
"revision" : "fd499bfafcccfae12a1a579dc922d8418025a35d"
}
},
{
Expand Down Expand Up @@ -252,15 +288,6 @@
"revision" : "1b54ef0b5efddddf393b45e173788499cc572048"
}
},
{
"identity" : "tree-sitter-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/alex-pinkus/tree-sitter-swift",
"state" : {
"branch" : "with-generated-files",
"revision" : "eda05af7ac41adb4eb19c346883c0fa32fe3bdd8"
}
},
{
"identity" : "usearch",
"kind" : "remoteSourceControl",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1520"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1520"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
8 changes: 8 additions & 0 deletions Core/Sources/Client/AsyncXPCService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ public struct AsyncXPCService {
{ $0.chatWithSelection }
)
}

public func openChat(editorContent: EditorContent) async throws -> UpdatedContent? {
try await suggestionRequest(
connection,
editorContent,
{ $0.openChat }
)
}

public func promptToCode(editorContent: EditorContent) async throws -> UpdatedContent? {
try await suggestionRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ protocol SuggestionCommandHandler {
func promptToCode(editor: EditorContent) async throws -> UpdatedContent?
@ServiceActor
func customCommand(id: String, editor: EditorContent) async throws -> UpdatedContent?
@ServiceActor
func openChat(editor: EditorContent) async throws -> UpdatedContent?
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,27 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
}
return nil
}

@WorkspaceActor
private func _openChat(editor: EditorContent) async throws {
guard let fileURL = await XcodeInspector.shared.safe.realtimeActiveDocumentURL
else { return }

let (workspace, _) = try await Service.shared.workspacePool
.fetchOrCreateWorkspaceAndFilespace(fileURL: fileURL)
try? await workspace.openChat()
}

func openChat(editor: EditorContent) async throws -> UpdatedContent? {
Task {
do {
try await _openChat(editor: editor)
} catch {
presenter.presentError(error)
}
}
return nil
}

func promptToCode(editor: EditorContent) async throws -> UpdatedContent? {
Task {
Expand Down
9 changes: 9 additions & 0 deletions Core/Sources/Service/XPCService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ public class XPCService: NSObject, XPCServiceProtocol {
try await handler.promptToCode(editor: editor)
}
}

public func openChat(
editorContent: Data,
withReply reply: @escaping (Data?, Error?) -> Void
) {
replyWithUpdatedContent(editorContent: editorContent, withReply: reply) { handler, editor in
try await handler.openChat(editor: editor)
}
}

public func customCommand(
id: String,
Expand Down
4 changes: 4 additions & 0 deletions Core/Sources/SuggestionService/SuggestionService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,9 @@ public extension SuggestionService {
func terminate() async {
await suggestionProvider.terminate()
}

func openChat() async throws {
try await suggestionProvider.openChat()
}
}

19 changes: 19 additions & 0 deletions EditorExtension/OpenCodeiumChatCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Client
import SuggestionModel
import Foundation
import XcodeKit

class OpenCodeiumChatCommand: NSObject, XCSourceEditorCommand, CommandType {
var name: String { "Open Codeium Chat" }

func perform(
with invocation: XCSourceEditorCommandInvocation,
completionHandler: @escaping (Error?) -> Void
) {
completionHandler(nil)
Task {
let service = try getService()
_ = try await service.openChat(editorContent: .init(invocation))
}
}
}
1 change: 1 addition & 0 deletions EditorExtension/SourceEditorExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SourceEditorExtension: NSObject, XCSourceEditorExtension {
PromptToCodeCommand(),
AcceptPromptToCodeCommand(),
ChatWithSelectionCommand(),
OpenCodeiumChatCommand(),
].map(makeCommandDefinition)
}

Expand Down