@@ -3,6 +3,7 @@ import { SnippetPayload } from "../snippets";
3
3
import {
4
4
AutocompleteCodeSnippet ,
5
5
AutocompleteSnippet ,
6
+ AutocompleteSnippetType ,
6
7
} from "../snippets/types" ;
7
8
import { HelperVars } from "../util/HelperVars" ;
8
9
import { formatOpenedFilesContext } from "./formatOpenedFilesContext" ;
@@ -130,21 +131,16 @@ export const getSnippets = (
130
131
const finalSnippets = [ ] ;
131
132
let remainingTokenCount = getRemainingTokenCount ( helper ) ;
132
133
134
+ // tracks already added filepaths for deduplication
135
+ const addedFilepaths = new Set < string > ( ) ;
136
+
133
137
// Process snippets in priority order
134
138
for ( const { key } of snippetOrder ) {
135
139
// Special handling for recentlyOpenedFiles
136
140
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
-
145
141
// Custom trimming
146
142
const processedSnippets = formatOpenedFilesContext (
147
- recentlyOpenedFilesSnippets ,
143
+ payload . recentlyOpenedFileSnippets ,
148
144
remainingTokenCount ,
149
145
helper ,
150
146
finalSnippets ,
@@ -160,18 +156,18 @@ export const getSnippets = (
160
156
161
157
if ( remainingTokenCount >= snippetSize ) {
162
158
finalSnippets . push ( snippet ) ;
159
+ addedFilepaths . add ( snippet . filepath ) ;
163
160
remainingTokenCount -= snippetSize ;
164
161
} else {
165
- break ; // Out of tokens
162
+ continue ; // Not enough tokens, try again with next snippet
166
163
}
167
164
}
168
165
} else {
169
166
// Normal processing for other snippet types
170
167
const snippetsToProcess = snippets [ key ] . filter (
171
168
( snippet ) =>
172
- ! ( snippet as AutocompleteCodeSnippet ) . filepath ?. startsWith (
173
- "output:extension-output-Continue.continue" ,
174
- ) ,
169
+ snippet . type !== AutocompleteSnippetType . Code ||
170
+ ! addedFilepaths . has ( snippet . filepath ) ,
175
171
) ;
176
172
177
173
for ( const snippet of snippetsToProcess ) {
@@ -182,9 +178,14 @@ export const getSnippets = (
182
178
183
179
if ( remainingTokenCount >= snippetSize ) {
184
180
finalSnippets . push ( snippet ) ;
181
+
182
+ if ( ( snippet as AutocompleteCodeSnippet ) . filepath ) {
183
+ addedFilepaths . add ( ( snippet as AutocompleteCodeSnippet ) . filepath ) ;
184
+ }
185
+
185
186
remainingTokenCount -= snippetSize ;
186
187
} else {
187
- break ; // Out of tokens
188
+ continue ; // Not enough tokens, try again with next snippet
188
189
}
189
190
}
190
191
}
0 commit comments