Changesets · Branches · Tags · Compare
| Changeset | 0795258f043e3529ad9d886c6f3195c0841a728e4563ca0fabcf79d3bdf2e920 |
|---|---|
| Author | Adarsh Iyer <76015889+adarshramiyer@users.noreply.github.com> · 2025-06-11 18:42 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-06-11 18:42 -07:00 |
| Parents | dc2ca87101a3, a665520662d1 |
3 files changed
modified core/autocomplete/templating/filtering.ts +15 −14
| @@ -3,6 +3,7 @@ | ||
| 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 @@ | ||
| 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 @@ | ||
| 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 @@ | ||
| 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 | } |
modified core/autocomplete/templating/formatOpenedFilesContext.ts +12 −1
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | import { |
| 3 | 3 | AutocompleteCodeSnippet, |
| 4 | 4 | AutocompleteSnippet, |
| 5 | + AutocompleteSnippetType, | |
| 5 | 6 | } from "../snippets/types"; |
| 6 | 7 | import { HelperVars } from "../util/HelperVars"; |
| 7 | 8 | |
| @@ -20,13 +21,23 @@ | ||
| 20 | 21 | recentlyOpenedFilesSnippets: AutocompleteCodeSnippet[], |
| 21 | 22 | remainingTokenCount: number, |
| 22 | 23 | helper: HelperVars, |
| 23 | - alreadyAddedSnippets: AutocompleteSnippet[], // TODO use this to deduplicate context | |
| 24 | + alreadyAddedSnippets: AutocompleteSnippet[], | |
| 24 | 25 | TOKEN_BUFFER: number, |
| 25 | 26 | ): AutocompleteCodeSnippet[] { |
| 26 | 27 | if (recentlyOpenedFilesSnippets.length === 0) { |
| 27 | 28 | return []; |
| 28 | 29 | } |
| 29 | 30 | |
| 31 | + // deduplication; if a snippet is already added, don't include it here | |
| 32 | + for (const snippet of alreadyAddedSnippets) { | |
| 33 | + if (snippet.type !== AutocompleteSnippetType.Code) { | |
| 34 | + continue; | |
| 35 | + } | |
| 36 | + recentlyOpenedFilesSnippets = recentlyOpenedFilesSnippets.filter( | |
| 37 | + (s) => s.filepath !== snippet.filepath, | |
| 38 | + ); | |
| 39 | + } | |
| 40 | + | |
| 30 | 41 | // Calculate how many full snippets would fit within the remaining token count |
| 31 | 42 | let numSnippetsThatFit = 0; |
| 32 | 43 | let totalTokens = 0; |
modified core/autocomplete/templating/validation.ts +9 −0
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import { |
| 2 | 2 | AutocompleteClipboardSnippet, |
| 3 | + AutocompleteCodeSnippet, | |
| 3 | 4 | AutocompleteSnippet, |
| 4 | 5 | AutocompleteSnippetType, |
| 5 | 6 | } from "../snippets/types"; |
| @@ -25,5 +26,13 @@ | ||
| 25 | 26 | return isValidClipboardSnippet(snippet); |
| 26 | 27 | } |
| 27 | 28 | |
| 29 | + if ( | |
| 30 | + (snippet as AutocompleteCodeSnippet).filepath?.startsWith( | |
| 31 | + "output:extension-output-Continue.continue", | |
| 32 | + ) | |
| 33 | + ) { | |
| 34 | + return false; | |
| 35 | + } | |
| 36 | + | |
| 28 | 37 | return true; |
| 29 | 38 | }; |