Skip to content

Commit 5d92706

Browse files
committed
Merge tag '0.5.0' into develop
2 parents 9288320 + cc577c3 commit 5d92706

7 files changed

Lines changed: 59 additions & 32 deletions

File tree

Copilot for Xcode.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@
493493
CODE_SIGN_ENTITLEMENTS = EditorExtension/EditorExtension.entitlements;
494494
CODE_SIGN_STYLE = Automatic;
495495
COMBINE_HIDPI_IMAGES = YES;
496-
CURRENT_PROJECT_VERSION = 1;
496+
CURRENT_PROJECT_VERSION = "$(APP_BUILD)";
497497
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
498498
ENABLE_HARDENED_RUNTIME = YES;
499499
INFOPLIST_FILE = EditorExtension/Info.plist;
@@ -505,7 +505,7 @@
505505
"@executable_path/../../../../Frameworks",
506506
);
507507
MACOSX_DEPLOYMENT_TARGET = 12.0;
508-
MARKETING_VERSION = 1.0;
508+
MARKETING_VERSION = "$(APP_VERSION)";
509509
PRODUCT_BUNDLE_IDENTIFIER = "$(BUNDLE_IDENTIFIER_BASE).EditorExtension";
510510
PRODUCT_NAME = Copilot;
511511
SKIP_INSTALL = YES;
@@ -520,7 +520,7 @@
520520
CODE_SIGN_ENTITLEMENTS = EditorExtension/EditorExtension.entitlements;
521521
CODE_SIGN_STYLE = Automatic;
522522
COMBINE_HIDPI_IMAGES = YES;
523-
CURRENT_PROJECT_VERSION = 1;
523+
CURRENT_PROJECT_VERSION = "$(APP_BUILD)";
524524
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
525525
ENABLE_HARDENED_RUNTIME = YES;
526526
INFOPLIST_FILE = EditorExtension/Info.plist;
@@ -532,7 +532,7 @@
532532
"@executable_path/../../../../Frameworks",
533533
);
534534
MACOSX_DEPLOYMENT_TARGET = 12.0;
535-
MARKETING_VERSION = 1.0;
535+
MARKETING_VERSION = "$(APP_VERSION)";
536536
PRODUCT_BUNDLE_IDENTIFIER = "$(BUNDLE_IDENTIFIER_BASE).EditorExtension";
537537
PRODUCT_NAME = Copilot;
538538
SKIP_INSTALL = YES;
@@ -703,7 +703,7 @@
703703
CODE_SIGN_ENTITLEMENTS = "Copilot for Xcode/Copilot_for_Xcode.entitlements";
704704
CODE_SIGN_STYLE = Automatic;
705705
COMBINE_HIDPI_IMAGES = YES;
706-
CURRENT_PROJECT_VERSION = 13;
706+
CURRENT_PROJECT_VERSION = "$(APP_BUILD)";
707707
DEVELOPMENT_ASSET_PATHS = "\"Copilot for Xcode/Preview Content\"";
708708
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
709709
ENABLE_HARDENED_RUNTIME = YES;
@@ -717,7 +717,7 @@
717717
"@executable_path/../Frameworks",
718718
);
719719
MACOSX_DEPLOYMENT_TARGET = 12.0;
720-
MARKETING_VERSION = 0.4.0;
720+
MARKETING_VERSION = "$(APP_VERSION)";
721721
PRODUCT_BUNDLE_IDENTIFIER = "$(BUNDLE_IDENTIFIER_BASE)";
722722
PRODUCT_MODULE_NAME = Copilot_for_Xcode;
723723
PRODUCT_NAME = "Copilot for Xcode Dev";
@@ -735,7 +735,7 @@
735735
CODE_SIGN_ENTITLEMENTS = "Copilot for Xcode/Copilot_for_Xcode.entitlements";
736736
CODE_SIGN_STYLE = Automatic;
737737
COMBINE_HIDPI_IMAGES = YES;
738-
CURRENT_PROJECT_VERSION = 13;
738+
CURRENT_PROJECT_VERSION = "$(APP_BUILD)";
739739
DEVELOPMENT_ASSET_PATHS = "\"Copilot for Xcode/Preview Content\"";
740740
DEVELOPMENT_TEAM = 5YKZ4Y3DAW;
741741
ENABLE_HARDENED_RUNTIME = YES;
@@ -749,7 +749,7 @@
749749
"@executable_path/../Frameworks",
750750
);
751751
MACOSX_DEPLOYMENT_TARGET = 12.0;
752-
MARKETING_VERSION = 0.4.0;
752+
MARKETING_VERSION = "$(APP_VERSION)";
753753
PRODUCT_BUNDLE_IDENTIFIER = "$(BUNDLE_IDENTIFIER_BASE)";
754754
PRODUCT_NAME = "Copilot for Xcode";
755755
SWIFT_EMIT_LOC_STRINGS = YES;

