Skip to content

[Updated PR] [Feature] Autocomplete context from other tabs open in the editor #6012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ad95e61
defining cache for opened files + making change in active editor upda…
adarshramiyer Jun 3, 2025
ceee183
general outline of which files will be modified for update 2; short b…
adarshramiyer Jun 3, 2025
78c86d1
temp experiment finished. figured out how to catch when files close.
adarshramiyer Jun 3, 2025
6a542a2
good detection of changing active view and closing tabs now
adarshramiyer Jun 3, 2025
192c22a
cache updates properly now for opening files, changing views, and clo…
adarshramiyer Jun 4, 2025
4f9c7a3
testing console logs removed, this is good to go
adarshramiyer Jun 4, 2025
e9c1ad7
caching of context with initialization, ordering, addition, and remov…
adarshramiyer Jun 4, 2025
0a632b5
open files context works :) refinements to come as to how they are lo…
adarshramiyer Jun 4, 2025
062abb6
branch feature/view-context-make-context-experiment-greedy terminated…
adarshramiyer Jun 4, 2025
7bbd9b0
ok branch finished now. made time limit for open file context same as…
adarshramiyer Jun 4, 2025
5fbc641
wrote adaptive trimmer for autocomplete opened file context
adarshramiyer Jun 5, 2025
8fc3a35
branch ends here; debugged, optimized, and set up for good open file …
adarshramiyer Jun 5, 2025
029b0ca
updated MessageIDE and FileSystemIDE to include necessary methods for…
adarshramiyer Jun 5, 2025
1513f5d
miscellaneous cleanup
adarshramiyer Jun 5, 2025
95abe0c
Merge branch 'main' of https://github.com/continuedev/continue
adarshramiyer Jun 6, 2025
ce2c902
erge branch 'feature/view-context/base' into feature/view-context/bas…
adarshramiyer Jun 6, 2025
a995da4
removed duplicate function in filesystem
adarshramiyer Jun 6, 2025
91a4550
changed test.ts for prettier formatting test
adarshramiyer Jun 6, 2025
039404a
wrapped up requested edits for opened file context
adarshramiyer Jun 9, 2025
b6ab31f
quick fixes for PR checks
adarshramiyer Jun 9, 2025
c5e86e8
restored files/closed data passing and unified util functions for get…
adarshramiyer Jun 10, 2025
8f1c5ed
quick fixes for PR checks
adarshramiyer Jun 9, 2025
37539b7
Merge branch 'feature/view-context/base-copy' of https://github.com/c…
adarshramiyer Jun 10, 2025
93ed462
console log cleanup
adarshramiyer Jun 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions core/autocomplete/snippets/getAllSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { findUriInDirs } from "../../util/uri";
import { ContextRetrievalService } from "../context/ContextRetrievalService";
import { GetLspDefinitionsFunction } from "../types";
import { HelperVars } from "../util/HelperVars";
import { openedFilesLruCache } from "../util/openedFilesLruCache";
import { getDiffsFromCache } from "./gitDiffCache";

import {
Expand All @@ -22,6 +23,7 @@ export interface SnippetPayload {
recentlyVisitedRangesSnippets: AutocompleteCodeSnippet[];
diffSnippets: AutocompleteDiffSnippet[];
clipboardSnippets: AutocompleteClipboardSnippet[];
recentlyOpenedFileSnippets: AutocompleteCodeSnippet[];
}

function racePromise<T>(promise: Promise<T[]>, timeout = 100): Promise<T[]> {
Expand Down Expand Up @@ -103,6 +105,65 @@ const getDiffSnippets = async (
});
};

const getSnippetsFromRecentlyOpenedFiles = async (
helper: HelperVars,
ide: IDE,
): Promise<AutocompleteCodeSnippet[]> => {
if (helper.options.useRecentlyOpened === false) {
return [];
}

try {
const currentFileUri = `${helper.filepath}`;

// Get all file URIs excluding the current file
const fileUrisToRead = [...openedFilesLruCache.entriesDescending()]
.filter(([fileUri, _]) => fileUri !== currentFileUri)
.map(([fileUri, _]) => fileUri);

// Create an array of promises that each read a file with timeout
const fileReadPromises = fileUrisToRead.map((fileUri) => {
// Create a promise that resolves to a snippet or null
const readPromise = new Promise<AutocompleteCodeSnippet | null>(
(resolve) => {
ide
.readFile(fileUri)
.then((fileContent) => {
if (!fileContent || fileContent.trim() === "") {
resolve(null);
return;
}

resolve({
filepath: fileUri,
content: fileContent,
type: AutocompleteSnippetType.Code,
});
})
.catch((e) => {
console.error(`Failed to read file ${fileUri}:`, e);
resolve(null);
});
},
);
// Cut off at 80ms via racing promises
return Promise.race([
readPromise,
new Promise<null>((resolve) => setTimeout(() => resolve(null), 80)),
]);
});

// Execute all file reads in parallel
const results = await Promise.all(fileReadPromises);

// Filter out null results
return results.filter(Boolean) as AutocompleteCodeSnippet[];
} catch (e) {
console.error("Error processing opened files cache:", e);
return [];
}
};

export const getAllSnippets = async ({
helper,
ide,
Expand All @@ -123,6 +184,7 @@ export const getAllSnippets = async ({
ideSnippets,
diffSnippets,
clipboardSnippets,
recentlyOpenedFileSnippets,
] = await Promise.all([
racePromise(contextRetrievalService.getRootPathSnippets(helper)),
racePromise(
Expand All @@ -133,6 +195,7 @@ export const getAllSnippets = async ({
: [],
[], // racePromise(getDiffSnippets(ide)) // temporarily disabled, see https://github.com/continuedev/continue/pull/5882,
racePromise(getClipboardSnippets(ide)),
racePromise(getSnippetsFromRecentlyOpenedFiles(helper, ide)), // giving this one a little more time to complete
]);

return {
Expand All @@ -143,5 +206,6 @@ export const getAllSnippets = async ({
diffSnippets,
clipboardSnippets,
recentlyVisitedRangesSnippets: helper.input.recentlyVisitedRanges,
recentlyOpenedFileSnippets,
};
};
Loading
Loading