-
Notifications
You must be signed in to change notification settings - Fork 336
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
feat(auto-edits): adding autoedits onboarding setup for dotcom users #6463
Changes from all commits
a8641e8
17cbc10
0051452
7d6df51
3451c3f
570ebe4
91dfd12
7c23a46
2730e37
ba9805e
998f66e
0d62c0f
326b010
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,125 @@ | ||||
import { | ||||
CodyAutoSuggestionMode, | ||||
FeatureFlag, | ||||
currentAuthStatus, | ||||
currentResolvedConfig, | ||||
currentUserProductSubscription, | ||||
featureFlagProvider, | ||||
storeLastValue, | ||||
} from '@sourcegraph/cody-shared' | ||||
import * as vscode from 'vscode' | ||||
import { localStorage } from '../services/LocalStorageProvider' | ||||
import { isUserEligibleForAutoeditsFeature } from './create-autoedits-provider' | ||||
|
||||
export interface AutoeditsNotificationInfo { | ||||
lastNotifiedTime: number | ||||
timesShown: number | ||||
} | ||||
|
||||
export class AutoeditsOnboarding implements vscode.Disposable { | ||||
private readonly MAX_AUTO_EDITS_ONBOARDING_NOTIFICATIONS = 3 | ||||
private readonly MIN_TIME_DIFF_AUTO_EDITS_BETWEEN_NOTIFICATIONS_MS = 60 * 60 * 1000 // 1 hour | ||||
|
||||
private featureFlagAutoeditsExperimental = storeLastValue( | ||||
featureFlagProvider.evaluatedFeatureFlag(FeatureFlag.CodyAutoeditExperimentEnabledFeatureFlag) | ||||
) | ||||
|
||||
public async showAutoeditsOnboardingIfEligible(): Promise<void> { | ||||
const shouldShowOnboardingPopup = await this.shouldShowAutoeditsOnboardingPopup() | ||||
if (shouldShowOnboardingPopup) { | ||||
await this.showAutoeditsOnboardingPopup() | ||||
} | ||||
} | ||||
|
||||
private async showAutoeditsOnboardingPopup(): Promise<void> { | ||||
const selection = await vscode.window.showInformationMessage( | ||||
toolmantim marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
'Try Cody Auto-Edits (experimental)? Cody will intelligently suggest next edits as you navigate the codebase.', | ||||
'Enable Auto-Edits', | ||||
"Don't Show Again" | ||||
) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a "Don't Show Again" option here? (like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added the text |
||||
await this.incrementAutoEditsOnboardingNotificationCount({ incrementCount: 1 }) | ||||
|
||||
if (selection === 'Enable Auto-Edits') { | ||||
// Enable the setting programmatically | ||||
await vscode.workspace | ||||
.getConfiguration() | ||||
.update( | ||||
'cody.suggestions.mode', | ||||
CodyAutoSuggestionMode.Autoedits, | ||||
vscode.ConfigurationTarget.Global | ||||
) | ||||
|
||||
// Open VS Code settings UI and focus on the Cody Autoedits setting | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the thinking behind opening the settings panel? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to make them aware where to find the settings in case they want to turn on/off or switch between autocomplete/auto-edits. |
||||
await vscode.commands.executeCommand( | ||||
'workbench.action.openSettings', | ||||
'cody.suggestions.mode' | ||||
) | ||||
} else if (selection === "Don't Show Again") { | ||||
// If user doesn't want to see the notification again, increase number of shown notification by max limit + 1 | ||||
// to prevent showing the notification again until the user restarts VS Code. | ||||
await this.incrementAutoEditsOnboardingNotificationCount({ | ||||
incrementCount: this.MAX_AUTO_EDITS_ONBOARDING_NOTIFICATIONS + 1, | ||||
}) | ||||
} | ||||
} | ||||
|
||||
private async shouldShowAutoeditsOnboardingPopup(): Promise<boolean> { | ||||
const isAutoeditsEnabled = await this.isAutoeditsEnabled() | ||||
if (isAutoeditsEnabled) { | ||||
return false | ||||
} | ||||
const isUserEligible = await this.isUserEligibleForAutoeditsOnboarding() | ||||
if (!isUserEligible) { | ||||
return false | ||||
} | ||||
const isUnderNotificationLimit = await this.isAutoeditsNotificationsUnderLimit() | ||||
return isUnderNotificationLimit | ||||
} | ||||
|
||||
private async incrementAutoEditsOnboardingNotificationCount(param: { | ||||
incrementCount: number | ||||
}): Promise<void> { | ||||
const info = await this.getAutoEditsOnboardingNotificationInfo() | ||||
await localStorage.setAutoEditsOnboardingNotificationInfo({ | ||||
timesShown: info.timesShown + param.incrementCount, | ||||
lastNotifiedTime: Date.now(), | ||||
}) | ||||
} | ||||
|
||||
private async isAutoeditsEnabled(): Promise<boolean> { | ||||
const config = await currentResolvedConfig() | ||||
return config.configuration.experimentalAutoeditsEnabled | ||||
} | ||||
|
||||
private async isAutoeditsNotificationsUnderLimit(): Promise<boolean> { | ||||
const info = await this.getAutoEditsOnboardingNotificationInfo() | ||||
return ( | ||||
info.timesShown < this.MAX_AUTO_EDITS_ONBOARDING_NOTIFICATIONS && | ||||
Date.now() - info.lastNotifiedTime > this.MIN_TIME_DIFF_AUTO_EDITS_BETWEEN_NOTIFICATIONS_MS | ||||
) | ||||
} | ||||
|
||||
private async getAutoEditsOnboardingNotificationInfo(): Promise<AutoeditsNotificationInfo> { | ||||
return localStorage.getAutoEditsOnboardingNotificationInfo() | ||||
} | ||||
|
||||
private async isUserEligibleForAutoeditsOnboarding(): Promise<boolean> { | ||||
const authStatus = currentAuthStatus() | ||||
const productSubscription = await currentUserProductSubscription() | ||||
const autoeditsFeatureFlag = this.isAutoeditsFeatureFlagEnabled() | ||||
const { isUserEligible } = isUserEligibleForAutoeditsFeature( | ||||
autoeditsFeatureFlag, | ||||
authStatus, | ||||
productSubscription | ||||
) | ||||
return isUserEligible | ||||
} | ||||
|
||||
private isAutoeditsFeatureFlagEnabled(): boolean { | ||||
return !!this.featureFlagAutoeditsExperimental.value.last | ||||
} | ||||
|
||||
dispose(): void { | ||||
this.featureFlagAutoeditsExperimental.subscription.unsubscribe() | ||||
} | ||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TY!