open files context works :) refinements to come as to how they are loaded into context
This commit is contained in:
parent
e9c1ad7e03
commit
0a632b5401
9 changed files with 94 additions and 9 deletions
|
|
@ -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 {
|
||||
|
|
@ -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[]> {
|
||||
|
|
@ -103,6 +105,49 @@ const getDiffSnippets = async (
|
|||
});
|
||||
};
|
||||
|
||||
const getSnippetsFromRecentlyOpenedFiles = async (
|
||||
helper: HelperVars,
|
||||
ide: IDE,
|
||||
): Promise<AutocompleteCodeSnippet[]> => {
|
||||
if (helper.options.useRecentlyOpened === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// stores snippets from cache
|
||||
const snippets: AutocompleteCodeSnippet[] = [];
|
||||
|
||||
try {
|
||||
const currentFileUri = `${helper.filepath}`;
|
||||
|
||||
// converts cache file URIs to autocomplete snippets
|
||||
for (const [fileUri, _] of openedFilesLruCache.entriesDescending()) {
|
||||
if (fileUri === currentFileUri) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const fileContent = await ide.readFile(fileUri);
|
||||
|
||||
if (!fileContent || fileContent.trim() === "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
snippets.push({
|
||||
filepath: fileUri,
|
||||
content: fileContent,
|
||||
type: AutocompleteSnippetType.Code,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(`Failed to read file ${fileUri}:`, e);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error processing opened files cache:", e);
|
||||
}
|
||||
|
||||
return snippets;
|
||||
};
|
||||
|
||||
export const getAllSnippets = async ({
|
||||
helper,
|
||||
ide,
|
||||
|
|
@ -123,6 +168,7 @@ export const getAllSnippets = async ({
|
|||
ideSnippets,
|
||||
diffSnippets,
|
||||
clipboardSnippets,
|
||||
recentlyOpenedFileSnippets,
|
||||
] = await Promise.all([
|
||||
racePromise(contextRetrievalService.getRootPathSnippets(helper)),
|
||||
racePromise(
|
||||
|
|
@ -133,6 +179,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), 500), // giving this one a little more time to complete
|
||||
]);
|
||||
|
||||
return {
|
||||
|
|
@ -143,5 +190,6 @@ export const getAllSnippets = async ({
|
|||
diffSnippets,
|
||||
clipboardSnippets,
|
||||
recentlyVisitedRangesSnippets: helper.input.recentlyVisitedRanges,
|
||||
recentlyOpenedFileSnippets,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ export const getSnippets = (
|
|||
recentlyVisitedRanges: payload.recentlyVisitedRangesSnippets,
|
||||
recentlyEditedRanges: payload.recentlyEditedRangeSnippets,
|
||||
diff: payload.diffSnippets,
|
||||
recentlyOpenedFiles: payload.recentlyOpenedFileSnippets,
|
||||
base: shuffleArray(
|
||||
filterSnippetsAlreadyInCaretWindow(
|
||||
[...payload.rootPathSnippets, ...payload.importDefinitionSnippets],
|
||||
|
|
@ -68,11 +69,17 @@ export const getSnippets = (
|
|||
defaultPriority: 1,
|
||||
snippets: payload.clipboardSnippets,
|
||||
},
|
||||
{
|
||||
key: "recentlyOpenedFiles",
|
||||
enabledOrPriority: helper.options.useRecentlyOpened,
|
||||
defaultPriority: 2,
|
||||
snippets: payload.recentlyOpenedFileSnippets,
|
||||
},
|
||||
{
|
||||
key: "recentlyVisitedRanges",
|
||||
enabledOrPriority:
|
||||
helper.options.experimental_includeRecentlyVisitedRanges,
|
||||
defaultPriority: 2,
|
||||
defaultPriority: 3,
|
||||
snippets: payload.recentlyVisitedRangesSnippets,
|
||||
/* TODO: recentlyVisitedRanges also contain contents from other windows like terminal or output
|
||||
if they are visible. We should handle them separately so that we can control their priority
|
||||
|
|
@ -82,13 +89,13 @@ export const getSnippets = (
|
|||
key: "recentlyEditedRanges",
|
||||
enabledOrPriority:
|
||||
helper.options.experimental_includeRecentlyEditedRanges,
|
||||
defaultPriority: 3,
|
||||
defaultPriority: 4,
|
||||
snippets: payload.recentlyEditedRangeSnippets,
|
||||
},
|
||||
{
|
||||
key: "diff",
|
||||
enabledOrPriority: helper.options.experimental_includeDiff,
|
||||
defaultPriority: 4,
|
||||
defaultPriority: 5,
|
||||
snippets: payload.diffSnippets,
|
||||
// TODO: diff is commonly too large, thus anything lower in priority is not included.
|
||||
},
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ import { CompletionOptions } from "../..";
|
|||
import { AutocompleteLanguageInfo } from "../constants/AutocompleteLanguageInfo";
|
||||
import { HelperVars } from "../util/HelperVars";
|
||||
|
||||
import { getUriPathBasename } from "../../util/uri";
|
||||
import { SnippetPayload } from "../snippets";
|
||||
import {
|
||||
AutocompleteTemplate,
|
||||
getTemplateForModel,
|
||||
} from "./AutocompleteTemplate";
|
||||
import { getSnippets } from "./filtering";
|
||||
import { getUriPathBasename } from "../../util/uri";
|
||||
import { formatSnippets } from "./formatting";
|
||||
import { getStopTokens } from "./getStopTokens";
|
||||
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -1107,6 +1107,7 @@ export interface TabAutocompleteOptions {
|
|||
useCache: boolean;
|
||||
onlyMyCode: boolean;
|
||||
useRecentlyEdited: boolean;
|
||||
useRecentlyOpened: boolean;
|
||||
disableInFiles?: string[];
|
||||
useImports?: boolean;
|
||||
showWhateverWeHaveAtXMs?: number;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ import { TabAutocompleteOptions } from "../index.js";
|
|||
|
||||
export const DEFAULT_AUTOCOMPLETE_OPTS: TabAutocompleteOptions = {
|
||||
disable: false,
|
||||
maxPromptTokens: 1024,
|
||||
prefixPercentage: 0.3,
|
||||
maxSuffixPercentage: 0.2,
|
||||
maxPromptTokens: 2048, // doubled from default to fit opened files
|
||||
prefixPercentage: 0.15, // halved as a result
|
||||
maxSuffixPercentage: 0.1, // halved as a result
|
||||
debounceDelay: 350,
|
||||
modelTimeout: 150,
|
||||
multilineCompletions: "auto",
|
||||
|
|
@ -15,6 +15,7 @@ export const DEFAULT_AUTOCOMPLETE_OPTS: TabAutocompleteOptions = {
|
|||
useCache: true,
|
||||
onlyMyCode: true,
|
||||
useRecentlyEdited: true,
|
||||
useRecentlyOpened: true,
|
||||
disableInFiles: undefined,
|
||||
useImports: true,
|
||||
transform: true,
|
||||
|
|
|
|||
21
manual-testing-sandbox/calculator_test/Calculator.java
Normal file
21
manual-testing-sandbox/calculator_test/Calculator.java
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
public class Calculator {
|
||||
public int myAddition(int a, int b, int c) {
|
||||
return a + b + c;
|
||||
}
|
||||
|
||||
public int subtract(int a, int b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
public int multiply(int a, int b) {
|
||||
return a * b;
|
||||
}
|
||||
|
||||
public double divide(int a, int b) {
|
||||
if (b != 0) {
|
||||
return (double) a / b;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Division by zero is not allowed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
7
manual-testing-sandbox/calculator_test/Main.java
Normal file
7
manual-testing-sandbox/calculator_test/Main.java
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Calculator calculator = new Calculator();
|
||||
calculator.myAddition(1, 2, 3);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -15,4 +15,4 @@ class Calculator:
|
|||
return self
|
||||
|
||||
def get_result(self):
|
||||
return self.result
|
||||
return self.result
|
||||
|
|
@ -14,7 +14,7 @@ class Calculator {
|
|||
this.result -= number;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
multiply(number: number): Calculator {
|
||||
this.result *= number;
|
||||
return this;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue