Skip to content

Commit

Permalink
feat: adding configuration to recently opened file enable collection …
Browse files Browse the repository at this point in the history
…of snippets from recent opened files

This commit enables the collection of snippets from recent opened files in the CompletionProvider class. It adds a new configuration option `collectSnippetsFromRecentOpenedFiles` to the default configuration, which is set to `true` by default. The maximum number of opened files to collect snippets from is set to 5.

These changes are necessary to improve the code completion feature by including snippets from recently opened files.

Ref: feat(recent-opened-files): enable collection of snippets from recent opened files
  • Loading branch information
Sma1lboy committed Oct 4, 2024
1 parent 5e8b163 commit 86518aa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions clients/tabby-agent/src/codeCompletion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,10 @@ export class CompletionProvider implements Feature {
private async collectSnippetsFromOpenedFiles(): Promise<
{ filepath: string; offset: number; text: string; score: number }[] | undefined
> {
const config = this.configurations.getMergedConfig();
if (!config.completion.prompt.collectSnippetsFromRecentOpenedFiles.enabled) {
return undefined;
}
this.logger.debug("Starting collecting snippets from opened files.");
const recentlyOpenedFiles = this.fileTracker.getAllFilesWithoutActive();
const codeSnippets: { filepath: string; offset: number; text: string; score: number }[] = [];
Expand Down
8 changes: 5 additions & 3 deletions clients/tabby-agent/src/codeSearch/fileTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Connection, Range } from "vscode-languageserver";
import { Feature } from "../feature";
import { OpenedFileParams, OpenedFileRequest, ServerCapabilities } from "../protocol";
import { getLogger } from "../logger";
import { Configurations } from "../config";

interface OpenedFile {
uri: string;
Expand Down Expand Up @@ -88,10 +89,11 @@ export class LRUList {
}
export class FileTracker implements Feature {
private readonly logger = getLogger("FileTracker");
private readonly fileList = new LRUList(10);

constructor() {}
private fileList: LRUList = new LRUList(
this.configurations.getMergedConfig().completion.prompt.collectSnippetsFromRecentOpenedFiles.maxOpenedFiles,
);

constructor(private readonly configurations: Configurations) {}
initialize(connection: Connection): ServerCapabilities | Promise<ServerCapabilities> {
connection.onNotification(OpenedFileRequest.type, (param: OpenedFileParams) => {
console.log("Received opened file request:" + param.action);
Expand Down
4 changes: 4 additions & 0 deletions clients/tabby-agent/src/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export const defaultConfigData: ConfigData = {
overlapLines: 1,
},
},
collectSnippetsFromRecentOpenedFiles:{
enabled: true,
maxOpenedFiles: 5,
},
clipboard: {
minChars: 3,
maxChars: 2000,
Expand Down
4 changes: 4 additions & 0 deletions clients/tabby-agent/src/config/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export type ConfigData = {
overlapLines: number;
};
};
collectSnippetsFromRecentOpenedFiles: {
enabled: boolean;
maxOpenedFiles: number;
};
clipboard: {
minChars: number;
maxChars: number;
Expand Down

0 comments on commit 86518aa

Please sign in to comment.