forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModels.swift
More file actions
77 lines (69 loc) · 2.32 KB
/
Models.swift
File metadata and controls
77 lines (69 loc) · 2.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import Foundation
import SuggestionBasic
public struct EditorContent: Codable {
public struct Selection: Codable {
public var start: CursorPosition
public var end: CursorPosition
public init(start: CursorPosition, end: CursorPosition) {
self.start = start
self.end = end
}
}
public init(
content: String,
lines: [String],
uti: String,
cursorPosition: CursorPosition,
cursorOffset: Int,
selections: [Selection],
tabSize: Int,
indentSize: Int,
usesTabsForIndentation: Bool,
suggesionLineLimit: Int? = nil
) {
self.content = content
self.lines = lines
self.uti = uti
self.cursorPosition = cursorPosition
self.cursorOffset = cursorOffset
self.selections = selections
self.tabSize = tabSize
self.indentSize = indentSize
self.usesTabsForIndentation = usesTabsForIndentation
self.suggesionLineLimit = suggesionLineLimit
}
public var content: String
/// Every line has a trailing newline character.
public var lines: [String]
public var uti: String
public var cursorPosition: CursorPosition
public var cursorOffset: Int
public var selections: [Selection]
public var tabSize: Int
public var indentSize: Int
public var usesTabsForIndentation: Bool
public var suggesionLineLimit: Int?
public func selectedCode(in selection: Selection) -> String {
return XPCShared.selectedCode(in: selection, for: lines)
}
}
public struct UpdatedContent: Codable {
public init(content: String, newSelection: CursorRange? = nil, modifications: [Modification]) {
self.content = content
self.newSelection = newSelection
self.modifications = modifications
}
public var content: String
public var newSelection: CursorRange?
public var modifications: [Modification]
}
func selectedCode(in selection: EditorContent.Selection, for lines: [String]) -> String {
return EditorInformation.code(
in: lines,
inside: .init(
start: .init(line: selection.start.line, character: selection.start.character),
end: .init(line: selection.end.line, character: selection.end.character)
),
ignoreColumns: false
).code
}