diff --git a/src/extension.ts b/src/extension.ts index af10b5aa..82df006f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,7 +10,7 @@ import { import { CompletionProvider } from './providers/completion' import { init } from './init' import { SidebarProvider } from './providers/sidebar' -import { chatCompletion, deleteTempFiles } from './utils' +import { chatCompletion, delayExecution, deleteTempFiles } from './utils' export async function activate(context: ExtensionContext) { const config = workspace.getConfiguration('twinny') @@ -41,32 +41,31 @@ export async function activate(context: ExtensionContext) { commands.registerCommand('twinny.disable', () => { statusBar.hide() }), - window.registerWebviewViewProvider('twinny-sidebar', sidebarProvider), - statusBar - ) - - setTimeout(() => { commands.registerCommand('twinny.explain', () => { commands.executeCommand('workbench.view.extension.twinny-sidebar-view') - chatCompletion('explain', sidebarProvider.view) + delayExecution(() => chatCompletion('explain', sidebarProvider.view)) + }), + commands.registerCommand('twinny.addTypes', () => { + commands.executeCommand('workbench.view.extension.twinny-sidebar-view') + delayExecution(() => chatCompletion('add-types', sidebarProvider.view)) + }), + commands.registerCommand('twinny.refactor', () => { + commands.executeCommand('workbench.view.extension.twinny-sidebar-view') + delayExecution(() => chatCompletion('refactor', sidebarProvider.view)) }), - commands.registerCommand('twinny.addTypes', () => { - commands.executeCommand('workbench.view.extension.twinny-sidebar-view') - chatCompletion('add-types', sidebarProvider.view) - }), - commands.registerCommand('twinny.refactor', () => { - commands.executeCommand('workbench.view.extension.twinny-sidebar-view') - chatCompletion('refactor', sidebarProvider.view) - }), - commands.registerCommand('twinny.addTests', () => { - commands.executeCommand('workbench.view.extension.twinny-sidebar-view') - chatCompletion('add-tests', sidebarProvider.view) - }), - commands.registerCommand('twinny.generateDocs', () => { - commands.executeCommand('workbench.view.extension.twinny-sidebar-view') + commands.registerCommand('twinny.addTests', () => { + commands.executeCommand('workbench.view.extension.twinny-sidebar-view') + delayExecution(() => chatCompletion('add-tests', sidebarProvider.view)) + }), + commands.registerCommand('twinny.generateDocs', () => { + commands.executeCommand('workbench.view.extension.twinny-sidebar-view') + delayExecution(() => chatCompletion('generate-docs', sidebarProvider.view) - }) - }, 2000) + ) + }), + window.registerWebviewViewProvider('twinny-sidebar', sidebarProvider), + statusBar + ) if (config.get('enabled')) { statusBar.show() diff --git a/src/utils.ts b/src/utils.ts index 560c5da3..c09439d7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -125,3 +125,12 @@ export async function deleteTempFiles() { return } } + +export const delayExecution = void>( + fn: T, + delay = 200 +): NodeJS.Timeout => { + return setTimeout(() => { + fn() + }, delay) +}