Skip to content

Commit

Permalink
Autocomplete: Add button to quickly expose Autocomplete options to st…
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-spiess authored Feb 6, 2024
1 parent f0c4933 commit a529827
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 88 deletions.
1 change: 1 addition & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This is a log of all notable changes to Cody for VS Code. [Unreleased] changes a
- [Internal] Command: Added new code lenses for generating additional unit tests. [pull/2959](https://github.com/sourcegraph/cody/pull/2959)
- Edit: Added Cody Pro support for models: GPT-4, GPT-3.5, Claude 2.1 and Claude Instant. [pull/2951](https://github.com/sourcegraph/cody/pull/2951)
- Edit: Added a multi-model selector to the Edit input, allowing quick access to change the Edit LLM. [pull/2951](https://github.com/sourcegraph/cody/pull/2951)
- Autocomplete: Added a shortcut to go to the Autocomplete settings from the Cody Settings overlay. [pull/3048(https://github.com/sourcegraph/cody/pull/3048)

### Fixed

Expand Down
199 changes: 111 additions & 88 deletions vscode/src/services/StatusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const ONE_HOUR = 60 * 60 * 1000

type StatusBarErrorName = 'auth' | 'RateLimitError' | 'AutoCompleteDisabledByAdmin'

interface StatusBarItem extends vscode.QuickPickItem {
onSelect: () => Promise<void>
}

export function createStatusBar(): CodyStatusBar {
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right)
statusBarItem.text = DEFAULT_TEXT
Expand All @@ -48,8 +52,9 @@ export function createStatusBar(): CodyStatusBar {
detail: string,
setting: string,
getValue: (config: Configuration) => boolean,
requiresReload = false
): vscode.QuickPickItem & { onSelect: () => Promise<void> } {
requiresReload = false,
buttons: readonly vscode.QuickInputButton[] | undefined = undefined
): StatusBarItem {
const isEnabled = getValue(config)
return {
label:
Expand All @@ -69,103 +74,121 @@ export function createStatusBar(): CodyStatusBar {
await vscode.commands.executeCommand('workbench.action.reloadWindow')
}
},
buttons,
}
}

if (errors.length > 0) {
errors.map(error => error.error.onShow?.())
}

const option = await vscode.window.showQuickPick(
const quickPick = vscode.window.createQuickPick()
quickPick.items = [
// These description should stay in sync with the settings in package.json
[
...(errors.length > 0
? [
{ label: 'notice', kind: vscode.QuickPickItemKind.Separator },
...errors.map(error => ({
label: `$(alert) ${error.error.title}`,
description: '',
detail: QUICK_PICK_ITEM_EMPTY_INDENT_PREFIX + error.error.description,
onSelect(): Promise<void> {
error.error.onSelect?.()
const index = errors.indexOf(error)
errors.splice(index)
rerender()
return Promise.resolve()
},
})),
]
: []),
{ label: 'enable/disable features', kind: vscode.QuickPickItemKind.Separator },
createFeatureToggle(
'Code Autocomplete',
undefined,
'Enable Cody-powered code autocompletions',
'cody.autocomplete.enabled',
c => c.autocomplete
),
createFeatureToggle(
'Code Actions',
undefined,
'Enable Cody fix and explain options in the Quick Fix menu',
'cody.codeActions.enabled',
c => c.codeActions
),
createFeatureToggle(
'Editor Title Icon',
undefined,
'Enable Cody to appear in editor title menu for quick access to Cody commands',
'cody.editorTitleCommandIcon',
c => c.editorTitleCommandIcon
),
createFeatureToggle(
'Code Lenses',
undefined,
'Enable Code Lenses in documents for quick access to Cody commands',
'cody.commandCodeLenses',
c => c.commandCodeLenses
),
createFeatureToggle(
'Command Hints',
undefined,
'Enable hints for Edit and Chat shortcuts, displayed alongside editor selections',
'cody.commandHints.enabled',
c => c.commandHints
),
createFeatureToggle(
'Search Context',
'Beta',
'Enable using the natural language search index as an Enhanced Context chat source',
'cody.experimental.symfContext',
c => c.experimentalSymfContext,
false
),
{ label: 'settings', kind: vscode.QuickPickItemKind.Separator },
{
label: '$(gear) Cody Extension Settings',
async onSelect(): Promise<void> {
await vscode.commands.executeCommand('cody.settings.extension')
},
},
{
label: '$(symbol-namespace) Custom Commands Settings',
async onSelect(): Promise<void> {
await vscode.commands.executeCommand('cody.menu.commands-settings')
},
...(errors.length > 0
? [
{ label: 'notice', kind: vscode.QuickPickItemKind.Separator },
...errors.map(error => ({
label: `$(alert) ${error.error.title}`,
description: '',
detail: QUICK_PICK_ITEM_EMPTY_INDENT_PREFIX + error.error.description,
onSelect(): Promise<void> {
error.error.onSelect?.()
const index = errors.indexOf(error)
errors.splice(index)
rerender()
return Promise.resolve()
},
})),
]
: []),
{ label: 'enable/disable features', kind: vscode.QuickPickItemKind.Separator },
createFeatureToggle(
'Code Autocomplete',
undefined,
'Enable Cody-powered code autocompletions',
'cody.autocomplete.enabled',
c => c.autocomplete,
false,
[
{
iconPath: new vscode.ThemeIcon('settings-more-action'),
tooltip: 'Autocomplete Settings',
onClick: () =>
vscode.commands.executeCommand('workbench.action.openSettings', {
query: '@ext:sourcegraph.cody-ai autocomplete',
}),
} as vscode.QuickInputButton,
]
),
createFeatureToggle(
'Code Actions',
undefined,
'Enable Cody fix and explain options in the Quick Fix menu',
'cody.codeActions.enabled',
c => c.codeActions
),
createFeatureToggle(
'Editor Title Icon',
undefined,
'Enable Cody to appear in editor title menu for quick access to Cody commands',
'cody.editorTitleCommandIcon',
c => c.editorTitleCommandIcon
),
createFeatureToggle(
'Code Lenses',
undefined,
'Enable Code Lenses in documents for quick access to Cody commands',
'cody.commandCodeLenses',
c => c.commandCodeLenses
),
createFeatureToggle(
'Command Hints',
undefined,
'Enable hints for Edit and Chat shortcuts, displayed alongside editor selections',
'cody.commandHints.enabled',
c => c.commandHints
),
createFeatureToggle(
'Search Context',
'Beta',
'Enable using the natural language search index as an Enhanced Context chat source',
'cody.experimental.symfContext',
c => c.experimentalSymfContext,
false
),
{ label: 'settings', kind: vscode.QuickPickItemKind.Separator },
{
label: '$(gear) Cody Extension Settings',
async onSelect(): Promise<void> {
await vscode.commands.executeCommand('cody.settings.extension')
},
{ label: 'feedback & support', kind: vscode.QuickPickItemKind.Separator },
...FeedbackOptionItems,
],
},
{
title: 'Cody Settings',
placeHolder: 'Choose an option',
matchOnDescription: true,
label: '$(symbol-namespace) Custom Commands Settings',
async onSelect(): Promise<void> {
await vscode.commands.executeCommand('cody.menu.commands-settings')
},
},
{ label: 'feedback & support', kind: vscode.QuickPickItemKind.Separator },
...FeedbackOptionItems,
]
quickPick.title = 'Cody Settings'
quickPick.placeholder = 'Choose an option'
quickPick.matchOnDescription = true
quickPick.show()
quickPick.onDidAccept(() => {
const option = quickPick.activeItems[0] as StatusBarItem
if (option && 'onSelect' in option) {
option.onSelect().catch(console.error)
}
)

if (option && 'onSelect' in option) {
option.onSelect().catch(console.error)
}
quickPick.hide()
})
quickPick.onDidTriggerItemButton(item => {
// @ts-ignore: onClick is a custom extension to the QuickInputButton
item?.button?.onClick?.()
quickPick.hide()
})
})

// Reference counting to ensure loading states are handled consistently across different
Expand Down

0 comments on commit a529827

Please sign in to comment.