Skip to content
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

feat(tabby-agent): add recent opened files frontend to code completion requests #3238

Merged
merged 16 commits into from
Oct 14, 2024

Conversation

Sma1lboy
Copy link
Collaborator

@Sma1lboy Sma1lboy commented Oct 4, 2024

CC @wsxiaoys
This is the frontend part to #2664

Demo

Screen.Recording.2024-10-04.at.14.47.07.mov

Description

This PR introduces functionality to include recently opened files in the code suggestion buffer, enhancing context-aware code completion.

Feature Overview

  • Adds recently opened files to the suggestion buffer
  • Improves code completion relevance by considering the user's recent work context

Implementation Details

  • Introduced a FileTracker in the TabbyAgent LSP server:
    • Uses an LRU (Least Recently Used) queue to manage recently opened files
    • Tracks filepath, TextEditor or last VisibleRanges, and file status (open/closed)
  • Relevant snippet collection strategy:
    • For files: Last visible range's middle line with configurable block size

This implementation aims to provide more contextually relevant code suggestions by considering the user's recent file interactions.

Next Steps

  • Add PR for dynamically adjusting offset based on last cursor position or last middle line range.

chore: add relevant snippets to client-open-api
refactor: Add LRUList class to track recently opened files

This commit adds a new class called LRUList to track recently opened files in the FileTracker feature. The LRUList class provides methods for inserting, removing, updating, and retrieving files based on their URI. It also maintains a maximum size to limit the number of files stored.

The LRUList class is used by the FileTracker feature to keep track of the most recently opened files. When a file is opened or its visibility changes, it is inserted or updated in the LRUList. The list is then pruned to remove the least recently used files if it exceeds the maximum size.

This refactor improves the efficiency and organization of the FileTracker feature by separating the logic for tracking files into a dedicated class.
…e editors

This commit adds a new class called FileTrackerProvider in the vscode/src directory. The FileTrackerProvider class is responsible for collecting visible editors and their visible ranges. It filters out editors that do not have a file name starting with a forward slash ("/"). The collected editors are then sorted based on their URI, with the active editor being prioritized.

The FileTrackerProvider class also provides a method to collect the active editor, which returns the URI and visible range of the currently active text editor.

These changes are part of the ongoing development of the FileTracker feature, which aims to track and manage recently opened files in the vscode extension.

