make the class a singleton, save user diff
This commit is contained in:
parent
d3e64842eb
commit
85dd9db597
1 changed files with 39 additions and 1 deletions
|
|
@ -40,6 +40,8 @@ const ERRORS_TO_IGNORE = [
|
|||
];
|
||||
|
||||
export class NextEditProvider {
|
||||
private static instance: NextEditProvider | null = null;
|
||||
|
||||
private autocompleteCache = AutocompleteLruCache.get();
|
||||
public errorsShown: Set<string> = new Set();
|
||||
private bracketMatchingService = new BracketMatchingService();
|
||||
|
|
@ -48,8 +50,9 @@ export class NextEditProvider {
|
|||
private loggingService = new AutocompleteLoggingService();
|
||||
private contextRetrievalService: ContextRetrievalService;
|
||||
private endpointType: "default" | "fineTuned";
|
||||
private diffContext: string = "";
|
||||
|
||||
constructor(
|
||||
private constructor(
|
||||
private readonly configHandler: ConfigHandler,
|
||||
private readonly ide: IDE,
|
||||
private readonly _injectedGetLlm: () => Promise<ILLM | undefined>,
|
||||
|
|
@ -62,6 +65,40 @@ export class NextEditProvider {
|
|||
this.endpointType = endpointType;
|
||||
}
|
||||
|
||||
public static initialize(
|
||||
configHandler: ConfigHandler,
|
||||
ide: IDE,
|
||||
injectedGetLlm: () => Promise<ILLM | undefined>,
|
||||
onError: (e: any) => void,
|
||||
getDefinitionsFromLsp: GetLspDefinitionsFunction,
|
||||
endpointType: "default" | "fineTuned",
|
||||
): NextEditProvider {
|
||||
if (!NextEditProvider.instance) {
|
||||
NextEditProvider.instance = new NextEditProvider(
|
||||
configHandler,
|
||||
ide,
|
||||
injectedGetLlm,
|
||||
onError,
|
||||
getDefinitionsFromLsp,
|
||||
endpointType,
|
||||
);
|
||||
}
|
||||
return NextEditProvider.instance;
|
||||
}
|
||||
|
||||
public static getInstance(): NextEditProvider {
|
||||
if (!NextEditProvider.instance) {
|
||||
throw new Error(
|
||||
"NextEditProvider has not been initialized. Call initialize() first.",
|
||||
);
|
||||
}
|
||||
return NextEditProvider.instance;
|
||||
}
|
||||
|
||||
public addDiffToContext(diff: string): void {
|
||||
this.diffContext = diff;
|
||||
}
|
||||
|
||||
private async _prepareLlm(): Promise<ILLM | undefined> {
|
||||
const llm = await this._injectedGetLlm();
|
||||
|
||||
|
|
@ -206,6 +243,7 @@ export class NextEditProvider {
|
|||
snippetPayload,
|
||||
this.ide,
|
||||
helper,
|
||||
this.diffContext,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue