@@ -3,6 +3,7 @@ import { SnippetPayload } from "../snippets";
33import {
44 AutocompleteCodeSnippet ,
55 AutocompleteSnippet ,
6+ AutocompleteSnippetType ,
67} from "../snippets/types" ;
78import { HelperVars } from "../util/HelperVars" ;
89import { formatOpenedFilesContext } from "./formatOpenedFilesContext" ;
@@ -130,21 +131,16 @@ export const getSnippets = (
130131 const finalSnippets = [ ] ;
131132 let remainingTokenCount = getRemainingTokenCount ( helper ) ;
132133
134+ // tracks already added filepaths for deduplication
135+ const addedFilepaths = new Set < string > ( ) ;
136+
133137 // Process snippets in priority order
134138 for ( const { key } of snippetOrder ) {
135139 // Special handling for recentlyOpenedFiles
136140 if ( key === "recentlyOpenedFiles" && helper . options . useRecentlyOpened ) {
137- const recentlyOpenedFilesSnippets =
138- payload . recentlyOpenedFileSnippets . filter (
139- ( snippet ) =>
140- ! ( snippet as AutocompleteCodeSnippet ) . filepath ?. startsWith (
141- "output:extension-output-Continue.continue" ,
142- ) ,
143- ) ;
144-
145141 // Custom trimming
146142 const processedSnippets = formatOpenedFilesContext (
147- recentlyOpenedFilesSnippets ,
143+ payload . recentlyOpenedFileSnippets ,
148144 remainingTokenCount ,
149145 helper ,
150146 finalSnippets ,
@@ -160,18 +156,18 @@ export const getSnippets = (
160156
161157 if ( remainingTokenCount >= snippetSize ) {
162158 finalSnippets . push ( snippet ) ;
159+ addedFilepaths . add ( snippet . filepath ) ;
163160 remainingTokenCount -= snippetSize ;
164161 } else {
165- break ; // Out of tokens
162+ continue ; // Not enough tokens, try again with next snippet
166163 }
167164 }
168165 } else {
169166 // Normal processing for other snippet types
170167 const snippetsToProcess = snippets [ key ] . filter (
171168 ( snippet ) =>
172- ! ( snippet as AutocompleteCodeSnippet ) . filepath ?. startsWith (
173- "output:extension-output-Continue.continue" ,
174- ) ,
169+ snippet . type !== AutocompleteSnippetType . Code ||
170+ ! addedFilepaths . has ( snippet . filepath ) ,
175171 ) ;
176172
177173 for ( const snippet of snippetsToProcess ) {
@@ -182,9 +178,14 @@ export const getSnippets = (
182178
183179 if ( remainingTokenCount >= snippetSize ) {
184180 finalSnippets . push ( snippet ) ;
181+
182+ if ( ( snippet as AutocompleteCodeSnippet ) . filepath ) {
183+ addedFilepaths . add ( ( snippet as AutocompleteCodeSnippet ) . filepath ) ;
184+ }
185+
185186 remainingTokenCount -= snippetSize ;
186187 } else {
187- break ; // Out of tokens
188+ continue ; // Not enough tokens, try again with next snippet
188189 }
189190 }
190191 }
0 commit comments