Skip to content

Commit

Permalink
VS Code: use enablement for Cody commands (#4155)
Browse files Browse the repository at this point in the history
- The `when` configuration field is not applicable to commands:
    - To verify disable autocomplete and observe that all autocomplete commands are still visible in the command list.
    - The related JSON schema in VS Code sources confirms this: https://github.com/microsoft/vscode/blob/29aeab1cbb350107a7bd5962b5e7efe745e0a3ec/src/vs/workbench/services/actions/common/menusExtensionPoint.ts#L729-L773. The `when` field is missing. Only `enablement` is specified.
    - The VS Code document is misleading: https://code.visualstudio.com/api/extension-guides/command#controlling-when-a-command-shows-up-in-the-command-palette
- This PR changes all `when` fields to `enablement` to hide Cody commands under certain conditions.
    - **Design input required**: we use `"cody.activated && editorTextFocus"` in multiple places. It does nothing in the current version of the extension, but with the `enablement` field, it hides the respective command from the quick pick menu (shift+command+P) even when it's opened from the editor. Technically, the editor is not focused anymore; the quick menu is. So this configuration can be treated as: "the command will be hidden from the commands list, but will be available via keybindings if `editorTextFocus`".
    - Related discussion: microsoft/vscode#124755.
  • Loading branch information
valerybugakov committed May 13, 2024
1 parent 15c2357 commit 69aec78
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
66 changes: 33 additions & 33 deletions vscode/package.json
Expand Up @@ -285,62 +285,62 @@
"command": "cody.command.edit-code",
"category": "Cody Command",
"title": "Edit Code",
"when": "cody.activated && editorTextFocus",
"enablement": "cody.activated",
"icon": "$(wand)"
},
{
"command": "cody.command.explain-code",
"category": "Cody Command",
"title": "Explain Code",
"icon": "$(output)",
"when": "cody.activated && editorFocus"
"enablement": "cody.activated"
},
{
"command": "cody.command.unit-tests",
"category": "Cody Command",
"title": "Generate Unit Tests",
"icon": "$(package)",
"when": "cody.activated && editorTextFocus"
"enablement": "cody.activated"
},
{
"command": "cody.command.document-code",
"category": "Cody Command",
"title": "Document Code",
"icon": "$(book)",
"when": "cody.activated && editorTextFocus"
"enablement": "cody.activated"
},
{
"command": "cody.command.smell-code",
"category": "Cody Command",
"title": "Find Code Smells",
"icon": "$(checklist)",
"when": "cody.activated && editorFocus"
"enablement": "cody.activated"
},
{
"command": "cody.menu.custom-commands",
"category": "Cody Menu",
"title": "Custom Commands",
"icon": "$(tools)",
"when": "cody.activated && workspaceFolderCount > 0"
"enablement": "cody.activated && workspaceFolderCount > 0"
},
{
"command": "cody.menu.commands-settings",
"category": "Cody Settings",
"title": "Custom Commands Settings",
"icon": "$(gear)",
"when": "cody.activated"
"enablement": "cody.activated"
},
{
"command": "cody.command.usageExamples",
"category": "Cody Command",
"title": "Usage Examples",
"when": "cody.activated && editorTextFocus && config.cody.experimental.noodle && (editorLangId === typescript || editorLangId === typescriptreact)"
"enablement": "cody.activated && config.cody.experimental.noodle && (editorLangId === typescript || editorLangId === typescriptreact)"
},
{
"command": "cody.command.explain-history",
"category": "Cody Command",
"title": "Explain Code History",
"when": "cody.activated && editorTextFocus && config.cody.experimental.noodle"
"enablement": "cody.activated && config.cody.experimental.noodle"
},
{
"command": "cody.auth.signout",
Expand Down Expand Up @@ -378,21 +378,21 @@
"title": "Cody Settings",
"group": "Cody",
"icon": "$(settings-gear)",
"when": "cody.activated"
"enablement": "cody.activated"
},
{
"command": "cody.show-page",
"category": "Cody",
"title": "Open Account Page",
"group": "Cody",
"when": "cody.activated"
"enablement": "cody.activated"
},
{
"command": "cody.show-rate-limit-modal",
"category": "Cody",
"title": "Show Rate Limit Modal",
"group": "Cody",
"when": "cody.activated"
"enablement": "cody.activated"
},
{
"command": "cody.guardrails.debug",
Expand All @@ -404,40 +404,40 @@
"command": "cody.menu.commands",
"category": "Cody Menu",
"title": "Cody Commands",
"when": "cody.activated",
"enablement": "cody.activated",
"icon": "$(cody-logo)"
},
{
"command": "cody.autocomplete.openTraceView",
"category": "Cody",
"title": "Open Autocomplete Trace View",
"when": "cody.activated && config.cody.autocomplete && editorHasFocus && !editorReadonly"
"enablement": "cody.activated && config.cody.autocomplete.enabled"
},
{
"command": "cody.autocomplete.manual-trigger",
"category": "Cody",
"title": "Trigger Autocomplete at Cursor",
"when": "cody.activated && config.cody.autocomplete && editorHasFocus && !editorReadonly && !editorHasSelection && !inlineSuggestionsVisible"
"enablement": "cody.activated && config.cody.autocomplete.enabled && !editorReadonly && !editorHasSelection && !inlineSuggestionsVisible"
},
{
"command": "cody.multi-model-autocomplete.manual-trigger",
"category": "Cody",
"title": "Get Completions for multiple autocomplete models",
"when": "cody.activated && config.cody.autocomplete.experimental.multiModelCompletions && config.cody.autocomplete && editorHasFocus && !editorReadonly && !editorHasSelection && !inlineSuggestionsVisible"
"enablement": "cody.activated && config.cody.autocomplete.experimental.multiModelCompletions && config.cody.autocomplete.enabled && !editorReadonly && !editorHasSelection && !inlineSuggestionsVisible"
},
{
"command": "cody.chat.panel.new",
"category": "Cody",
"title": "New Chat",
"when": "cody.activated",
"enablement": "cody.activated",
"group": "Cody",
"icon": "$(new-comment-icon)"
},
{
"command": "workbench.action.moveEditorToNewWindow",
"category": "Cody",
"title": "Pop out",
"when": "cody.activated",
"enablement": "cody.activated",
"group": "Cody",
"icon": "$(link-external)"
},
Expand All @@ -454,92 +454,92 @@
"title": "Rename Chat",
"group": "Cody",
"icon": "$(edit)",
"when": "cody.activated && cody.hasChatHistory"
"enablement": "cody.activated && cody.hasChatHistory"
},
{
"command": "cody.chat.history.clear",
"category": "Cody",
"title": "Delete All Chats",
"group": "Cody",
"icon": "$(trash)",
"when": "cody.activated && cody.hasChatHistory"
"enablement": "cody.activated && cody.hasChatHistory"
},
{
"command": "cody.chat.history.delete",
"category": "Cody",
"title": "Delete Chat",
"group": "Cody",
"icon": "$(trash)",
"when": "cody.activated && cody.hasChatHistory"
"enablement": "cody.activated && cody.hasChatHistory"
},
{
"command": "cody.chat.history.export",
"category": "Cody",
"title": "Export Chats as JSON",
"group": "Cody",
"icon": "$(arrow-circle-down)",
"when": "cody.activated && cody.hasChatHistory"
"enablement": "cody.activated && cody.hasChatHistory"
},
{
"command": "cody.chat.history.panel",
"category": "Cody",
"title": "Chat History",
"group": "Cody",
"icon": "$(list-unordered)",
"when": "cody.activated && cody.hasChatHistory"
"enablement": "cody.activated && cody.hasChatHistory"
},
{
"command": "cody.search.index-update",
"category": "Cody",
"group": "Cody",
"title": "Update search index for current workspace folder",
"icon": "$(refresh)",
"when": "cody.activated"
"enablement": "cody.activated"
},
{
"command": "cody.mention.selection",
"category": "Cody",
"group": "Chat",
"title": "Add Selection to Cody Chat",
"icon": "$(mention)",
"when": "cody.activated && editorHasSelection && !explorerViewletFocus && cody.hasNewChatOpened"
"enablement": "cody.activated && editorHasSelection && !explorerViewletFocus && cody.hasNewChatOpened"
},
{
"command": "cody.mention.selection.new",
"category": "Cody",
"group": "Chat",
"title": "New Chat with Selection",
"icon": "$(mention)",
"when": "cody.activated && editorHasSelection && !explorerViewletFocus && !cody.hasNewChatOpened"
"enablement": "cody.activated && editorHasSelection && !explorerViewletFocus && !cody.hasNewChatOpened"
},
{
"command": "cody.mention.file",
"category": "Cody",
"group": "Chat",
"title": "Add File to Cody Chat",
"icon": "$(mention)",
"when": "cody.activated && resourceScheme == file && cody.hasNewChatOpened"
"enablement": "cody.activated && resourceScheme == file && cody.hasNewChatOpened"
},
{
"command": "cody.mention.file.new",
"category": "Cody",
"group": "Chat",
"title": "New Chat with File",
"icon": "$(mention)",
"when": "cody.activated && resourceScheme == file && !cody.hasNewChatOpened"
"enablement": "cody.activated && resourceScheme == file && !cody.hasNewChatOpened"
},
{
"command": "cody.chat.panel.reset",
"category": "Cody",
"title": "New Chat Session",
"group": "Cody",
"icon": "$(clear-all)",
"when": "cody.activated && cody.hasChatHistory"
"enablement": "cody.activated && cody.hasChatHistory"
},
{
"command": "cody.embeddings.resolveIssue",
"title": "Cody Embeddings",
"when": "cody.embeddings.hasIssue"
"enablement": "cody.activated && cody.embeddings.hasIssue"
},
{
"command": "cody.debug.export.logs",
Expand All @@ -558,7 +558,7 @@
"category": "Cody Debug",
"group": "Debug",
"title": "Enable Debug Mode",
"when": "!config.cody.debug.verbose"
"enablement": "!config.cody.debug.verbose"
},
{
"command": "cody.debug.reportIssue",
Expand All @@ -579,12 +579,12 @@
"group": "Search",
"icon": "$(search)",
"title": "Natural Language Search Code (Beta)",
"when": "cody.activated && workspaceFolderCount > 0"
"enablement": "cody.activated && workspaceFolderCount > 0"
},
{
"command": "cody.test.set-context-filters",
"title": "[Internal] Set Context Filters Overwrite",
"when": "cody.activated && cody.devOrTest"
"enablement": "cody.activated && cody.devOrTest"
}
],
"keybindings": [
Expand Down
Expand Up @@ -83,13 +83,13 @@ export async function createInlineCompletionItemFromMultipleProviders({
const disposables: vscode.Disposable[] = []

const multiModelConfigsList: MultimodelSingleModelConfig[] = []
for (const curretProviderConfig of config.autocompleteExperimentalMultiModelCompletions) {
if (curretProviderConfig.provider && curretProviderConfig.model) {
for (const currentProviderConfig of config.autocompleteExperimentalMultiModelCompletions) {
if (currentProviderConfig.provider && currentProviderConfig.model) {
multiModelConfigsList.push({
provider: curretProviderConfig.provider,
model: curretProviderConfig.model,
provider: currentProviderConfig.provider,
model: currentProviderConfig.model,
enableExperimentalFireworksOverrides:
curretProviderConfig.enableExperimentalFireworksOverrides ?? false,
currentProviderConfig.enableExperimentalFireworksOverrides ?? false,
})
}
}
Expand All @@ -100,13 +100,13 @@ export async function createInlineCompletionItemFromMultipleProviders({
}
}

const allPromises = multiModelConfigsList.map(async curretProviderConfig => {
const allPromises = multiModelConfigsList.map(async currentProviderConfig => {
const newConfig = _.cloneDeep(config)
// Override some config to ensure we are not logging extra events.
newConfig.telemetryLevel = 'off'
// We should only override the fireworks "cody.autocomplete.experimental.fireworksOptions" when added in the config.
newConfig.autocompleteExperimentalFireworksOptions =
curretProviderConfig.enableExperimentalFireworksOverrides
currentProviderConfig.enableExperimentalFireworksOverrides
? config.autocompleteExperimentalFireworksOptions
: undefined
// Don't use the advanced provider config to get the model
Expand All @@ -115,8 +115,8 @@ export async function createInlineCompletionItemFromMultipleProviders({
const providerConfig = await createProviderConfigFromVSCodeConfig(
client,
authStatus,
curretProviderConfig.model,
curretProviderConfig.provider,
currentProviderConfig.model,
currentProviderConfig.provider,
newConfig
)
if (providerConfig) {
Expand All @@ -135,8 +135,8 @@ export async function createInlineCompletionItemFromMultipleProviders({
noInlineAccept: true,
})
return {
providerName: curretProviderConfig.provider,
modelName: curretProviderConfig.model,
providerName: currentProviderConfig.provider,
modelName: currentProviderConfig.model,
completionsProvider: completionsProvider,
}
}
Expand Down

0 comments on commit 69aec78

Please sign in to comment.