11import * as vscode from "vscode"
2- import { FillInAtCursorSuggestion , GhostSuggestionsState } from "./GhostSuggestions"
2+ import { FillInAtCursorSuggestion } from "./GhostSuggestions"
33import { extractPrefixSuffix , GhostSuggestionContext , contextToAutocompleteInput } from "../types"
44import { parseGhostResponse } from "./GhostStreamingParser"
55import { AutoTriggerStrategy } from "./AutoTriggerStrategy"
@@ -62,7 +62,7 @@ export function findMatchingSuggestion(
6262}
6363
6464export interface LLMRetrievalResult {
65- suggestions : GhostSuggestionsState
65+ suggestion : FillInAtCursorSuggestion
6666 cost : number
6767 inputTokens : number
6868 outputTokens : number
@@ -134,9 +134,9 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte
134134 // Check cache before making API call (includes both successful and failed lookups)
135135 const cachedResult = findMatchingSuggestion ( prefix , suffix , this . suggestionsHistory )
136136 if ( cachedResult !== null ) {
137- // Return empty result if we have a cached entry (either success or failure)
137+ // Return cached result (either success with text or failure with empty string )
138138 return {
139- suggestions : new GhostSuggestionsState ( ) ,
139+ suggestion : { text : cachedResult , prefix , suffix } ,
140140 cost : 0 ,
141141 inputTokens : 0 ,
142142 outputTokens : 0 ,
@@ -154,7 +154,7 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte
154154
155155 if ( this . isRequestCancelled ) {
156156 return {
157- suggestions : new GhostSuggestionsState ( ) ,
157+ suggestion : { text : "" , prefix , suffix } ,
158158 cost : 0 ,
159159 inputTokens : 0 ,
160160 outputTokens : 0 ,
@@ -183,7 +183,7 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte
183183
184184 if ( this . isRequestCancelled ) {
185185 return {
186- suggestions : new GhostSuggestionsState ( ) ,
186+ suggestion : { text : "" , prefix , suffix } ,
187187 cost : usageInfo . cost ,
188188 inputTokens : usageInfo . inputTokens ,
189189 outputTokens : usageInfo . outputTokens ,
@@ -193,14 +193,15 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte
193193 }
194194
195195 // Parse the response using the standalone function
196- const finalParseResult = parseGhostResponse ( response , prefix , suffix )
196+ const fillInAtCursorSuggestion = parseGhostResponse ( response , prefix , suffix )
197197
198- if ( finalParseResult . suggestions . getFillInAtCursor ( ) ) {
199- console . info ( "Final suggestion:" , finalParseResult . suggestions . getFillInAtCursor ( ) )
198+ if ( fillInAtCursorSuggestion . text ) {
199+ console . info ( "Final suggestion:" , fillInAtCursorSuggestion )
200200 }
201201
202+ // Always return a FillInAtCursorSuggestion, even if text is empty
202203 return {
203- suggestions : finalParseResult . suggestions ,
204+ suggestion : fillInAtCursorSuggestion ,
204205 cost : usageInfo . cost ,
205206 inputTokens : usageInfo . inputTokens ,
206207 outputTokens : usageInfo . outputTokens ,
@@ -281,19 +282,17 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte
281282 )
282283 }
283284
284- const fillInAtCursor = result . suggestions . getFillInAtCursor ( )
285+ // Always update suggestions, even if text is empty (for caching)
286+ this . updateSuggestions ( result . suggestion )
285287
286- if ( fillInAtCursor ) {
287- this . updateSuggestions ( fillInAtCursor )
288+ if ( result . suggestion . text ) {
288289 const item : vscode . InlineCompletionItem = {
289- insertText : fillInAtCursor . text ,
290+ insertText : result . suggestion . text ,
290291 range : new vscode . Range ( position , position ) ,
291292 }
292293 return [ item ]
293294 } else {
294- // Store empty suggestion to prevent re-requesting
295- this . updateSuggestions ( { text : "" , prefix, suffix } )
296-
295+ // Empty text means no suggestion to show
297296 return [ ]
298297 }
299298 } catch ( error ) {
0 commit comments