11import * as vscode from "vscode"
2- import { GhostSuggestionsState } from "./GhostSuggestions"
2+ import { FillInAtCursorSuggestion , GhostSuggestionsState } from "./GhostSuggestions"
33import { extractPrefixSuffix } from "./types"
44
55const MAX_SUGGESTIONS_HISTORY = 20
66
77export class GhostInlineCompletionProvider implements vscode . InlineCompletionItemProvider {
8- private suggestionsHistory : GhostSuggestionsState [ ] = [ ]
8+ private suggestionsHistory : FillInAtCursorSuggestion [ ] = [ ]
99
10- public updateSuggestions ( suggestions : GhostSuggestionsState | null ) : void {
11- if ( suggestions == null ) {
10+ public updateSuggestions ( suggestions : GhostSuggestionsState ) : void {
11+ const fillInAtCursor = suggestions . getFillInAtCursor ( )
12+
13+ // Only store if we have a fill-in suggestion
14+ if ( ! fillInAtCursor ) {
1215 return
1316 }
1417
15- const fillInAtCursor = suggestions . getFillInAtCursor ( )
16-
1718 // Check if this suggestion already exists in the history
18- if ( fillInAtCursor ) {
19- const isDuplicate = this . suggestionsHistory . some ( ( existingSuggestion ) => {
20- const existingFillIn = existingSuggestion . getFillInAtCursor ( )
21- return (
22- existingFillIn &&
23- existingFillIn . text === fillInAtCursor . text &&
24- existingFillIn . prefix === fillInAtCursor . prefix &&
25- existingFillIn . suffix === fillInAtCursor . suffix
26- )
27- } )
19+ const isDuplicate = this . suggestionsHistory . some (
20+ ( existing ) =>
21+ existing . text === fillInAtCursor . text &&
22+ existing . prefix === fillInAtCursor . prefix &&
23+ existing . suffix === fillInAtCursor . suffix ,
24+ )
2825
29- // Skip adding if it's a duplicate
30- if ( isDuplicate ) {
31- return
32- }
26+ // Skip adding if it's a duplicate
27+ if ( isDuplicate ) {
28+ return
3329 }
3430
3531 // Add to the end of the array (most recent)
36- this . suggestionsHistory . push ( suggestions )
32+ this . suggestionsHistory . push ( fillInAtCursor )
3733
3834 // Remove oldest if we exceed the limit
3935 if ( this . suggestionsHistory . length > MAX_SUGGESTIONS_HISTORY ) {
@@ -51,12 +47,7 @@ export class GhostInlineCompletionProvider implements vscode.InlineCompletionIte
5147
5248 // Search from most recent to least recent
5349 for ( let i = this . suggestionsHistory . length - 1 ; i >= 0 ; i -- ) {
54- const suggestions = this . suggestionsHistory [ i ]
55- const fillInAtCursor = suggestions ?. getFillInAtCursor ( )
56-
57- if ( ! fillInAtCursor ) {
58- continue
59- }
50+ const fillInAtCursor = this . suggestionsHistory [ i ]
6051
6152 // First, try exact prefix/suffix match
6253 if ( prefix === fillInAtCursor . prefix && suffix === fillInAtCursor . suffix ) {
0 commit comments