forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceEditorExtension.swift
More file actions
45 lines (39 loc) · 1.32 KB
/
SourceEditorExtension.swift
File metadata and controls
45 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Foundation
import XcodeKit
class SourceEditorExtension: NSObject, XCSourceEditorExtension {
var commandDefinitions: [[XCSourceEditorCommandDefinitionKey: Any]] {
[
GetSuggestionsCommand(),
AcceptSuggestionCommand(),
RejectSuggestionCommand(),
NextSuggestionCommand(),
PreviousSuggestionCommand(),
TurnOnRealtimeSuggestionsCommand(),
TurnOffRealtimeSuggestionsCommand(),
RealtimeSuggestionsCommand(),
PrefetchSuggestionsCommand(),
].map(makeCommandDefinition)
}
}
private let identifierPrefix: String = Bundle.main.bundleIdentifier ?? ""
protocol CommandType: AnyObject {
var commandClassName: String { get }
var identifier: String { get }
var name: String { get }
}
extension CommandType where Self: NSObject {
var commandClassName: String { Self.className() }
var identifier: String { commandClassName }
}
extension CommandType {
func makeCommandDefinition() -> [XCSourceEditorCommandDefinitionKey: Any] {
[.classNameKey: commandClassName,
.identifierKey: identifierPrefix + identifier,
.nameKey: name]
}
}
func makeCommandDefinition(_ commandType: CommandType)
-> [XCSourceEditorCommandDefinitionKey: Any]
{
commandType.makeCommandDefinition()
}