Core/Sources/Service/AutoTrigger.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public actor AutoTrigger {
6464
if task == nil {
6565
task = Task { [stream = eventObserver.stream] in
6666
var triggerTask: Task<Void, Error>?
67-
for await _ in stream {
67+
for await eventType in stream {
6868
triggerTask?.cancel()
6969
if Task.isCancelled { break }
7070
guard await Environment.isXcodeActive() else { continue }
@@ -77,16 +77,17 @@ public actor AutoTrigger {
7777
}
7878
}
7979

80+
guard eventType == .keyUp else { continue }
81+
8082
triggerTask = Task { @ServiceActor in
81-
try? await Task.sleep(nanoseconds: 2_000_000_000)
83+
try? await Task.sleep(nanoseconds: 1_500_000_000)
8284
if Task.isCancelled { return }
8385
let fileURL = try? await Environment.fetchCurrentFileURL()
84-
guard let folderURL = try? await Environment
85-
.fetchCurrentProjectRootURL(fileURL)
86-
else { return }
87-
let workspace = workspaces[folderURL] ??
88-
Workspace(projectRootURL: folderURL)
89-
workspaces[folderURL] = workspace
86+
let folderURL = try? await Environment.fetchCurrentProjectRootURL(fileURL)
87+
guard let workspaceURL = folderURL ?? fileURL else { return }
88+
let workspace = workspaces[workspaceURL]
89+
?? Workspace(projectRootURL: workspaceURL)
90+
workspaces[workspaceURL] = workspace
9091
guard workspace.isRealtimeSuggestionEnabled else { return }
9192
if Task.isCancelled { return }
9293
try? await Environment.triggerAction("Prefetch Suggestions")

Core/Sources/Service/CGEventObserver.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@ public protocol CGEventObserverType {
66
@discardableResult
77
func activateIfPossible() -> Bool
88
func deactivate()
9-
var stream: AsyncStream<Void> { get }
9+
var stream: AsyncStream<CGEventType> { get }
1010
var isEnabled: Bool { get }
1111
}
1212

1313
final class CGEventObserver: CGEventObserverType {
14-
let stream: AsyncStream<Void>
14+
let stream: AsyncStream<CGEventType>
1515
var isEnabled: Bool { port != nil }
1616

17-
private var continuation: AsyncStream<Void>.Continuation
17+
private var continuation: AsyncStream<CGEventType>.Continuation
1818
private var port: CFMachPort?
19-
private let eventsOfInterest: Set<CGEventType> = [.keyUp]
19+
private let eventsOfInterest: Set<CGEventType> = [
20+
.keyUp,
21+
.keyDown,
22+
.rightMouseDown,
23+
.leftMouseDown,
24+
]
2025
private let tapLocation: CGEventTapLocation = .cghidEventTap
2126
private let tapPlacement: CGEventTapPlacement = .tailAppendEventTap
2227
private let tapOptions: CGEventTapOptions = .listenOnly
@@ -28,7 +33,7 @@ final class CGEventObserver: CGEventObserverType {
2833
}
2934

3035
init() {
31-
var continuation: AsyncStream<Void>.Continuation!
36+
var continuation: AsyncStream<CGEventType>.Continuation!
3237
stream = AsyncStream { c in
3338
continuation = c
3439
}
@@ -66,9 +71,9 @@ final class CGEventObserver: CGEventObserverType {
6671
}
6772

6873
if let continuation = continuationPointer?
69-
.assumingMemoryBound(to: AsyncStream<Void>.Continuation.self)
74+
.assumingMemoryBound(to: AsyncStream<CGEventType>.Continuation.self)
7075
{
71-
continuation.pointee.yield(())
76+
continuation.pointee.yield(eventType)
7277
}
7378

7479
return .passRetained(event)

DEVELOPMENT.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ Testing Real-time Suggestions is a little bit different because the Apple Script
3434

3535
Just run both the XPCService and the EditorExtension Target.
3636

37+
## Code Style
38+
39+
We use SwiftFormat to format the code.
40+
41+
The source code mostly follows the [Ray Wenderlich Style Guide](https://github.com/raywenderlich/swift-style-guide) very closely with the following exception:
42+
43+
- Use the Xcode default of 4 spaces for indentation.
44+
3745
## App Versioning
3846

3947
The app version and all targets' version in controlled by `Version.xcconfig`.

EditorExtension/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleShortVersionString</key>
6-
<string>$(APP_VERSION)</string>
6+
<string>$(MARKETING_VERSION)</string>
77
<key>NSHumanReadableCopyright</key>
88
<string></string>
99
<key>CFBundleDevelopmentRegion</key>
@@ -15,7 +15,7 @@
1515
<key>CFBundleExecutable</key>
1616
<string>$(EXECUTABLE_NAME)</string>
1717
<key>CFBundleVersion</key>
18-
<string>$(APP_BUILD)</string>
18+
<string>$(CURRENT_PROJECT_VERSION)</string>
1919
<key>CFBundleInfoDictionaryVersion</key>
2020
<string>6.0</string>
2121
<key>CFBundleIdentifier</key>

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,28 @@ Thanks to [LSP-copilot](https://github.com/TerminalFi/LSP-copilot) for showing t
2020

2121
## Installation and Setup
2222

23-
1. Download the Copilot for Xcode.app from the latest release, and extract it to the Applications folder.
23+
### Install
24+
25+
1. Download the Copilot for Xcode.app from the latest [release](https://github.com/intitni/CopilotForXcode/releases), and extract it to the Applications folder.
2426
2. Open the app, and click "Set Up Launch Agents" to set up a background running XPC Service that does the real job.
25-
3. Refresh the Copilot status, if it fails, quit and restart the app.
26-
4. Sign in. You will be directed to a verification website provided by GitHub, and a user code will be pasted into your clipboard.
27-
5. After signing in, go back to the app and click "Confirm Sign-in" to finish.
28-
5. Enable the extension in the Settings.app, then maybe restart Xcode.
27+
3. Enable the extension in the Settings.app, then maybe restart Xcode.
28+
29+
### Sign In Github Copilot
30+
31+
1. In the app, refresh the Copilot status, if it fails, quit and restart the app.
32+
2. Click "Sign In", you will be directed to a verification website provided by GitHub, and a user code will be pasted into your clipboard.
33+
3. After signing in, go back to the app and click "Confirm Sign-in" to finish.
2934

3035
The first time the commands run, the extension will ask for 2 types of permissions:
3136
1. Accessibility API: which the extension uses to get the editing file path.
3237
2. Folder Access: the extension needs, to run some Apple Scripts to get the project/workspace path.
3338

39+
## Update
40+
41+
You can manually download the latest release. After updating the app, don't forget to click `Restart XPC Service` in the app to kill the old version and run the new version.
42+
43+
If you want to keep track of the new releases, you can watch this repo's releases to get notifications on updates.
44+
3445
## Commands
3546

3647
- Get Suggestions: Get suggestions for the editing file at the current cursor position.
@@ -91,6 +102,8 @@ fi
91102
**Q: I turned on real-time suggestions, but nothing happens**
92103

93104
> A: Check the list in `Settings.app > Privacy & Security > Input Monitoring`. Turn the toggle on for `Copilot for Xcode`. If it's not on the list, add it manually. After that, you may have to restart the XPC Service.
105+
>
106+
> If that doesn't help, try to restart the XPC Service again.
94107
95108
**Q: Will it work in future Xcode updates?**
96109

Version.xcconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
APP_VERSION = 0.4.0
2-
APP_BUILD = 13
1+
APP_VERSION = 0.5.0
2+
APP_BUILD = 18

0 commit comments

Comments
 (0)