Skip to content

Commit abc9a87

Browse files
committed
Implement basic structure of suggestion cheatsheet
1 parent f07f5e6 commit abc9a87

File tree

4 files changed

+82
-74
lines changed

4 files changed

+82
-74
lines changed

Core/Package.swift

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,57 @@
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
5+
import Foundation
6+
7+
// MARK: - Pro
8+
9+
extension [Target.Dependency] {
10+
func pro(_ targetNames: [String]) -> [Target.Dependency] {
11+
if isProIncluded {
12+
// include the pro package
13+
return self + targetNames.map { Target.Dependency.product(name: $0, package: "Pro") }
14+
}
15+
return self
16+
}
17+
}
18+
19+
extension [Package.Dependency] {
20+
var pro: [Package.Dependency] {
21+
if isProIncluded {
22+
// include the pro package
23+
return self + [.package(path: "../Pro/Pro")]
24+
}
25+
return self
26+
}
27+
}
28+
29+
let isProIncluded: Bool = {
30+
func isProIncluded(file: StaticString = #file) -> Bool {
31+
let filePath = "\(file)"
32+
let fileURL = URL(fileURLWithPath: filePath)
33+
let rootURL = fileURL
34+
.deletingLastPathComponent()
35+
.deletingLastPathComponent()
36+
let confURL = rootURL.appendingPathComponent("PLUS")
37+
if !FileManager.default.fileExists(atPath: confURL.path) {
38+
return false
39+
}
40+
do {
41+
let content = String(
42+
data: try Data(contentsOf: confURL),
43+
encoding: .utf8
44+
)
45+
print("")
46+
return content?.hasPrefix("YES") ?? false
47+
} catch {
48+
return false
49+
}
50+
}
51+
52+
return isProIncluded()
53+
}()
54+
55+
// MARK: - Package
556

657
let package = Package(
758
name: "Core",
@@ -322,52 +373,3 @@ let package = Package(
322373
]
323374
)
324375

325-
// MARK: - Pro
326-
327-
extension [Target.Dependency] {
328-
func pro(_ targetNames: [String]) -> [Target.Dependency] {
329-
if isProIncluded {
330-
// include the pro package
331-
return self + targetNames.map { Target.Dependency.product(name: $0, package: "Pro") }
332-
}
333-
return self
334-
}
335-
}
336-
337-
extension [Package.Dependency] {
338-
var pro: [Package.Dependency] {
339-
if isProIncluded {
340-
// include the pro package
341-
return self + [.package(path: "../Pro/Pro")]
342-
}
343-
return self
344-
}
345-
}
346-
347-
import Foundation
348-
349-
let isProIncluded: Bool = {
350-
func isProIncluded(file: StaticString = #file) -> Bool {
351-
let filePath = "\(file)"
352-
let fileURL = URL(fileURLWithPath: filePath)
353-
let rootURL = fileURL
354-
.deletingLastPathComponent()
355-
.deletingLastPathComponent()
356-
let confURL = rootURL.appendingPathComponent("PLUS")
357-
if !FileManager.default.fileExists(atPath: confURL.path) {
358-
return false
359-
}
360-
do {
361-
let content = String(
362-
data: try Data(contentsOf: confURL),
363-
encoding: .utf8
364-
)
365-
print("")
366-
return content?.hasPrefix("YES") ?? false
367-
} catch {
368-
return false
369-
}
370-
}
371-
372-
return isProIncluded()
373-
}()

Core/Sources/Service/RealtimeSuggestionController.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,23 @@ public actor RealtimeSuggestionController {
2121
private var sourceEditor: SourceEditor?
2222

2323
init() {}
24+
25+
deinit {
26+
task?.cancel()
27+
inflightPrefetchTask?.cancel()
28+
windowChangeObservationTask?.cancel()
29+
activeApplicationMonitorTask?.cancel()
30+
editorObservationTask?.cancel()
31+
}
2432

2533
nonisolated
2634
func start() {
27-
Task { [weak self] in
35+
Task { await observeXcodeChange() }
36+
}
37+
38+
private func observeXcodeChange() {
39+
task?.cancel()
40+
task = Task { [weak self] in
2841
if ActiveApplicationMonitor.shared.activeXcode != nil {
2942
await self?.handleXcodeChanged()
3043
}

Core/Sources/Service/Service.swift

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import Foundation
33
import Workspace
44
import WorkspaceSuggestionService
55

6-
#if canImport(KeyBindingManager)
7-
import EnhancedWorkspace
8-
import KeyBindingManager
6+
#if canImport(ProService)
7+
import ProService
98
#endif
109

1110
@globalActor public enum ServiceActor {
@@ -23,42 +22,36 @@ public final class Service {
2322
public let guiController = GraphicalUserInterfaceController()
2423
public let realtimeSuggestionController = RealtimeSuggestionController()
2524
public let scheduledCleaner: ScheduledCleaner
26-
#if canImport(KeyBindingManager)
27-
let keyBindingManager: KeyBindingManager
25+
26+
#if canImport(ProService)
27+
let proService: ProService
2828
#endif
2929

3030
private init() {
3131
@Dependency(\.workspacePool) var workspacePool
3232

3333
scheduledCleaner = .init(workspacePool: workspacePool, guiController: guiController)
34-
#if canImport(KeyBindingManager)
35-
keyBindingManager = .init(
36-
workspacePool: workspacePool,
37-
acceptSuggestion: {
38-
Task {
39-
await PseudoCommandHandler().acceptSuggestion()
40-
}
41-
}
42-
)
43-
#endif
44-
4534
workspacePool.registerPlugin { SuggestionServiceWorkspacePlugin(workspace: $0) }
46-
#if canImport(EnhancedWorkspace)
47-
if !UserDefaults.shared.value(for: \.disableEnhancedWorkspace) {
48-
workspacePool.registerPlugin { EnhancedWorkspacePlugin(workspace: $0) }
35+
self.workspacePool = workspacePool
36+
37+
#if canImport(ProService)
38+
proService = withDependencies { dependencyValues in
39+
dependencyValues.proServiceAcceptSuggestion = {
40+
Task { await PseudoCommandHandler().acceptSuggestion() }
41+
}
42+
} operation: {
43+
ProService()
4944
}
5045
#endif
51-
52-
self.workspacePool = workspacePool
5346
}
5447

5548
@MainActor
5649
public func start() {
5750
scheduledCleaner.start()
5851
realtimeSuggestionController.start()
5952
guiController.start()
60-
#if canImport(KeyBindingManager)
61-
keyBindingManager.start()
53+
#if canImport(ProService)
54+
proService.start()
6255
#endif
6356
DependencyUpdater().update()
6457
}

Pro

Submodule Pro updated from 8bb1ad6 to 71f5088

0 commit comments

Comments
 (0)