@@ -67,25 +67,30 @@ final class Filespace {
6767 func refreshUpdateTime( ) {
6868 lastSuggestionUpdateTime = Environment . now ( )
6969 }
70-
70+
7171 func validateSuggestions( lines: [ String ] , cursorPosition: CursorPosition ) -> Bool {
7272 if cursorPosition. line != suggestionSourceSnapshot. cursorPosition. line {
7373 reset ( )
7474 return false
7575 }
76-
76+
7777 guard cursorPosition. line >= 0 , cursorPosition. line < lines. count else {
7878 reset ( )
7979 return false
8080 }
81-
81+
8282 let editingLine = lines [ cursorPosition. line] . dropLast ( 1 ) // dropping \n
8383 let suggestionFirstLine = presentingSuggestion? . text. split ( separator: " \n " ) . first ?? " "
8484 if !suggestionFirstLine. hasPrefix ( editingLine) {
8585 reset ( )
8686 return false
8787 }
88-
88+
89+ if editingLine. trimmingCharacters ( in: . whitespacesAndNewlines) . isEmpty {
90+ reset ( )
91+ return false
92+ }
93+
8994 return true
9095 }
9196}
@@ -166,7 +171,7 @@ final class Workspace {
166171 guard let self else { return }
167172 _ = self . suggestionService
168173 }
169-
174+
170175 let openedFiles = openedFileRecoverableStorage. openedFiles
171176 for fileURL in openedFiles {
172177 _ = createFilespaceIfNeeded ( fileURL: fileURL)
@@ -199,13 +204,13 @@ final class Workspace {
199204 let filespace = existed. createFilespaceIfNeeded ( fileURL: fileURL)
200205 return ( existed, filespace)
201206 }
202-
207+
203208 let new = Workspace ( projectRootURL: currentProjectURL)
204209 workspaces [ currentProjectURL] = new
205210 let filespace = new. createFilespaceIfNeeded ( fileURL: fileURL)
206211 return ( new, filespace)
207212 }
208-
213+
209214 // If not, we try to reuse a filespace if found.
210215 //
211216 // Sometimes, we can't get the project root path from Xcode window, for example, when the
@@ -218,7 +223,7 @@ final class Workspace {
218223
219224 // If we can't find an existed one, we will try to guess it.
220225 // Most of the time we won't enter this branch, just incase.
221-
226+
222227 let workspaceURL = try await Environment . guessProjectRootURLForFile ( fileURL)
223228
224229 let workspace = {
@@ -428,8 +433,9 @@ extension Workspace {
428433 guard let suggestionService else { return }
429434 await suggestionService. cancelRequest ( )
430435 }
431-
436+
432437 func terminateSuggestionService( ) async {
433438 await _suggestionService? . terminate ( )
434439 }
435440}
441+
0 commit comments