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

fix: custom command in context menu #1123

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi

- Fix a potential race condition for autocomplete requests that happen when a completion is stored as the last shown candidate when it will not be shown. [pull/1059](https://github.com/sourcegraph/cody/pull/1059)
- Use `insert` instead of `replace` for `Insert at Cursor` button for inserting code to current cursor position. [pull/1118](https://github.com/sourcegraph/cody/pull/1118)
- Fix issue that caused the custom commands menu to unable to execute commands. [pull/1123](https://github.com/sourcegraph/cody/pull/1123)

### Changed

Expand Down
48 changes: 30 additions & 18 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
{
"command": "cody.command.smell-code",
"category": "Ask Cody",
"title": "Smell Code"
"title": "Find Code Smells"
},
{
"command": "cody.command.context-search",
Expand Down Expand Up @@ -371,7 +371,7 @@
},
{
"command": "cody.inline.new",
"title": "Start New Thread",
"title": "Ask Cody Inline",
"category": "Cody Inline Chat",
"when": "cody.activated && config.cody.inlineChat.enabled",
"enablement": "editorFocus"
Expand Down Expand Up @@ -433,8 +433,8 @@
},
{
"command": "cody.action.commands.custom.menu",
"category": "Cody",
"title": "Custom Commands (Experimental)",
"category": "Ask Cody",
"title": "Custom Commands",
"when": "cody.activated",
"icon": "$(bookmark)"
},
Expand All @@ -459,7 +459,7 @@
"mac": "alt+/"
},
{
"command": "cody.fixup.new",
"command": "cody.command.edit-code",
"key": "ctrl+shift+v",
"mac": "shift+cmd+v",
"when": "cody.activated && !editorReadonly"
Expand Down Expand Up @@ -502,27 +502,27 @@
"commandPalette": [
{
"command": "cody.command.explain-code",
"when": "cody.activated"
"when": "false"
},
{
"command": "cody.command.context-search",
"when": "cody.activated"
"when": "false"
},
{
"command": "cody.command.inline-touch",
"when": "false"
},
{
"command": "cody.command.smell-code",
"when": "cody.activated"
"when": "false"
},
{
"command": "cody.command.generate-tests",
"when": "cody.activated"
"when": "false"
},
{
"command": "cody.command.document-code",
"when": "cody.activated"
"when": "false"
},
{
"command": "cody.focus",
Expand Down Expand Up @@ -587,35 +587,47 @@
"cody.submenu": [
{
"command": "cody.command.explain-code",
"when": "cody.activated"
"when": "cody.activated",
"group": "command"
},
{
"command": "cody.command.edit-code",
"when": "cody.activated"
"when": "cody.activated",
"group": "ask"
},
{
"command": "cody.command.generate-tests",
"when": "cody.activated"
"when": "cody.activated",
"group": "command"
},
{
"command": "cody.command.document-code",
"when": "cody.activated"
"when": "cody.activated",
"group": "command"
},
{
"command": "cody.command.smell-code",
"when": "cody.activated"
"when": "cody.activated",
"group": "command"
},
{
"command": "cody.action.commands.custom.menu",
"when": "cody.activated"
"when": "cody.activated",
"group": "command"
},
{
"command": "cody.focus",
"when": "!cody.activated"
"when": "!cody.activated",
"group": "other"
},
{
"command": "cody.guardrails.debug",
"when": "cody.activated && config.cody.experimental.guardrails && editorHasSelection"
"when": "cody.activated && config.cody.experimental.guardrails && editorHasSelection",
"group": "other"
},
{
"command": "cody.inline.new",
"group": "ask"
}
],
"view/title": [
Expand Down
24 changes: 12 additions & 12 deletions vscode/src/custom-prompts/CommandsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,34 +303,34 @@ export class CommandsController implements VsCodeCommandsController, vscode.Disp
?.filter(command => command !== null && command?.[1]?.type !== 'default')
.map(commandItem => {
const command = commandItem[1]
const description = command.type
return createQuickPickItem(command.description || commandItem[0], description)
const description = commandItem[0]
return createQuickPickItem(command.description, description)
})

const configOption = menu_options.config
const addOption = menu_options.add

promptItems.push(menu_separators.settings, configOption, addOption)

// Show the list of prompts to the user using a quick pick
const selectedPrompt = await showCustomCommandMenu([...promptItems])
// Find the prompt based on the selected prompt name
const promptTitle = selectedPrompt?.label
if (!selectedPrompt || !promptTitle) {
const selected = await showCustomCommandMenu([...promptItems])
const commandKey = selected?.description

if (!selected || !commandKey) {
return
}

switch (promptTitle.length > 0) {
case promptTitle === addOption.label:
switch (commandKey.length > 0) {
case commandKey === addOption.label:
return await this.addNewUserCommandQuick()
case promptTitle === configOption.label:
case commandKey === configOption.label:
return await this.configMenu('custom')
default:
// Run the prompt
await vscode.commands.executeCommand('cody.action.commands.exec', promptTitle)
await vscode.commands.executeCommand('cody.action.commands.exec', commandKey)
break
}

logDebug('CommandsController:promptsQuickPicker:selectedPrompt', promptTitle)
logDebug('CommandsController:promptsQuickPicker:selectedPrompt', commandKey)
} catch (error) {
logError('CommandsController:promptsQuickPicker', 'error', { verbose: error })
}
Expand Down
12 changes: 10 additions & 2 deletions vscode/src/custom-prompts/menus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export async function showCommandMenu(

export async function showCustomCommandMenu(items: QuickPickItem[]): Promise<QuickPickItem> {
const CustomCommandsMenuOptions: QuickPickOptions = {
title: 'Cody Custom Commands (Experimental)',
title: 'Cody: Custom Commands (Experimental)',
placeHolder: 'Search command to run...',
}

Expand All @@ -140,11 +140,19 @@ export async function showCustomCommandMenu(items: QuickPickItem[]): Promise<Qui
quickPick.placeholder = CustomCommandsMenuOptions.placeHolder
quickPick.ignoreFocusOut = true

quickPick.buttons = [menu_buttons.back]

quickPick.onDidAccept(() => {
const selection = quickPick.activeItems[0]
resolve(selection)
quickPick.hide()
})

quickPick.onDidTriggerButton(async () => {
quickPick.hide()
await commands.executeCommand('cody.action.commands.menu')
})

quickPick.show()
})
}
Expand All @@ -154,7 +162,7 @@ export async function showCustomCommandMenu(items: QuickPickItem[]): Promise<Qui
*/
export async function showCommandConfigMenu(): Promise<CustomCommandsItem> {
const CustomCommandConfigMenuOptions = {
title: 'Configure Custom Commands (Experimental)',
title: 'Cody: Configure Custom Commands (Experimental)',
placeHolder: 'Choose an option',
}

Expand Down