Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "copilot.vim"]
path = copilot.vim
url = git@github.com:github/copilot.vim.git
Binary file modified AppIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 2 additions & 15 deletions Copilot for Xcode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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 */; };
C81291AE2994F8A000196E12 /* copilot in Copy CopilotLSP */ = {isa = PBXBuildFile; fileRef = C832A47B2940C71D000989F2 /* copilot */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
C81291D72994FE6900196E12 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C81291D52994FE6900196E12 /* Main.storyboard */; };
C814588F2939EFDC00135263 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C814588E2939EFDC00135263 /* Cocoa.framework */; };
C81458942939EFDC00135263 /* SourceEditorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C81458932939EFDC00135263 /* SourceEditorExtension.swift */; };
Expand Down Expand Up @@ -68,17 +67,6 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
C81291AD2994F88D00196E12 /* Copy CopilotLSP */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 7;
files = (
C81291AE2994F8A000196E12 /* copilot in Copy CopilotLSP */,
);
name = "Copy CopilotLSP";
runOnlyForDeploymentPostprocessing = 0;
};
C814589F2939EFDC00135263 /* Embed Foundation Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -159,7 +147,7 @@
C8216B70298036EC00AD38C7 /* Helper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Helper; sourceTree = BUILT_PRODUCTS_DIR; };
C8216B72298036EC00AD38C7 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
C8216B772980370100AD38C7 /* ReloadLaunchAgent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReloadLaunchAgent.swift; sourceTree = "<group>"; };
C832A47B2940C71D000989F2 /* copilot */ = {isa = PBXFileReference; lastKnownFileType = folder; name = copilot; path = copilot.vim/copilot; sourceTree = "<group>"; };
C82E38492A1F025F00D4EADF /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
C8520300293C4D9000460097 /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
C8520308293D805800460097 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
C861A6A229E5503F005C41A3 /* PromptToCodeCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromptToCodeCommand.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -255,11 +243,11 @@
children = (
C887BC832965D96000931567 /* DEVELOPMENT.md */,
C8520308293D805800460097 /* README.md */,
C82E38492A1F025F00D4EADF /* LICENSE */,
C81E867D296FE4420026E908 /* Version.xcconfig */,
C81458AD293A009600135263 /* Config.xcconfig */,
C81458AE293A009800135263 /* Config.debug.xcconfig */,
C8CD828229B88006008D044D /* TestPlan.xctestplan */,
C832A47B2940C71D000989F2 /* copilot */,
C8189B282938979000C9DCDA /* Core */,
C8189B182938972F00C9DCDA /* Copilot for Xcode */,
C81458922939EFDC00135263 /* EditorExtension */,
Expand Down Expand Up @@ -400,7 +388,6 @@
C861E60A2994F6070056CB02 /* Sources */,
C861E60B2994F6070056CB02 /* Frameworks */,
C861E60C2994F6070056CB02 /* Resources */,
C81291AD2994F88D00196E12 /* Copy CopilotLSP */,
);
buildRules = (
);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions Copilot for Xcode/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
{
"images" : [
{
"filename" : "app-icon-realistic-materials_2x 9.png",
"filename" : "1024 x 1024 your icon@16w.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"filename" : "app-icon-realistic-materials_2x 8.png",
"filename" : "1024 x 1024 your icon@32w 1.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"filename" : "app-icon-realistic-materials_2x 7.png",
"filename" : "1024 x 1024 your icon@32w.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"filename" : "app-icon-realistic-materials_2x 6.png",
"filename" : "1024 x 1024 your icon@64w.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"filename" : "app-icon-realistic-materials_2x 5.png",
"filename" : "1024 x 1024 your icon@128w.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"filename" : "app-icon-realistic-materials_2x 4.png",
"filename" : "1024 x 1024 your icon@256w 1.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"filename" : "app-icon-realistic-materials_2x 3.png",
"filename" : "1024 x 1024 your icon@256w.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"filename" : "app-icon-realistic-materials_2x 2.png",
"filename" : "1024 x 1024 your icon@512w 1.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"filename" : "app-icon-realistic-materials_2x 1.png",
"filename" : "1024 x 1024 your icon@512w.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"filename" : "app-icon-realistic-materials_2x.png",
"filename" : "1024 x 1024 your icon.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 8 additions & 4 deletions Core/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ let package = Package(
.package(url: "https://github.com/apple/swift-async-algorithms", from: "0.1.0"),
.package(url: "https://github.com/raspu/Highlightr", from: "2.1.0"),
.package(url: "https://github.com/JohnSundell/Splash", branch: "master"),
.package(url: "https://github.com/nmdias/FeedKit", from: "9.1.2"),
.package(url: "https://github.com/gonzalezreal/swift-markdown-ui", from: "2.1.0"),
.package(url: "https://github.com/sparkle-project/Sparkle", from: "2.0.0"),
.package(url: "https://github.com/alfianlosari/GPTEncoder", from: "1.0.4"),
Expand Down Expand Up @@ -230,8 +229,7 @@ let package = Package(
name: "UpdateChecker",
dependencies: [
"Logger",
"Sparkle",
.product(name: "FeedKit", package: "FeedKit"),
"Sparkle"
]
),
.target(name: "AXExtension"),
Expand All @@ -255,7 +253,13 @@ let package = Package(

.target(
name: "GitHubCopilotService",
dependencies: ["LanguageClient", "SuggestionModel", "XPCShared", "Preferences"]
dependencies: [
"LanguageClient",
"SuggestionModel",
"XPCShared",
"Preferences",
"Terminal",
]
),
.testTarget(
name: "GitHubCopilotServiceTests",
Expand Down
26 changes: 17 additions & 9 deletions Core/Sources/ChatPlugins/TerminalChatPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,34 @@ public actor TerminalChatPlugin: ChatPlugin {

do {
let fileURL = try await Environment.fetchCurrentFileURL()
let projectURL = try await Environment.fetchCurrentProjectRootURL(fileURL)
let projectURL = try await {
if let url = try await Environment.fetchCurrentProjectRootURLFromXcode() {
return url
}
return try await Environment.guessProjectRootURLForFile(fileURL)
}()

await chatGPTService.mutateHistory { history in
history.append(.init(
role: .user,
content: originalMessage,
summary: "Run command: \(content)")
history.append(
.init(
role: .user,
content: originalMessage,
summary: "Run command: \(content)"
)
)
}

if isCancelled { throw CancellationError() }

let env = ProcessInfo.processInfo.environment
let shell = env["SHELL"] ?? "/bin/bash"

let output = terminal.streamCommand(
shell,
arguments: ["-i", "-l", "-c", content],
currentDirectoryPath: projectURL?.path ?? fileURL.path,
currentDirectoryPath: projectURL.path,
environment: [
"PROJECT_ROOT": projectURL?.path ?? fileURL.path,
"PROJECT_ROOT": projectURL.path,
"FILE_PATH": fileURL.path,
]
)
Expand Down Expand Up @@ -103,9 +110,10 @@ public actor TerminalChatPlugin: ChatPlugin {
isCancelled = true
await terminal.terminate()
}

public func stopResponding() async {
isCancelled = true
await terminal.terminate()
}
}

5 changes: 3 additions & 2 deletions Core/Sources/CodeiumService/CodeiumInstallationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Terminal

public struct CodeiumInstallationManager {
private static var isInstalling = false
static let latestSupportedVersion: String = "1.2.17"
static let latestSupportedVersion = "1.2.17"

public init() {}

Expand Down Expand Up @@ -72,11 +72,12 @@ public struct CodeiumInstallationManager {
try FileManager.default.copyItem(at: fileURL, to: targetURL)
defer { try? FileManager.default.removeItem(at: targetURL) }

// uninstall
continuation.yield(.uninstalling)
try await uninstall()

continuation.yield(.decompressing)
// extract file
continuation.yield(.decompressing)
let terminal = Terminal()
_ = try await terminal.runCommand(
"/usr/bin/gunzip",
Expand Down
64 changes: 34 additions & 30 deletions Core/Sources/Environment/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,47 @@ public enum Environment {
}
}

public static var fetchCurrentProjectRootURL: (_ fileURL: URL?) async throws
-> URL? = { fileURL in
if let xcode = ActiveApplicationMonitor.activeXcode
?? ActiveApplicationMonitor.latestXcode
{
let application = AXUIElementCreateApplication(xcode.processIdentifier)
let focusedWindow = application.focusedWindow
for child in focusedWindow?.children ?? [] {
if child.description.starts(with: "/"), child.description.count > 1 {
let path = child.description
let trimmedNewLine = path.trimmingCharacters(in: .newlines)
var url = URL(fileURLWithPath: trimmedNewLine)
while !FileManager.default.fileIsDirectory(atPath: url.path) ||
!url.pathExtension.isEmpty
{
url = url.deletingLastPathComponent()
}
return url
public static var fetchCurrentProjectRootURLFromXcode: () async throws -> URL? = {
if let xcode = ActiveApplicationMonitor.activeXcode
?? ActiveApplicationMonitor.latestXcode
{
let application = AXUIElementCreateApplication(xcode.processIdentifier)
let focusedWindow = application.focusedWindow
for child in focusedWindow?.children ?? [] {
if child.description.starts(with: "/"), child.description.count > 1 {
let path = child.description
let trimmedNewLine = path.trimmingCharacters(in: .newlines)
var url = URL(fileURLWithPath: trimmedNewLine)
while !FileManager.default.fileIsDirectory(atPath: url.path) ||
!url.pathExtension.isEmpty
{
url = url.deletingLastPathComponent()
}
return url
}
}
}

guard var currentURL = fileURL else { return nil }
var firstDirectoryURL: URL?
while currentURL.pathComponents.count > 1 {
defer { currentURL.deleteLastPathComponent() }
guard FileManager.default.fileIsDirectory(atPath: currentURL.path) else { continue }
if firstDirectoryURL == nil { firstDirectoryURL = currentURL }
let gitURL = currentURL.appendingPathComponent(".git")
if FileManager.default.fileIsDirectory(atPath: gitURL.path) {
return currentURL
}
}
return nil
}

return firstDirectoryURL ?? fileURL
public static var guessProjectRootURLForFile: (_ fileURL: URL) async throws -> URL = {
fileURL in
var currentURL = fileURL
var firstDirectoryURL: URL?
while currentURL.pathComponents.count > 1 {
defer { currentURL.deleteLastPathComponent() }
guard FileManager.default.fileIsDirectory(atPath: currentURL.path) else { continue }
if firstDirectoryURL == nil { firstDirectoryURL = currentURL }
let gitURL = currentURL.appendingPathComponent(".git")
if FileManager.default.fileIsDirectory(atPath: gitURL.path) {
return currentURL
}
}

return firstDirectoryURL ?? fileURL
}

public static var fetchCurrentFileURL: () async throws -> URL = {
guard let xcode = ActiveApplicationMonitor.activeXcode
?? ActiveApplicationMonitor.latestXcode
Expand Down
Loading