-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Ghost context provider #3506
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
Open
beatlevic
wants to merge
30
commits into
main
Choose a base branch
from
beatlevic/ghost-context-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ghost context provider #3506
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
1c0e0c1
WiP ghost context provider
beatlevic 0d5a465
Use pure function for formatContextForPrompt
beatlevic c067c1d
Added more context snippets like clipboard, static, recentlyVisited a…
beatlevic dc1f5f6
Improved categorizeSnippets
beatlevic 3ade747
Used comment wrapped formatSnippets directly
beatlevic 5810ccb
Removed RECENT_EDITS
beatlevic 3e3060c
Cleanup auto trigger strategy test
beatlevic a90e41a
Removed Ghost recent operations spec
beatlevic d10b8bc
Merge branch 'main' into beatlevic/ghost-context-provider
beatlevic 2334465
Cleanup ghost context provider
beatlevic 4c28d9b
Cleanup GhostContextProvider.test.ts
beatlevic b935be2
Plumb through GhostContextProvider
jrf0110 44f5165
Added GhostRecentlyVisitedRangesService to keep track of recent files
beatlevic ead100a
Added GhostRecentlyEditedTracker
beatlevic f9378a9
Use recentlyEditedRanges and recentlyVisitedRanges services directly
beatlevic 1432705
Added continuedev dispose methods
beatlevic dd4f395
Merge branch 'main' into beatlevic/ghost-context-provider
beatlevic adcac93
Merge branch 'main' into beatlevic/ghost-context-provider
beatlevic aad27a6
Fixed GhostInlineCompletionProvider.test.ts
beatlevic 7bf414b
Merge branch 'beatlevic/ghost-context-provider' of github.com:Kilo-Or…
beatlevic a3c1aad
Merge branch 'main' into beatlevic/ghost-context-provider
beatlevic 48450b3
Merge branch 'main' into beatlevic/ghost-context-provider
beatlevic 787ec84
Fixed HoleFiller.test.ts
beatlevic bdfceaa
Removed addCursorMarker from HoleFiller
beatlevic 3eed116
Merge branch 'main' into beatlevic/ghost-context-provider
beatlevic f171370
Removed useless comments
beatlevic e835e40
Removed try/catch wrapper for formattedContext
beatlevic 48c1124
Use AutocompleteCodeSnippet from continue
beatlevic e11c18e
Moved recentlyVisitedRanges and recentlyEditedRanges into context
beatlevic 06c623b
Fixed GhostContextProvider.test to propagate error
beatlevic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 0 additions & 153 deletions
153
src/services/ghost/__tests__/GhostRecentOperations.spec.ts
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
src/services/ghost/classic-auto-complete/GhostContextProvider.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import * as vscode from "vscode" | ||
| import { ContextRetrievalService } from "../../continuedev/core/autocomplete/context/ContextRetrievalService" | ||
| import { VsCodeIde } from "../../continuedev/core/vscode-test-harness/src/VSCodeIde" | ||
| import { AutocompleteInput } from "../types" | ||
| import { AutocompleteSnippetType } from "../../continuedev/core/autocomplete/snippets/types" | ||
| import { HelperVars } from "../../continuedev/core/autocomplete/util/HelperVars" | ||
| import { getAllSnippetsWithoutRace } from "../../continuedev/core/autocomplete/snippets/getAllSnippets" | ||
| import { getDefinitionsFromLsp } from "../../continuedev/core/vscode-test-harness/src/autocomplete/lsp" | ||
| import { DEFAULT_AUTOCOMPLETE_OPTS } from "../../continuedev/core/util/parameters" | ||
| import { getSnippets } from "../../continuedev/core/autocomplete/templating/filtering" | ||
| import { formatSnippets } from "../../continuedev/core/autocomplete/templating/formatting" | ||
|
|
||
| function convertToContinuedevInput(autocompleteInput: AutocompleteInput) { | ||
beatlevic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return { | ||
| ...autocompleteInput, | ||
| recentlyVisitedRanges: autocompleteInput.recentlyVisitedRanges.map((range) => ({ | ||
| ...range, | ||
| type: AutocompleteSnippetType.Code, | ||
| })), | ||
| } | ||
| } | ||
|
|
||
| export class GhostContextProvider { | ||
| private contextService: ContextRetrievalService | ||
| private ide: VsCodeIde | ||
|
|
||
| constructor(context: vscode.ExtensionContext) { | ||
| this.ide = new VsCodeIde(context) | ||
| this.contextService = new ContextRetrievalService(this.ide) | ||
| } | ||
|
|
||
| /** | ||
| * Get the IDE instance for use by tracking services | ||
| */ | ||
| public getIde(): VsCodeIde { | ||
| return this.ide | ||
| } | ||
|
|
||
| /** | ||
| * Get context snippets for the current autocomplete request | ||
| * Returns comment-based formatted context that can be added to prompts | ||
| */ | ||
| async getFormattedContext(autocompleteInput: AutocompleteInput, filepath: string): Promise<string> { | ||
| try { | ||
| // Convert filepath to URI if it's not already one | ||
beatlevic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const filepathUri = filepath.startsWith("file://") ? filepath : vscode.Uri.file(filepath).toString() | ||
|
|
||
| // Initialize import definitions cache | ||
| await this.contextService.initializeForFile(filepathUri) | ||
beatlevic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const continuedevInput = convertToContinuedevInput(autocompleteInput) | ||
|
|
||
| // Create helper with URI filepath | ||
| const helperInput = { | ||
| ...continuedevInput, | ||
| filepath: filepathUri, | ||
| } | ||
|
|
||
| const helper = await HelperVars.create(helperInput as any, DEFAULT_AUTOCOMPLETE_OPTS, "codestral", this.ide) | ||
beatlevic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const snippetPayload = await getAllSnippetsWithoutRace({ | ||
| helper, | ||
| ide: this.ide, | ||
| getDefinitionsFromLsp, | ||
| contextRetrievalService: this.contextService, | ||
| }) | ||
|
|
||
| const filteredSnippets = getSnippets(helper, snippetPayload) | ||
|
|
||
| // Convert all snippet filepaths to URIs | ||
| const snippetsWithUris = filteredSnippets.map((snippet: any) => ({ | ||
| ...snippet, | ||
| filepath: snippet.filepath?.startsWith("file://") | ||
beatlevic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ? snippet.filepath | ||
| : vscode.Uri.file(snippet.filepath).toString(), | ||
| })) | ||
|
|
||
| const workspaceDirs = await this.ide.getWorkspaceDirs() | ||
| const formattedContext = formatSnippets(helper, snippetsWithUris, workspaceDirs) | ||
|
|
||
| console.log("[GhostContextProvider] - formattedContext:", formattedContext) | ||
|
|
||
| return formattedContext | ||
| } catch (error) { | ||
beatlevic marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| console.warn("Failed to get formatted context:", error) | ||
| return "" | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.