Skip to content

Commit

Permalink
Pre-release 0.27.93
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 4, 2024
1 parent 3404070 commit 887f789
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 29 deletions.
29 changes: 27 additions & 2 deletions Core/Sources/HostApp/AdvancedSettings/EnterpriseSection.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
import Combine
import SwiftUI
import Toast

struct EnterpriseSection: View {
@AppStorage(\.gitHubCopilotEnterpriseURI) var gitHubCopilotEnterpriseURI
@Environment(\.toast) var toast

var body: some View {
SettingsSection(title: "Enterprise") {
SettingsTextField(
title: "Auth provider URL",
prompt: "Leave it blank if none is available.",
text: $gitHubCopilotEnterpriseURI
prompt: "https://your-enterprise.ghe.com",
text: DebouncedBinding($gitHubCopilotEnterpriseURI, handler: urlChanged).binding
)
}
}

func urlChanged(_ url: String) {
if !url.isEmpty {
validateAuthURL(url)
}
NotificationCenter.default.post(
name: .gitHubCopilotShouldRefreshEditorInformation,
object: nil
)
}

func validateAuthURL(_ url: String) {
let maybeURL = URL(string: url)
guard let parsedURl = maybeURL else {
toast("Invalid URL", .error)
return
}
if parsedURl.scheme != "https" {
toast("URL scheme must be https://", .error)
return
}
}
}

#Preview {
Expand Down
21 changes: 9 additions & 12 deletions Core/Sources/HostApp/AdvancedSettings/ProxySection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,30 @@ struct ProxySection: View {
SettingsTextField(
title: "Proxy URL",
prompt: "http://host:port",
text: $gitHubCopilotProxyUrl
text: wrapBinding($gitHubCopilotProxyUrl)
)
SettingsTextField(
title: "Proxy username",
prompt: "username",
text: $gitHubCopilotProxyUsername
text: wrapBinding($gitHubCopilotProxyUsername)
)
SettingsSecureField(
title: "Proxy password",
prompt: "password",
text: $gitHubCopilotProxyPassword
text: wrapBinding($gitHubCopilotProxyPassword)
)
SettingsToggle(
title: "Proxy strict SSL",
isOn: $gitHubCopilotUseStrictSSL
isOn: wrapBinding($gitHubCopilotUseStrictSSL)
)
} footer: {
HStack {
Spacer()
Button("Refresh configurations") {
refreshConfiguration()
}
}
}
}

