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(auto-edit): fix the cody status bar with new suggestion mode #6691

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 0 additions & 7 deletions vscode/src/autoedits/create-autoedits-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ export function isUserEligibleForAutoeditsFeature(
authStatus: AuthStatus,
productSubscription: UserProductSubscription | null
): AutoeditsUserEligibilityInfo {
console.log({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY

autoeditsFeatureFlagEnabled,
isTesting: process.env.CODY_TESTING === 'true',
isRunningInsideAgent: isRunningInsideAgent(),
isFreeUser: isFreeUser(authStatus, productSubscription),
})

// Always enable auto-edit when testing
if (process.env.CODY_TESTING === 'true') {
return { isUserEligible: true }
Expand Down
120 changes: 97 additions & 23 deletions vscode/src/services/StatusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@ import * as vscode from 'vscode'
import {
type AuthStatus,
type ClientConfiguration,
CodyAutoSuggestionMode,
CodyIDE,
FeatureFlag,
InvisibleStatusBarTag,
type IsIgnored,
Mutable,
type ResolvedConfiguration,
type UserProductSubscription,
assertUnreachable,
authStatus,
combineLatest,
contextFiltersProvider,
currentUserProductSubscription,
distinctUntilChanged,
featureFlagProvider,
firstValueFrom,
fromVSCodeEvent,
logError,
promise,
promiseFactoryToObservable,
resolvedConfig,
shareReplay,
} from '@sourcegraph/cody-shared'

import { type Subscription, map } from 'observable-fns'
import type { LiteralUnion, ReadonlyDeep } from 'type-fest'
import { isUserEligibleForAutoeditsFeature } from '../autoedits/create-autoedits-provider'
import { getGhostHintEnablement } from '../commands/GhostHintDecorator'
import { getReleaseNotesURLByIDE } from '../release'
import { version } from '../version'
Expand Down Expand Up @@ -82,7 +88,9 @@ export class CodyStatusBar implements vscode.Disposable {
resolvedConfig,
this.errors.changes,
this.loaders.changes,
this.ignoreStatus
this.ignoreStatus,
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.CodyAutoEditExperimentEnabledFeatureFlag),
promiseFactoryToObservable(async () => await currentUserProductSubscription())
).pipe(
map((combined): StatusBarState | undefined => {
return {
Expand Down Expand Up @@ -258,7 +266,9 @@ export class CodyStatusBar implements vscode.Disposable {
config: ResolvedConfiguration,
errors: ReadonlySet<StatusBarError>,
loaders: ReadonlySet<StatusBarLoader>,
ignoreStatus: IsIgnored
ignoreStatus: IsIgnored,
autoeditsFeatureFlagEnabled: boolean,
userProductSubscription: UserProductSubscription | null
): Partial<StatusBarState> & Pick<StatusBarState, 'interact' | 'tooltip'> {
const tags = new Set<InvisibleStatusBarTag>()

Expand Down Expand Up @@ -319,6 +329,9 @@ export class CodyStatusBar implements vscode.Disposable {
config,
errors,
isIgnored: ignoreStatus,
autoeditsFeatureFlagEnabled,
userProductSubscription,
authStatus,
}),
}
}
Expand Down Expand Up @@ -356,6 +369,9 @@ export class CodyStatusBar implements vscode.Disposable {
config,
errors,
isIgnored: ignoreStatus,
autoeditsFeatureFlagEnabled,
userProductSubscription,
authStatus,
}),
}
}
Expand All @@ -371,6 +387,9 @@ export class CodyStatusBar implements vscode.Disposable {
config,
errors,
isIgnored: ignoreStatus,
autoeditsFeatureFlagEnabled,
userProductSubscription,
authStatus,
}),
}
}
Expand All @@ -381,6 +400,9 @@ export class CodyStatusBar implements vscode.Disposable {
config,
errors,
isIgnored: ignoreStatus,
autoeditsFeatureFlagEnabled,
userProductSubscription,
authStatus,
}),
}
}
Expand All @@ -406,9 +428,17 @@ function interactDefault({
config,
errors,
isIgnored,
}: { config: ResolvedConfiguration; errors: ReadonlySet<StatusBarError>; isIgnored: IsIgnored }): (
abort: AbortSignal
) => Promise<void> {
autoeditsFeatureFlagEnabled,
userProductSubscription,
authStatus,
}: {
config: ResolvedConfiguration
errors: ReadonlySet<StatusBarError>
isIgnored: IsIgnored
autoeditsFeatureFlagEnabled: boolean
userProductSubscription: UserProductSubscription | null
authStatus: AuthStatus
}): (abort: AbortSignal) => Promise<void> {
return async (abort: AbortSignal) => {
const [interactionDone] = promise<void>()
// this QuickPick could probably be made reactive but that's a bit overkill.
Expand Down Expand Up @@ -436,6 +466,9 @@ function interactDefault({
config.configuration,
vscode.workspace.getConfiguration()
)
const createFeatureEnumChoice = featureCodySuggestionEnumBuilder(
vscode.workspace.getConfiguration()
)

quickPick.items = [
// These description should stay in sync with the settings in package.json
Expand All @@ -461,23 +494,12 @@ function interactDefault({
]
: []),
{ label: 'enable/disable features', kind: vscode.QuickPickItemKind.Separator },
await 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,
]
await createFeatureEnumChoice(
'Cody Suggestion Mode',
'Choose how Cody suggests inline code changes',
autoeditsFeatureFlagEnabled,
userProductSubscription,
authStatus
),
await createFeatureToggle(
'Code Actions',
Expand Down Expand Up @@ -571,6 +593,58 @@ function interactDefault({
}
}

function featureCodySuggestionEnumBuilder(workspaceConfig: vscode.WorkspaceConfiguration) {
return async (
name: string,
detail: string,
autoeditsFeatureFlagEnabled: boolean,
userProductSubscription: UserProductSubscription | null,
authStatus: AuthStatus
): Promise<StatusBarItem> => {
const suggestionModeKey = 'cody.suggestions.mode'

const currentValue =
(await workspaceConfig.get<CodyAutoSuggestionMode>(suggestionModeKey)) ??
CodyAutoSuggestionMode.Autocomplete

const { isUserEligible } = isUserEligibleForAutoeditsFeature(
autoeditsFeatureFlagEnabled,
authStatus,
userProductSubscription
)
const requiredValues = isUserEligible
? [
CodyAutoSuggestionMode.Autocomplete,
CodyAutoSuggestionMode.Autoedit,
CodyAutoSuggestionMode.Off,
]
: [CodyAutoSuggestionMode.Autocomplete, CodyAutoSuggestionMode.Off]

// Show the current choice in the label.
const label = `${QUICK_PICK_ITEM_EMPTY_INDENT_PREFIX}${name} (Current: “${currentValue}”)`

return {
label,
detail: QUICK_PICK_ITEM_EMPTY_INDENT_PREFIX + detail,
async onSelect() {
// Show a QuickPick for the user to choose a new value.
const selection = await vscode.window.showQuickPick(requiredValues, {
placeHolder: `Current: “${currentValue}”. Pick a new mode...`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @toolmantim
I wanted to get your review on these string that we are showing to the user on the UI. Do you think these look okay or we should change them to something else ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how they currently look in the UI:

image image

Copy link
Contributor

@toolmantim toolmantim Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the existing settings in the "enable/disable features" are boolean… I think instead we add this in a section above it @hitesh-1997 & @umpox:

section label: "code suggestion settings"
icon: code (unless you find something better)
title: "Code Suggestion Mode (${current})"
description: "Choose how Cody suggests inline code changes"

q: Have we dropped the cog right hand action, for configuring autocomplete file types? We could add it to the next quickpick where you choose…

placeholder: "Choose an option"
section label: options
options:

  • title: "Autocomplete"
    description: "Suggest code completions for the rest of the line or block"
  • title: "Auto-edit"
    description: "Suggest additions, changes and deletions around cursor based on file changes"
  • title: Disabled
    description: "No code suggestions"

If autocomplete is enabled, add this extra section:

section label: settings

  • title: "Autocomplete Settings"
    description: "Open Cody autocomplete settings"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @toolmantim
Would it be possible to add a quick design snapshot ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the response @toolmantim
The new design looks really good, implemented the same :)

})
if (!selection) {
return
}
await workspaceConfig.update(
suggestionModeKey,
selection as CodyAutoSuggestionMode,
vscode.ConfigurationTarget.Global
)
vscode.window.showInformationMessage(`${name} is set to “${selection}”.`)
},
}
}
}

function featureToggleBuilder(
config: ReadonlyDeep<ClientConfiguration>,
workspaceConfig: vscode.WorkspaceConfiguration
Expand Down
Loading