Skip to content

Commit 359dc7d

Browse files
committed
Fix tests
1 parent f9f19c1 commit 359dc7d

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

Tool/Sources/WorkspaceSuggestionService/Filespace+SuggestionService.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ extension Filespace {
104104
) -> Bool {
105105
// cursor is not even moved during the generation.
106106
if alwaysTrueIfCursorNotMoved, cursorPosition == suggestion.position { return true }
107-
107+
108108
// cursor has moved to another line
109109
if cursorPosition.line != suggestion.position.line { return false }
110110

@@ -219,6 +219,23 @@ extension Filespace {
219219
completion: pseudoSuggestion,
220220
extraInfo: &extraInfo
221221
)
222+
223+
// We want that finish typing a partial suggestion should also make no difference.
224+
if let lastOriginalLine = originalEditingLines.last,
225+
cursorPosition.character < lastOriginalLine.utf16.count,
226+
// But we also want to separate this case from the case that the suggestion is
227+
// shortening the last line. Which does make a difference.
228+
suggestion.range.end.character < lastOriginalLine.utf16.count - 1 // for line ending
229+
{
230+
let editingLinesPrefix = editingLines.dropLast()
231+
let originalEditingLinesPrefix = originalEditingLines.dropLast()
232+
if editingLinesPrefix != originalEditingLinesPrefix {
233+
return false
234+
}
235+
let lastEditingLine = editingLines.last ?? "\n"
236+
return lastOriginalLine.hasPrefix(lastEditingLine.dropLast(1)) // for line ending
237+
}
238+
222239
return editingLines == originalEditingLines
223240
}
224241
}

Tool/Tests/SuggestionProviderTests/PostProcessingSuggestionServiceMiddlewareTests.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ class PostProcessingSuggestionServiceMiddlewareTests: XCTestCase {
241241
id: "1",
242242
text: "hello world",
243243
position: .init(line: 0, character: 1),
244-
range: .init(startPair: (0, 0), endPair: (0, 1))
244+
range: .init(startPair: (0, 0), endPair: (0, 1)),
245+
middlewareComments: ["Removed redundant closing parenthesis."]
245246
),
246247
])
247248
}
@@ -275,7 +276,8 @@ class PostProcessingSuggestionServiceMiddlewareTests: XCTestCase {
275276
id: "1",
276277
text: "",
277278
position: .init(line: 0, character: 0),
278-
range: .init(startPair: (0, 0), endPair: (0, 0))
279+
range: .init(startPair: (0, 0), endPair: (0, 0)),
280+
middlewareComments: ["Removed redundant closing parenthesis."]
279281
),
280282
])
281283
}
@@ -309,7 +311,8 @@ class PostProcessingSuggestionServiceMiddlewareTests: XCTestCase {
309311
id: "1",
310312
text: "hello world",
311313
position: .init(line: 0, character: 1),
312-
range: .init(startPair: (0, 0), endPair: (0, 1))
314+
range: .init(startPair: (0, 0), endPair: (0, 1)),
315+
middlewareComments: ["Removed redundant closing parenthesis."]
313316
),
314317
])
315318
}
@@ -343,7 +346,8 @@ class PostProcessingSuggestionServiceMiddlewareTests: XCTestCase {
343346
id: "1",
344347
text: "hello world",
345348
position: .init(line: 0, character: 1),
346-
range: .init(startPair: (0, 0), endPair: (0, 1))
349+
range: .init(startPair: (0, 0), endPair: (0, 1)),
350+
middlewareComments: ["Removed redundant closing parenthesis."]
347351
),
348352
])
349353
}
@@ -377,7 +381,8 @@ class PostProcessingSuggestionServiceMiddlewareTests: XCTestCase {
377381
id: "1",
378382
text: "hello world",
379383
position: .init(line: 0, character: 1),
380-
range: .init(startPair: (0, 0), endPair: (0, 1))
384+
range: .init(startPair: (0, 0), endPair: (0, 1)),
385+
middlewareComments: ["Removed redundant closing parenthesis."]
381386
),
382387
])
383388
}

0 commit comments

Comments
 (0)