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

adding autoedits onboarding setup for dotcom users #6463

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,12 @@
"markdownDescription": "Enable hints for Cody commands such as \"Opt+K to Edit\" or \"Opt+D to Document\"",
"default": true
},
"cody.experimental.autoedits.enabled": {
"order": 99,
"type": "boolean",
"markdownDescription": "Enable Autoedit, an experimental feature which suggest smarter code edits as you type.",
"default": false
},
"cody.experimental.tracing": {
"order": 99,
"type": "boolean",
Expand Down
68 changes: 68 additions & 0 deletions vscode/src/autoedits/autoedit-onboarding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
FeatureFlag,
currentAuthStatus,
featureFlagProvider,
isDotComAuthed,
isS2,
} from '@sourcegraph/cody-shared'
import * as vscode from 'vscode'
import { isRunningInsideAgent } from './../jsonrpc/isRunningInsideAgent'

export async function showAutoeditOnboardingIfEligible(): Promise<void> {
// Determine if we should show the onboarding popup
if (!shouldShowAutoeditsOnboardingPopup()) {
return
}

const selection = await vscode.window.showInformationMessage(
'✨ Try Cody Autoedits - experimental feature which suggest smarter code edits as you type.',
'Enable Autoedits'
)

if (selection === 'Enable Autoedits') {
// Enable the setting programmatically
await vscode.workspace
.getConfiguration()
.update('cody.experimental.autoedits.enabled', true, vscode.ConfigurationTarget.Global)

// Open VS Code settings UI and focus on the Cody Autoedits setting
await vscode.commands.executeCommand(
'workbench.action.openSettings',
'cody.experimental.autoedits'
)
}
}

function shouldShowAutoeditsOnboardingPopup(): boolean {
const isAutoeditsConfigEnabled = vscode.workspace
.getConfiguration()
.get<boolean>('cody.experimental.autoedits.enabled', false)

// Do not show the onboarding popup if the feature is already enabled or any other editor than vscode.
if (isRunningInsideAgent() || isAutoeditsConfigEnabled) {
return false
}

if (isDotComAuthed()) {
return shouldShowAutoeditsOnboardingPopupForDotComUser()
}

const authStatus = currentAuthStatus()
if (isS2(authStatus)) {
// All the S2 users should see the onboarding popup for dogfooding
return true
}

// Decide later if we want to show the pop-up for the enterprise
return false
}

function shouldShowAutoeditsOnboardingPopupForDotComUser(): boolean {
const isUserEligibleForFeature = featureFlagProvider.evaluatedFeatureFlag(
FeatureFlag.CodyAutoeditExperimentEnabledFeatureFlag
)
if (!isUserEligibleForFeature) {
return false
}
return true
}
5 changes: 5 additions & 0 deletions vscode/src/completions/inline-completion-item-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { autocompleteStageCounterLogger } from '../services/autocomplete-stage-c
import { recordExposedExperimentsToSpan } from '../services/open-telemetry/utils'
import { isInTutorial } from '../tutorial/helpers'

import { showAutoeditOnboardingIfEligible } from '../autoedits/autoedit-onboarding'
import { ContextRankingStrategy } from '../completions/context/completions-context-ranker'
import type { CompletionBookkeepingEvent, CompletionItemID, CompletionLogID } from './analytics-logger'
import * as CompletionAnalyticsLogger from './analytics-logger'
Expand Down Expand Up @@ -138,6 +139,10 @@ export class InlineCompletionItemProvider
tracer = null,
...config
}: CodyCompletionItemProviderConfig) {
// Show the autoedits onboarding message if the user hasn't enabled autoedits
// but is eligible to use them as an alternative to autocomplete
showAutoeditOnboardingIfEligible()

// This is a static field to allow for easy access in the static `configuration` getter.
// There must only be one instance of this class at a time.
InlineCompletionItemProviderConfigSingleton.set({
Expand Down
29 changes: 23 additions & 6 deletions vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,14 @@ function registerAutoEdits(chatClient: ChatClient, disposables: vscode.Disposabl
)
)
.pipe(
map(([config, authStatus, autoeditEnabled]) => {
if (shouldEnableExperimentalAutoedits(config, autoeditEnabled, authStatus)) {
map(([config, authStatus, autoeditFeatureFlagEnabled]) => {
if (
shouldEnableExperimentalAutoedits(
config,
autoeditFeatureFlagEnabled,
authStatus
)
) {
const provider = new AutoeditsProvider(chatClient)
const completionRegistration =
vscode.languages.registerInlineCompletionItemProvider(
Expand Down Expand Up @@ -745,14 +751,19 @@ function registerAutoEdits(chatClient: ChatClient, disposables: vscode.Disposabl

function shouldEnableExperimentalAutoedits(
config: ResolvedConfiguration,
autoeditExperimentFlag: boolean,
autoeditFeatureFlagEnabled: boolean,
authStatus: AuthStatus
): boolean {
// If running inside agent don't enable experimental autoedits
if (isRunningInsideAgent()) {
return false
}
// If the config is explicitly set in the vscode settings, use the setting instead of the feature flag.
if (config.configuration.experimentalAutoeditsEnabled !== undefined) {
return config.configuration.experimentalAutoeditsEnabled
}
return autoeditExperimentFlag && isS2(authStatus) && isRunningInsideAgent() === false
// Feature flag should only control S2, use the flag instead of the config.
return autoeditFeatureFlagEnabled && isS2(authStatus)
}

/**
Expand Down Expand Up @@ -792,9 +803,15 @@ function registerAutocomplete(
isEqual(a[2], b[2])
)
}),
switchMap(([config, authStatus, autoeditEnabled]) => {
switchMap(([config, authStatus, autoeditFeatureFlagEnabled]) => {
// If the auto-edit experiment is enabled, we don't need to load the completion provider
if (shouldEnableExperimentalAutoedits(config, autoeditEnabled, authStatus)) {
if (
shouldEnableExperimentalAutoedits(
config,
autoeditFeatureFlagEnabled,
authStatus
)
) {
finishLoading()
return NEVER
}
Expand Down
Loading