Skip to content

Commit

Permalink
fix(chat): Hide insert and new file buttons if there is no edit cap…
Browse files Browse the repository at this point in the history
…ability (#6018)

Currently all clients default to showing the Insert and New file buttons
on code snippets in an assistant response, but only editors which
support the `edit` capability (i.e. not Eclipse or VS) should show these
buttons. This simply hides the action if the capability is not set to
`enabled`.

## Test plan
Tested this build in Eclipse and saw that only the Copy button was
retained, but on main, all three buttons were shown

## Changelog
Hide non-functional edit buttons in chat if client does not support the
functionality.
  • Loading branch information
jamesmcnamara authored Oct 28, 2024
1 parent 7adae4b commit ecd0212
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions vscode/src/chat/chat-view/ChatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
return this.extensionClient.capabilities?.edit !== 'none'
}

private hasEditCapability(): boolean {
return this.extensionClient.capabilities?.edit === 'enabled' ?? false
}

private featureCodyExperimentalOneBox = storeLastValue(
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.CodyExperimentalOneBox)
)
Expand All @@ -514,6 +518,7 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
serverEndpoint: auth.serverEndpoint,
experimentalNoodle: configuration.experimentalNoodle,
smartApply: this.isSmartApplyEnabled(),
hasEditCapability: this.hasEditCapability(),
webviewType,
multipleWebviewsEnabled: !sidebarViewOnly,
internalDebugContext: configuration.internalDebugContext,
Expand Down
1 change: 1 addition & 0 deletions vscode/src/chat/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export interface ConfigurationSubsetForWebview
extends Pick<ClientConfiguration, 'experimentalNoodle' | 'internalDebugContext'>,
Pick<AuthCredentials, 'serverEndpoint'> {
smartApply: boolean
hasEditCapability: boolean
// Type/location of the current webview.
webviewType?: WebviewType | undefined | null
// Whether support running multiple webviews (e.g. sidebar w/ multiple editor panels).
Expand Down
1 change: 1 addition & 0 deletions vscode/webviews/App.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const dummyVSCodeAPI: VSCodeWrapper = {
uiKindIsWeb: false,
experimentalNoodle: false,
smartApply: false,
hasEditCapability: false,
},
clientCapabilities: CLIENT_CAPABILITIES_FIXTURE,
authStatus: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ export const ChatMessageContent: React.FunctionComponent<ChatMessageContentProps
config,
codeBlockName,
copyButtonOnSubmit,
insertButtonOnSubmit,
config.config.hasEditCapability ? insertButtonOnSubmit : undefined,
smartApplyInterceptor,
smartApplyId,
smartApplyState
)
} else {
buttons = createButtons(preText, copyButtonOnSubmit, insertButtonOnSubmit)
buttons = createButtons(
preText,
copyButtonOnSubmit,
config.config.hasEditCapability ? insertButtonOnSubmit : undefined
)
}

const metadataContainer = document.createElement('div')
Expand Down

0 comments on commit ecd0212

Please sign in to comment.