func refreshConfiguration() {
private func wrapBinding<T>(_ b: Binding<T>) -> Binding<T> {
DebouncedBinding(b, handler: refreshConfiguration).binding
}

func refreshConfiguration(_: Any) {
NotificationCenter.default.post(
name: .gitHubCopilotShouldRefreshEditorInformation,
object: nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ struct CopilotConnectionView: View {
@Environment(\.toast) var toast
@StateObject var viewModel = GitHubCopilotViewModel()

@State var waitingForSignIn = false
let store: StoreOf<General>

var body: some View {
Expand All @@ -24,13 +23,13 @@ struct CopilotConnectionView: View {
title: "GitHub Account Status Permissions",
subtitle: "GitHub Connection: \(viewModel.status?.description ?? "Loading...")"
) {
if viewModel.isRunningAction || waitingForSignIn {
if viewModel.isRunningAction || viewModel.waitingForSignIn {
ProgressView().controlSize(.small)
}
Button("Refresh Connection") {
viewModel.checkStatus()
}
if waitingForSignIn {
if viewModel.waitingForSignIn {
Button("Cancel") {
viewModel.cancelWaiting()
}
Expand Down
25 changes: 25 additions & 0 deletions Core/Sources/HostApp/SharedComponents/DebouncedBinding.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Combine
import SwiftUI

class DebouncedBinding<T> {
private let subject = PassthroughSubject<T, Never>()
private let cancellable: AnyCancellable
private let wrappedBinding: Binding<T>

init(_ binding: Binding<T>, handler: @escaping (T) -> Void) {
self.wrappedBinding = binding
self.cancellable = subject
.debounce(for: .seconds(1.0), scheduler: RunLoop.main)
.sink { handler($0) }
}

var binding: Binding<T> {
return Binding(
get: { self.wrappedBinding.wrappedValue },
set: {
self.wrappedBinding.wrappedValue = $0
self.subject.send($0)
}
)
}
}
4 changes: 4 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ Requires Node installed and `npm` available on your system path, e.g.

```sh
sudo ln -s `which npm` /usr/local/bin
sudo ln -s `which node` /usr/local/bin
```

For context, this is used by an Xcode run script as part of the build. Run
scripts use a very limited path to resolve commands.

## Targets

### Copilot for Xcode
Expand Down
4 changes: 2 additions & 2 deletions ExtensionService/AuthStatusChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class AuthStatusChecker {
Task {
do {
let status = try await self.getCurrentAuthStatus()
DispatchQueue.main.async {
Task { @MainActor in
notify(status.description, status == .ok)
}
} catch {
DispatchQueue.main.async {
Task { @MainActor in
notify("\(error)", false)
}
}
Expand Down
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ Use of the GitHub Copilot Xcode Extension is subject to [GitHub's Pre-Release Te
<img alt="Screenshot of downloaded from the internet warning" src="./Docs/downloaded-from-internet.png" width="372" />
</p>

1. A background item will be added for the application to be able to start itself when Xcode starts.
1. A background item will be added to enable Copilot to start when Xcode is opened.
<p align="center">
<img alt="Screenshot of background item" src="./Docs/background-item.png" width="370" />
</p>

1. Two permissions are required: `Accessibility` and `Xcode Source Editor Extension`.
1. Two permissions are required: `Accessibility` and `Xcode Source Editor
Extension`. For more on why these permissions are required see
[TROUBLESHOOTING.md](./TROUBLESHOOTING.md).

The first time the application is run the `Accessibility` permission should be requested:

Expand All @@ -57,7 +59,9 @@ Use of the GitHub Copilot Xcode Extension is subject to [GitHub's Pre-Release Te
<img alt="Screenshot of extension permission" src="./Docs/extension-permission.png" width="582" />
</p>

1. After granting the extension permission, please restart Xcode so the `Github Copilot` menu is available under the Xcode `Editor` menu.
1. After granting the extension permission, please restart Xcode to ensure the
`Github Copilot` menu is available and not disabled under the Xcode `Editor`
menu.
<br>
<p align="center">
<img alt="Screenshot of Xcode Editor GitHub Copilot menu item" src="./Docs/xcode-menu.png" width="648" />
Expand All @@ -71,7 +75,16 @@ Use of the GitHub Copilot Xcode Extension is subject to [GitHub's Pre-Release Te
<img alt="Screenshot of sign-in popup" src="./Docs/device-code.png" width="372" />
</p>

1. To install updates, click `Check for Updates` from the menu item or in the settings application. After installing a new version, Xcode must be restarted to use the new version correctly. New versions can also be installed from `dmg` files downloaded from the releases page. When installing a new version via `dmg`, the application must be run manually the first time to accept the downloaded from the internet warning.
1. To install updates, click `Check for Updates` from the menu item or in the
settings application.

After installing a new version, Xcode must be restarted to use the new
version correctly.

New versions can also be installed from `dmg` files downloaded from the
releases page. When installing a new version via `dmg`, the application must
be run manually the first time to accept the downloaded from the internet
warning.

1. To avoid confusion, we recommend disabling `Predictive code completion` under
`Xcode` > `Preferences` > `Text Editing` > `Editing`.
Expand Down
32 changes: 29 additions & 3 deletions TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ common issues:
then Xcode needs to be restarted to enable the extension.

3. Need more help? If these steps don't resolve the issue, please [open an
issue](https://github.com/github/CopilotForXcode/issues/new/choose).
issue](https://github.com/github/CopilotForXcode/issues/new/choose). Make
sure to [include logs](#logs) and any other relevant information.

## Extension Permission

Expand All @@ -34,8 +35,33 @@ Or you can navigate to the permission manually depending on your OS version:

## Accessibility Permission

GitHub Copilot for Xcode requires accessibility permission to receive
information from the active Xcode editor.
GitHub Copilot for Xcode requires the accessibility permission to receive
real-time updates from the active Xcode editor. [The XcodeKit
API](https://developer.apple.com/documentation/xcodekit)
enabled by the Xcode Source Editor extension permission only provides
information when manually triggered by the user. In order to generate
suggestions as you type, the accessibility permission is used read the
Xcode editor content in real-time.

The accessibility permission is also used to accept suggestions when `tab` is
pressed.

The accessibility permission is __not__ used to read or write to any
applications besides Xcode. There are no granular options for the permission,
but you can audit the usage in this repository: search for `CGEvent` and `AX`*.

Enable in System Settings under `Privacy & Security` > `Accessibility` >
`GitHub Copilot for Xcode Extension` and turn on the toggle.

## Logs

Logs can be found in `~/Library/Logs/GitHubCopilot/` the most recent log file
is:

```
~/Library/Logs/GitHubCopilot/github-copilot-for-xcode.log
```

To enable verbose logging, open the GitHub Copilot for Xcode settings and enable
`Verbose Logging` in the `Advanced` tab. After enabling verbose logging, restart
Copilot for Xcode for the change to take effect.
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ public func editorConfiguration() -> JSONValue {
d["proxyAuthorization"] = .string(proxyAuthorization)
}
d["proxyStrictSSL"] = .bool(UserDefaults.shared.value(for: \.gitHubCopilotUseStrictSSL))
if d.isEmpty { return nil }
return .hash(d)
}

var authProvider: JSONValue? {
let enterpriseURI = UserDefaults.shared.value(for: \.gitHubCopilotEnterpriseURI)
if enterpriseURI.isEmpty { return nil }
return .hash([ "uri": .string(enterpriseURI) ])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public final class GitHubCopilotService: GitHubCopilotBaseService,
tabSize: tabSize,
insertSpaces: !usesTabsForIndentation
),
context: .init(triggerKind: .automatic)
context: .init(triggerKind: .invoked)
)))
.items
.compactMap { (item: _) -> CodeSuggestion? in
Expand Down

0 comments on commit 887f789

Please sign in to comment.