Skip to content
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

remove fixup command handling from refactor menu #766

Merged
merged 6 commits into from
Aug 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 2 additions & 61 deletions vscode/src/non-stop/FixupTypingUI.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,17 @@
import * as vscode from 'vscode'

import { FixupIntent } from '@sourcegraph/cody-shared/src/chat/recipes/fixup'

import { FixupTask } from './FixupTask'
import { FixupTaskFactory } from './roles'

type FixupCommand = `/${FixupIntent}`
interface FixupQuickPickItem {
description: string
placeholder: string
/**
* Optional value to insert.
* Some commands (like /document) are self explanatory and a user might not want to write anything
**/
value?: string
}

const FixupCommands = new Map<FixupCommand, FixupQuickPickItem>([
[
'/fix',
{
description: 'Fix a problem in the selected code',
placeholder: 'Describe what you want Cody to fix',
value: 'Fix any problems in the selected code',
},
],
[
'/document',
{
description: 'Generate documentation or comments for the selected code',
placeholder: 'Describe what you want Cody to do',
value: 'Generate documentation or comments for the selected code',
},
],
])

const FixupQuickPickItems: vscode.QuickPickItem[] = [...FixupCommands].map(([command, item]) => ({
label: command,
...item,
}))

/**
* The UI for creating non-stop fixup tasks by typing instructions.
*/
export class FixupTypingUI {
constructor(private readonly taskFactory: FixupTaskFactory) {}

private async getInstructionFromQuickPick({
title = 'Cody',
placeholder = "Tell Cody what to do, or type '/' for commands",
title = 'Cody: Refactoring...',
abeatrix marked this conversation as resolved.
Show resolved Hide resolved
placeholder = 'Enter your refactoring instruction here...',
value = '',
prefix = '',
} = {}): Promise<string> {
Expand All @@ -69,32 +32,10 @@ export class FixupTypingUI {
quickPick.hide()
})

quickPick.onDidChangeValue(value => {
if (value.startsWith('/')) {
quickPick.items = FixupQuickPickItems
} else {
// We show no items by default
quickPick.items = []
}
})

quickPick.show()

return new Promise(resolve =>
quickPick.onDidAccept(() => {
const selectedItem = quickPick.selectedItems[0]?.label
const command = FixupCommands.get(selectedItem as FixupCommand)
if (command) {
return resolve(
this.getInstructionFromQuickPick({
title: `Cody - ${selectedItem}`,
placeholder: command.placeholder,
value: command.value,
prefix: selectedItem,
})
)
}

const instruction = quickPick.value.trim()
if (!instruction) {
// noop
Expand Down
Loading