Skip to content

Commit f9b673b

Browse files
committed
Update the interface of CodeSuggestion
1 parent 1b57767 commit f9b673b

File tree

10 files changed

+100
-106
lines changed

10 files changed

+100
-106
lines changed

Core/Sources/Service/SuggestionCommandHandler/WindowBaseCommandHandler.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,10 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
214214
}()
215215

216216
let suggestion = CodeSuggestion(
217+
id: UUID().uuidString,
217218
text: promptToCode.code,
218219
position: range.start,
219-
uuid: UUID().uuidString,
220-
range: range,
221-
displayText: promptToCode.code
220+
range: range
222221
)
223222

224223
injector.acceptSuggestion(

Core/Tests/ServiceTests/Environment.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import XPCShared
1111
@testable import Service
1212

1313
func completion(text: String, range: CursorRange, uuid: String = "") -> CodeSuggestion {
14-
.init(text: text, position: range.start, uuid: uuid, range: range, displayText: text)
14+
.init(id: uuid, text: text, position: range.start, range: range)
1515
}
1616

1717
class MockSuggestionService: GitHubCopilotSuggestionServiceType {
@@ -61,11 +61,11 @@ class MockSuggestionService: GitHubCopilotSuggestionServiceType {
6161
}
6262

6363
func notifyAccepted(_ completion: CodeSuggestion) async {
64-
accepted = completion.uuid
64+
accepted = completion.id
6565
}
6666

6767
func notifyRejected(_ completions: [CodeSuggestion]) async {
68-
rejected = completions.map(\.uuid)
68+
rejected = completions.map(\.id)
6969
}
7070
}
7171

Core/Tests/ServiceTests/FilespaceSuggestionInvalidationTests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
1313
.fetchOrCreateWorkspaceAndFilespace(fileURL: URL(fileURLWithPath: "file/path/to.swift"))
1414
filespace.suggestions = [
1515
.init(
16+
id: "",
1617
text: suggestionText,
1718
position: cursorPosition,
18-
uuid: "",
19-
range: .outOfScope,
20-
displayText: ""
19+
range: .outOfScope
2120
),
2221
]
2322
return filespace

Core/Tests/SuggestionInjectorTests/AcceptSuggestionTests.swift

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ final class AcceptSuggestionTests: XCTestCase {
1515
var age: String
1616
"""
1717
let suggestion = CodeSuggestion(
18+
id: "",
1819
text: text,
1920
position: .init(line: 0, character: 1),
20-
uuid: "",
2121
range: .init(
2222
start: .init(line: 1, character: 0),
2323
end: .init(line: 1, character: 0)
24-
),
25-
displayText: ""
24+
)
2625
)
2726
var extraInfo = SuggestionInjector.ExtraInfo()
2827
var lines = content.breakIntoEditorStyleLines()
@@ -62,14 +61,13 @@ final class AcceptSuggestionTests: XCTestCase {
6261
var age: String
6362
"""
6463
let suggestion = CodeSuggestion(
64+
id: "",
6565
text: text,
6666
position: .init(line: 0, character: 12),
67-
uuid: "",
6867
range: .init(
6968
start: .init(line: 0, character: 0),
7069
end: .init(line: 0, character: 12)
71-
),
72-
displayText: ""
70+
)
7371
)
7472

7573
var extraInfo = SuggestionInjector.ExtraInfo()
@@ -106,14 +104,13 @@ final class AcceptSuggestionTests: XCTestCase {
106104
var age: String
107105
"""
108106
let suggestion = CodeSuggestion(
107+
id: "",
109108
text: text,
110109
position: .init(line: 1, character: 12),
111-
uuid: "",
112110
range: .init(
113111
start: .init(line: 1, character: 0),
114112
end: .init(line: 1, character: 12)
115-
),
116-
displayText: ""
113+
)
117114
)
118115

119116
var extraInfo = SuggestionInjector.ExtraInfo()
@@ -150,14 +147,13 @@ final class AcceptSuggestionTests: XCTestCase {
150147
var age: String
151148
"""
152149
let suggestion = CodeSuggestion(
150+
id: "",
153151
text: text,
154152
position: .init(line: 1, character: 12),
155-
uuid: "",
156153
range: .init(
157154
start: .init(line: 1, character: 0),
158155
end: .init(line: 1, character: 12)
159-
),
160-
displayText: ""
156+
)
161157
)
162158

163159
var extraInfo = SuggestionInjector.ExtraInfo()
@@ -191,14 +187,13 @@ final class AcceptSuggestionTests: XCTestCase {
191187
print("Hello World!")
192188
"""
193189
let suggestion = CodeSuggestion(
190+
id: "",
194191
text: text,
195192
position: .init(line: 0, character: 6),
196-
uuid: "",
197193
range: .init(
198194
start: .init(line: 0, character: 0),
199195
end: .init(line: 0, character: 6)
200-
),
201-
displayText: ""
196+
)
202197
)
203198

204199
var extraInfo = SuggestionInjector.ExtraInfo()
@@ -229,14 +224,13 @@ final class AcceptSuggestionTests: XCTestCase {
229224
print("Hello World!
230225
"""
231226
let suggestion = CodeSuggestion(
227+
id: "",
232228
text: text,
233229
position: .init(line: 0, character: 6),
234-
uuid: "",
235230
range: .init(
236231
start: .init(line: 0, character: 0),
237232
end: .init(line: 0, character: 6)
238-
),
239-
displayText: ""
233+
)
240234
)
241235

242236
var extraInfo = SuggestionInjector.ExtraInfo()
@@ -271,14 +265,13 @@ final class AcceptSuggestionTests: XCTestCase {
271265
}
272266
"""
273267
let suggestion = CodeSuggestion(
268+
id: "",
274269
text: text,
275270
position: .init(line: 0, character: 6),
276-
uuid: "",
277271
range: .init(
278272
start: .init(line: 0, character: 0),
279273
end: .init(line: 0, character: 6)
280-
),
281-
displayText: ""
274+
)
282275
)
283276

284277
var extraInfo = SuggestionInjector.ExtraInfo()
@@ -316,14 +309,13 @@ final class AcceptSuggestionTests: XCTestCase {
316309
}
317310
"""
318311
let suggestion = CodeSuggestion(
312+
id: "",
319313
text: text,
320314
position: .init(line: 0, character: 18),
321-
uuid: "",
322315
range: .init(
323316
start: .init(line: 0, character: 0),
324317
end: .init(line: 0, character: 20)
325-
),
326-
displayText: ""
318+
)
327319
)
328320

