Skip to content

Commit 6d8d92e

Browse files
committed
Handle the case where the suggestion is partial but fully typed
1 parent 5942862 commit 6d8d92e

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

Core/Tests/ServiceTests/FilespaceSuggestionInvalidationTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
7878
range: .init(startPair: (1, 0), endPair: (1, 0))
7979
)
8080
let isValid = await filespace.validateSuggestions(
81-
lines: ["\n", "h🎆🎆o man\n", "\n"],
81+
lines: ["\n", "h🎆🎆o ma\n", "\n"],
8282
cursorPosition: .init(line: 1, character: 2)
8383
)
8484
XCTAssertTrue(isValid)
@@ -95,7 +95,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
9595
range: .init(startPair: (1, 0), endPair: (1, 0))
9696
)
9797
let isValid = await filespace.validateSuggestions(
98-
lines: ["\n", "h🎆🎆o man\n", "\n"],
98+
lines: ["\n", "h🎆🎆o ma\n", "\n"],
9999
cursorPosition: .init(line: 1, character: 3)
100100
)
101101
XCTAssertTrue(isValid)
@@ -170,7 +170,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
170170
range: .init(startPair: (1, 0), endPair: (1, 0))
171171
)
172172
let wasValid = await filespace.validateSuggestions(
173-
lines: ["\n", "hello man\n", "\n"],
173+
lines: ["\n", "hello ma\n", "\n"],
174174
cursorPosition: .init(line: 1, character: 8)
175175
)
176176
let isValid = await filespace.validateSuggestions(
@@ -190,7 +190,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
190190
range: .init(startPair: (1, 0), endPair: (1, 0))
191191
)
192192
let wasValid = await filespace.validateSuggestions(
193-
lines: ["\n", "hello m🎆🎆an\n", "\n"],
193+
lines: ["\n", "hello m🎆🎆a\n", "\n"],
194194
cursorPosition: .init(line: 1, character: 12)
195195
)
196196
let isValid = await filespace.validateSuggestions(
@@ -211,7 +211,7 @@ class FilespaceSuggestionInvalidationTests: XCTestCase {
211211
range: .init(startPair: (1, 0), endPair: (1, 0))
212212
)
213213
let wasValid = await filespace.validateSuggestions(
214-
lines: ["\n", "hello man!!!!!\n", "\n"],
214+
lines: ["\n", "hello ma!!!!\n", "\n"],
215215
cursorPosition: .init(line: 1, character: 8)
216216
)
217217
let isValid = await filespace.validateSuggestions(

Pro

Submodule Pro updated from 841a2c7 to a630ea2

Tool/Sources/WorkspaceSuggestionService/Filespace+SuggestionService.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public extension Filespace {
8383
)
8484

8585
let utf16View = editingLine.utf16
86-
86+
8787
let startIndex = utf16View.index(
8888
utf16View.startIndex,
8989
offsetBy: max(0, presentingSuggestion.range.start.character),
@@ -102,11 +102,13 @@ public extension Filespace {
102102

103103
return ""
104104
}()
105-
105+
106106
/// if the line will not change after accepting the suggestion
107-
if presentingSuggestion.range.isOneLine {
108-
#warning("TODO: Also handle the case where the suggestion doesn't start at character 0")
109-
if editingLine == suggestionFirstLine {
107+
if suggestionLines.count == 1 {
108+
if editingLine.hasPrefix(suggestionFirstLine),
109+
cursorPosition.character
110+
>= suggestionFirstLine.utf16.count + presentingSuggestion.range.start.character
111+
{
110112
reset()
111113
resetSnapshot()
112114
return false

0 commit comments

Comments
 (0)