Ref: feat(fileTracker): adding file tracking provider in lsp server
@Sma1lboy Sma1lboy requested a review from wsxiaoys October 4, 2024 20:09
…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
@Sma1lboy Sma1lboy force-pushed the feat-recent-opened-files-frontend branch from 94e3671 to 86518aa Compare October 4, 2024 21:40
@wsxiaoys wsxiaoys changed the title feat(tabby-agent): Feat recent opened files frontend to code completion requests feat(tabby-agent): add recent opened files frontend to code completion requests Oct 5, 2024
@wsxiaoys wsxiaoys requested a review from icycodes October 8, 2024 08:25
clients/tabby-agent/src/codeSearch/fileTracker.ts Outdated Show resolved Hide resolved
clients/tabby-agent/src/codeSearch/fileTracker.ts Outdated Show resolved Hide resolved
clients/vscode/src/FileTrackProvider.ts Outdated Show resolved Hide resolved
clients/tabby-agent/src/protocol.ts Outdated Show resolved Hide resolved
clients/tabby-agent/src/protocol.ts Outdated Show resolved Hide resolved
clients/tabby-agent/src/codeSearch/fileTracker.ts Outdated Show resolved Hide resolved
clients/tabby-agent/src/codeSearch/fileTracker.ts Outdated Show resolved Hide resolved
clients/tabby-agent/src/codeCompletion/index.ts Outdated Show resolved Hide resolved
clients/tabby-agent/src/protocol.ts Outdated Show resolved Hide resolved
@wsxiaoys wsxiaoys removed their request for review October 11, 2024 09:55
chore: remove logger import
@Sma1lboy Sma1lboy force-pushed the feat-recent-opened-files-frontend branch from 3fadc47 to 382f941 Compare October 11, 2024 19:12
@icycodes icycodes merged commit 5dfe7a1 into TabbyML:main Oct 14, 2024
6 of 8 checks passed
@Sma1lboy Sma1lboy deleted the feat-recent-opened-files-frontend branch October 14, 2024 19:35
icycodes pushed a commit that referenced this pull request Oct 17, 2024
…n requests (#3238)

* feat(backend): adding open recent file segments

chore: add relevant snippets to client-open-api

* feat(protocol): add OpenedFileRequest namespace and types

* feat: add FileTracker to code completion and server initialization

* feat(fileTracker): adding file tracking provider in lsp server
refactor: Add LRUList class to track recently opened files

This commit adds a new class called LRUList to track recently opened files in the FileTracker feature. The LRUList class provides methods for inserting, removing, updating, and retrieving files based on their URI. It also maintains a maximum size to limit the number of files stored.

The LRUList class is used by the FileTracker feature to keep track of the most recently opened files. When a file is opened or its visibility changes, it is inserted or updated in the LRUList. The list is then pruned to remove the least recently used files if it exceeds the maximum size.

This refactor improves the efficiency and organization of the FileTracker feature by separating the logic for tracking files into a dedicated class.

* feat(vscode): implement FileTrackerProvider class for tracking visible editors

This commit adds a new class called FileTrackerProvider in the vscode/src directory. The FileTrackerProvider class is responsible for collecting visible editors and their visible ranges. It filters out editors that do not have a file name starting with a forward slash ("/"). The collected editors are then sorted based on their URI, with the active editor being prioritized.

The FileTrackerProvider class also provides a method to collect the active editor, which returns the URI and visible range of the currently active text editor.

These changes are part of the ongoing development of the FileTracker feature, which aims to track and manage recently opened files in the vscode extension.

Ref: feat(fileTracker): adding file tracking provider in lsp server

* feat(vscode): implement FileTrackerProvider class for tracking visible editors

* feat: update snippet count check in extract_snippets_from_segments

* feat: adding configuration to recently opened file enable collection 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

* [autofix.ci] apply automated fixes

* refactor: using lru-cache package and passing config

* fix: fixing typo, remove unuse type

* refactor: remove action and rename the notification

* feat(config): add maxCharsPerOpenedFiles to default config data.

* refactor: optimize code snippet collection algorithm in CompletionProvider.

adding max chars size per opened files

* chore: remove unused log

chore: remove logger import

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
icycodes pushed a commit that referenced this pull request Oct 17, 2024
…n requests (#3238)

* feat(backend): adding open recent file segments

chore: add relevant snippets to client-open-api

* feat(protocol): add OpenedFileRequest namespace and types

* feat: add FileTracker to code completion and server initialization

* feat(fileTracker): adding file tracking provider in lsp server
refactor: Add LRUList class to track recently opened files

This commit adds a new class called LRUList to track recently opened files in the FileTracker feature. The LRUList class provides methods for inserting, removing, updating, and retrieving files based on their URI. It also maintains a maximum size to limit the number of files stored.

The LRUList class is used by the FileTracker feature to keep track of the most recently opened files. When a file is opened or its visibility changes, it is inserted or updated in the LRUList. The list is then pruned to remove the least recently used files if it exceeds the maximum size.

This refactor improves the efficiency and organization of the FileTracker feature by separating the logic for tracking files into a dedicated class.

* feat(vscode): implement FileTrackerProvider class for tracking visible editors

This commit adds a new class called FileTrackerProvider in the vscode/src directory. The FileTrackerProvider class is responsible for collecting visible editors and their visible ranges. It filters out editors that do not have a file name starting with a forward slash ("/"). The collected editors are then sorted based on their URI, with the active editor being prioritized.

The FileTrackerProvider class also provides a method to collect the active editor, which returns the URI and visible range of the currently active text editor.

These changes are part of the ongoing development of the FileTracker feature, which aims to track and manage recently opened files in the vscode extension.

Ref: feat(fileTracker): adding file tracking provider in lsp server

* feat(vscode): implement FileTrackerProvider class for tracking visible editors

* feat: update snippet count check in extract_snippets_from_segments

* feat: adding configuration to recently opened file enable collection 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

* [autofix.ci] apply automated fixes

* refactor: using lru-cache package and passing config

* fix: fixing typo, remove unuse type

* refactor: remove action and rename the notification

* feat(config): add maxCharsPerOpenedFiles to default config data.

* refactor: optimize code snippet collection algorithm in CompletionProvider.

adding max chars size per opened files

* chore: remove unused log

chore: remove logger import

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants