-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Ghost context provider #3506
Changes from 24 commits
1c0e0c1
0d5a465
c067c1d
dc1f5f6
3ade747
5810ccb
3e3060c
a90e41a
d10b8bc
2334465
4c28d9b
b935be2
44f5165
ead100a
f9378a9
1432705
dd4f395
adcac93
aad27a6
7bf414b
a3c1aad
48450b3
787ec84
bdfceaa
3eed116
f171370
e835e40
48c1124
e11c18e
06c623b
d442b5b
7a15c57
b279001
36ab69e
83824de
d338310
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| 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) | ||
|
||
|
|
||
| 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://") | ||
|
||
| ? 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 "" | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.