329321
var extraInfo = SuggestionInjector.ExtraInfo()
@@ -363,14 +355,13 @@ final class AcceptSuggestionTests: XCTestCase {
363355
}
364356
"""
365357
let suggestion = CodeSuggestion(
358+
id: "",
366359
text: text,
367360
position: .init(line: 0, character: 18),
368-
uuid: "",
369361
range: .init(
370362
start: .init(line: 1, character: 0),
371363
end: .init(line: 1, character: 0)
372-
),
373-
displayText: ""
364+
)
374365
)
375366

376367
var extraInfo = SuggestionInjector.ExtraInfo()
@@ -413,14 +404,13 @@ final class AcceptSuggestionTests: XCTestCase {
413404
}
414405
"""
415406
let suggestion = CodeSuggestion(
407+
id: "",
416408
text: text,
417409
position: .init(line: 0, character: 7),
418-
uuid: "",
419410
range: .init(
420411
start: .init(line: 0, character: 0),
421412
end: .init(line: 2, character: 1)
422-
),
423-
displayText: ""
413+
)
424414
)
425415

426416
var extraInfo = SuggestionInjector.ExtraInfo()
@@ -467,14 +457,13 @@ final class AcceptSuggestionTests: XCTestCase {
467457
}
468458
"""
469459
let suggestion = CodeSuggestion(
460+
id: "",
470461
text: text,
471462
position: .init(line: 5, character: 34),
472-
uuid: "",
473463
range: .init(
474464
start: .init(line: 4, character: 7),
475465
end: .init(line: 5, character: 34)
476-
),
477-
displayText: ""
466+
)
478467
)
479468

480469
var extraInfo = SuggestionInjector.ExtraInfo()
@@ -515,14 +504,13 @@ final class AcceptSuggestionTests: XCTestCase {
515504
"""
516505

517506
let suggestion = CodeSuggestion(
507+
id: "",
518508
text: "apiKeyName: azureOpenAIAPIKeyName",
519509
position: .init(line: 0, character: 12),
520-
uuid: "",
521510
range: .init(
522511
start: .init(line: 0, character: 0),
523512
end: .init(line: 0, character: 12)
524-
),
525-
displayText: ""
513+
)
526514
)
527515

