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
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ struct GitHubCopilotView: View {
case let .installed(version):
Text("Copilot.Vim Version: \(version)")
uninstallButton
case let .outdated(version, latest):
case let .outdated(version, latest, _):
Text("Copilot.Vim Version: \(version) (Update Available: \(latest))")
updateButton
uninstallButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ToastPanelView: View {
}() as Color, in: RoundedRectangle(cornerRadius: 8))
.overlay {
RoundedRectangle(cornerRadius: 8)
.stroke(Color.black.opacity(0.3), lineWidth: 1)
.stroke(Color.black.opacity(0.1), lineWidth: 1)
}
}

Expand Down
1 change: 1 addition & 0 deletions Tool/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ let package = Package(
"Preferences",
"Terminal",
"BuiltinExtension",
"Toast",
.product(name: "LanguageServerProtocol", package: "LanguageServerProtocol"),
.product(name: "CopilotForXcodeKit", package: "CopilotForXcodeKit"),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
import Foundation
import Logger
import Workspace
import Toast
import Dependencies

public final class GitHubCopilotWorkspacePlugin: WorkspacePlugin {
enum Error: Swift.Error, LocalizedError {
case gitHubCopilotLanguageServerMustBeUpdated
var errorDescription: String? {
switch self {
case .gitHubCopilotLanguageServerMustBeUpdated:
return "GitHub Copilot language server must be updated. Update will start immediately. \nIf it fails, please go to Host app > Service > GitHub Copilot and check if there is an update available."
}
}
}

@Dependency(\.toast) var toast

let installationManager = GitHubCopilotInstallationManager()
private var _gitHubCopilotService: GitHubCopilotService?
@GitHubCopilotSuggestionActor
var gitHubCopilotService: GitHubCopilotService? {
if let service = _gitHubCopilotService { return service }
do {
return try createGitHubCopilotService()
} catch let error as Error {
toast(error.localizedDescription, .warning)
Task {
await updateLanguageServerIfPossible()
}
return nil
} catch {
Logger.gitHubCopilot.error("Failed to create GitHub Copilot service: \(error)")
return nil
Expand All @@ -23,6 +44,9 @@ public final class GitHubCopilotWorkspacePlugin: WorkspacePlugin {

@GitHubCopilotSuggestionActor
func createGitHubCopilotService() throws -> GitHubCopilotService {
if case .outdated(_, _, true) = installationManager.checkInstallation() {
throw Error.gitHubCopilotLanguageServerMustBeUpdated
}
let newService = try GitHubCopilotService(projectRootURL: projectRootURL)
_gitHubCopilotService = newService
newService.localProcessServer?.terminationHandler = { [weak self] in
Expand Down Expand Up @@ -50,6 +74,30 @@ public final class GitHubCopilotWorkspacePlugin: WorkspacePlugin {
}
}
}

@GitHubCopilotSuggestionActor
func updateLanguageServerIfPossible() async {
guard !GitHubCopilotInstallationManager.isInstalling else { return }
let events = installationManager.installLatestVersion()
do {
for try await event in events {
switch event {
case .downloading:
toast("Updating GitHub Copilot language server", .info)
case .uninstalling:
break
case .decompressing:
break
case .done:
toast("Finished updating GitHub Copilot language server", .info)
}
}
} catch GitHubCopilotInstallationManager.Error.isInstalling {
return
} catch {
toast(error.localizedDescription, .error)
}
}

func terminate() {
_gitHubCopilotService = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Foundation
import Terminal

public struct GitHubCopilotInstallationManager {
private static var isInstalling = false
@GitHubCopilotSuggestionActor
public private(set) static var isInstalling = false

static var downloadURL: URL {
let commitHash = "c79d711cbf7c6672c6c57d6df7c5ab7b6cac2b7a"
Expand All @@ -11,13 +12,14 @@ public struct GitHubCopilotInstallationManager {
}

static let latestSupportedVersion = "1.33.0"
static let minimumSupportedVersion = "1.32.0"

public init() {}

public enum InstallationStatus {
case notInstalled
case installed(String)
case outdated(current: String, latest: String)
case outdated(current: String, latest: String, mandatory: Bool)
case unsupported(current: String, latest: String)
}

Expand All @@ -38,15 +40,22 @@ public struct GitHubCopilotInstallationManager {
{
switch version.compare(Self.latestSupportedVersion) {
case .orderedAscending:
return .outdated(current: version, latest: Self.latestSupportedVersion)
switch version.compare(Self.minimumSupportedVersion) {
case .orderedAscending:
return .outdated(current: version, latest: Self.latestSupportedVersion, mandatory: true)
case .orderedSame:
return .outdated(current: version, latest: Self.latestSupportedVersion, mandatory: false)
case .orderedDescending:
return .outdated(current: version, latest: Self.latestSupportedVersion, mandatory: false)
}
case .orderedSame:
return .installed(version)
case .orderedDescending:
return .unsupported(current: version, latest: Self.latestSupportedVersion)
}
}

return .outdated(current: "Unknown", latest: Self.latestSupportedVersion)
return .outdated(current: "Unknown", latest: Self.latestSupportedVersion, mandatory: false)
}

public enum InstallationStep {
Expand Down Expand Up @@ -75,7 +84,7 @@ public struct GitHubCopilotInstallationManager {

public func installLatestVersion() -> AsyncThrowingStream<InstallationStep, Swift.Error> {
AsyncThrowingStream<InstallationStep, Swift.Error> { continuation in
Task {
Task { @GitHubCopilotSuggestionActor in
guard !GitHubCopilotInstallationManager.isInstalling else {
continuation.finish(throwing: Error.isInstalling)
return
Expand Down
2 changes: 1 addition & 1 deletion appcast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<sparkle:shortVersionString>0.33.2</sparkle:shortVersionString>
<sparkle:minimumSystemVersion>12.0</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>https://github.com/intitni/CopilotForXcode/releases/tag/0.33.2</sparkle:releaseNotesLink>
<enclosure url="https://github.com/intitni/CopilotForXcode/releases/download/0.33.2/Copilot.for.Xcode.app.zip" length="50244080" type="application/octet-stream" sparkle:edSignature="w7Viael/iLTwC1qK57siFV2KFEb0SolaXDtNx1KuKVjVNsoKtECIzkbbFfn/xS+B5jLEf52Q8W1ui9V8BXzdDw=="/>
<enclosure url="https://github.com/intitni/CopilotForXcode/releases/download/0.33.2/Copilot.for.Xcode.app.zip" length="50260794" type="application/octet-stream" sparkle:edSignature="l9n9W78mnkHbkUIAl+a9q11f9zvG1EF0UAqnbTnCl5xfoKaZpquA12evzOa6dypM1ra+IyWCM7VJ97uKf+DeAg=="/>
</item>
<item>
<title>0.33.1</title>
Expand Down