Skip to content

Commit

Permalink
fix execution of first command if twinny sidebar not visible
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmacarthy committed Jan 3, 2024
1 parent 92b458b commit ffcf21e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,12 @@ export async function deleteTempFiles() {
return
}
}

export const delayExecution = <T extends () => void>(
fn: T,
delay = 200
): NodeJS.Timeout => {
return setTimeout(() => {
fn()
}, delay)
}

0 comments on commit ffcf21e

Please sign in to comment.