528516
var lines = content.breakIntoEditorStyleLines()
@@ -549,14 +537,13 @@ final class AcceptSuggestionTests: XCTestCase {
549537
"""
550538

551539
let suggestion = CodeSuggestion(
540+
id: "",
552541
text: "apiKeyName: azureOpenAIAPIKeyName",
553542
position: .init(line: 0, character: 12),
554-
uuid: "",
555543
range: .init(
556544
start: .init(line: 0, character: 0),
557545
end: .init(line: 0, character: 12)
558-
),
559-
displayText: ""
546+
)
560547
)
561548

562549
var lines = content.breakIntoEditorStyleLines()

Core/Tests/SuggestionInjectorTests/ProposeSuggestionTests.swift

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ final class ProposeSuggestionTests: XCTestCase {
1515
var age: String
1616
"""
1717
let suggestion = CodeSuggestion(
18+
id: "",
1819
text: text,
1920
position: .init(line: 2, character: 19),
20-
uuid: "",
2121
range: .init(
2222
start: .init(line: 1, character: 0),
2323
end: .init(line: 2, character: 18)
24-
),
25-
displayText: ""
24+
)
2625
)
2726
var extraInfo = SuggestionInjector.ExtraInfo()
2827
var lines = content.breakLines()
@@ -62,14 +61,13 @@ final class ProposeSuggestionTests: XCTestCase {
6261
var age: String
6362
"""
6463
let suggestion = CodeSuggestion(
64+
id: "",
6565
text: text,
6666
position: .init(line: 1, character: 0),
67-
uuid: "",
6867
range: .init(
6968
start: .init(line: 1, character: 0),
7069
end: .init(line: 2, character: 18)
71-
),
72-
displayText: ""
70+
)
7371
)
7472
var extraInfo = SuggestionInjector.ExtraInfo()
7573
var lines = content.breakLines()
@@ -105,14 +103,13 @@ final class ProposeSuggestionTests: XCTestCase {
105103
var age: String
106104
"""
107105
let suggestion = CodeSuggestion(
106+
id: "",
108107
text: text,
109108
position: .init(line: 1, character: 0),
110-
uuid: "",
111109
range: .init(
112110
start: .init(line: 1, character: 0),
113111
end: .init(line: 2, character: 18)
114-
),
115-
displayText: ""
112+
)
116113
)
117114
var extraInfo = SuggestionInjector.ExtraInfo()
118115
var lines = content.breakLines()
@@ -149,14 +146,13 @@ final class ProposeSuggestionTests: XCTestCase {
149146
var age: String
150147
"""
151148
let suggestion = CodeSuggestion(
149+
id: "",
152150
text: text,
153151
position: .init(line: 1, character: 0),
154-
uuid: "",
155152
range: .init(
156153
start: .init(line: 1, character: 0),
157154
end: .init(line: 2, character: 18)
158-
),
159-
displayText: ""
155+
)
160156
)
161157
var extraInfo = SuggestionInjector.ExtraInfo()
162158
var lines = content.breakLines()
@@ -197,14 +193,13 @@ final class ProposeSuggestionTests: XCTestCase {
197193
print(array)
198194
"""
199195
let suggestion = CodeSuggestion(
196+
id: "",
200197
text: text,
201198
position: .init(line: 1, character: 0),
202-
uuid: "",
203199
range: .init(
204200
start: .init(line: 1, character: 0),
205201
end: .init(line: 2, character: 18)
206-
),
207-
displayText: ""
202+
)
208203
)
209204
var extraInfo = SuggestionInjector.ExtraInfo()
210205
var lines = content.breakLines()
@@ -247,14 +242,13 @@ final class ProposeSuggestionTests: XCTestCase {
247242
}
248243
"""
249244
let suggestion = CodeSuggestion(
245+
id: "",
250246
text: text,
251247
position: .init(line: 0, character: 0),
252-
uuid: "",
253248
range: .init(
254249
start: .init(line: 0, character: 0),
255250
end: .init(line: 5, character: 15)
256-
),
257-
displayText: ""
251+
)
258252
)
259253
var extraInfo = SuggestionInjector.ExtraInfo()
260254
var lines = content.breakLines()
@@ -294,14 +288,13 @@ final class ProposeSuggestionTests: XCTestCase {
294288
"""
295289
let text = "} else {\n"
296290
let suggestion = CodeSuggestion(
291+
id: "",
297292
text: text,
298293
position: .init(line: 2, character: 0),
299-
uuid: "",
300294
range: .init(
301295
start: .init(line: 2, character: 0),
302296
end: .init(line: 2, character: 8)
303-
),
304-
displayText: ""
297+
)
305298
)
306299
var extraInfo = SuggestionInjector.ExtraInfo()
307300
var lines = content.breakLines()

0 commit comments

Comments
 (0)