Skip to content

Commit

Permalink
remove fixup command handling from refactor menu (#766)
Browse files Browse the repository at this point in the history
RE: #765

#510 (comment)
added the nested commands to the `Refactor Menu` with menu title `Cody`
that is similar to the `Cody Commands Menu` which has been causing a lot
of confusion.

There are follow-up works that @umpox has planned for, but before those
are completed, I proposed the following in this PR:
- remove the nested commands from the refactor menu
- rename the refactor menu from `Cody` to `Cody: Refactor Code` to avoid
confusion
- replace placeholder text for the refactor menu from `Tell Cody what to
do, or type '/' for commands` to `Enter your refactoring instruction
here...`

## Test plan

<!-- Required. See
https://docs.sourcegraph.com/dev/background-information/testing_principles.
-->

### Before


![image](https://github.com/sourcegraph/cody/assets/68532117/a34eed35-24c4-456d-b785-e1e886caf787)


### After


![image](https://github.com/sourcegraph/cody/assets/68532117/57d49521-e3b2-43dc-b71d-89ef36320a3c)


![refactormenu](https://github.com/sourcegraph/cody/assets/68532117/0e4bc151-a41a-47fe-9a33-dc3272a1c3b0)

---------

Co-authored-by: Tim Lucas <t@toolmantim.com>
  • Loading branch information
abeatrix and toolmantim committed Aug 21, 2023
1 parent 5239ebe commit 9753dc9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 66 deletions.
1 change: 1 addition & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi
- Cody Commands: Don't require Esc to dismiss Cody menu. [pull/700](https://github.com/sourcegraph/cody/pull/700)
- Updated welcome chat words. [pull/748](https://github.com/sourcegraph/cody/pull/748)
- Autocomplete: Reduce network bandwidth with requests are resolved by previous responses. [pull/762](https://github.com/sourcegraph/cody/pull/762)
- Fixup: Remove `/document` and other command handling from the Refactor Menu. [pull/766](https://github.com/sourcegraph/cody/pull/766)

## [0.6.7]

Expand Down
70 changes: 6 additions & 64 deletions vscode/src/non-stop/FixupTypingUI.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,26 @@
import * as vscode from 'vscode'

import { FixupIntent } from '@sourcegraph/cody-shared/src/chat/recipes/fixup'
import { menu_buttons } from '../custom-prompts/utils/menu'

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: Refactor Code',
placeholder = 'Enter your refactoring instruction here...',
value = '',
prefix = '',
prefix = '/fix',
} = {}): Promise<string> {
const quickPick = vscode.window.createQuickPick()
quickPick.title = title
quickPick.placeholder = placeholder
quickPick.buttons = [{ tooltip: 'Cody', iconPath: new vscode.ThemeIcon('cody-logo-heavy') }]
quickPick.ignoreFocusOut = true
quickPick.buttons = [menu_buttons.back]
quickPick.value = value

// VS Code automatically sorts quick pick items by label.
Expand All @@ -65,36 +29,14 @@ export class FixupTypingUI {
;(quickPick as any).sortByLabel = false

quickPick.onDidTriggerButton(() => {
void vscode.commands.executeCommand('cody.focus')
void vscode.commands.executeCommand('cody.action.commands.menu')
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
2 changes: 1 addition & 1 deletion vscode/test/e2e/fixup-decorator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('decorations from un-applied Cody changes appear', async ({ page, sidebar }
await page.getByRole('option', { name: 'Refactor This Code' }).click()

// Wait for the input box to appear
await page.getByPlaceholder("Tell Cody what to do, or type '/' for commands").click()
await page.getByPlaceholder('Enter your refactoring instruction here...').click()
// Type in the instruction for fixup
await page.keyboard.type('replace hello with goodbye')
// Press enter to submit the fixup
Expand Down
2 changes: 1 addition & 1 deletion vscode/test/e2e/task-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('task tree view for non-stop cody', async ({ page, sidebar }) => {
await page.getByRole('option', { name: 'Refactor This Code' }).click()

// Wait for the input box to appear
await page.getByPlaceholder("Tell Cody what to do, or type '/' for commands").click()
await page.getByPlaceholder('Enter your refactoring instruction here...').click()
// Type in the instruction for fixup
await page.keyboard.type('replace hello with goodbye')
// Press enter to submit the fixup
Expand Down

0 comments on commit 9753dc9

Please sign in to comment.