update control for posthog

This commit is contained in:
Test 2025-01-09 10:14:26 -08:00
parent 2a20b5adc9
commit b283f1b402
2 changed files with 22 additions and 9 deletions

View file

@ -12,7 +12,7 @@ export enum PosthogFeatureFlag {
export const EXPERIMENTS: {
[key in PosthogFeatureFlag]: {
[key: string]: { value: number };
[key: string]: { value: any };
};
} = {
[PosthogFeatureFlag.AutocompleteTimeout]: {
@ -22,7 +22,8 @@ export const EXPERIMENTS: {
"450": { value: 450 },
},
[PosthogFeatureFlag.RecentlyVisitedRangesNumSurroundingLines]: {
control: { value: 5 },
control: { value: null },
"5": { value: 5 },
"10": { value: 10 },
"15": { value: 15 },
"20": { value: 20 },

View file

@ -19,6 +19,7 @@ export class RecentlyVisitedRangesService {
private numSurroundingLines = 5;
private maxRecentFiles = 3;
private maxSnippetsPerFile = 3;
private isActive: boolean = false;
constructor(private readonly ide: IDE) {
this.cache = new LRUCache<
@ -31,18 +32,23 @@ export class RecentlyVisitedRangesService {
void this.setNumSurroundingLinesFromPostHogExperiment();
vscode.window.onDidChangeTextEditorSelection(
this.handleOnDidChangeTextEditorSelection,
this.cacheCurrentSelectionContext,
);
}
private async setNumSurroundingLinesFromPostHogExperiment() {
this.numSurroundingLines =
(await Telemetry.getValueForFeatureFlag(
PosthogFeatureFlag.AutocompleteTimeout,
)) ?? this.numSurroundingLines;
const recentlyVisitedRangesNumSurroundingLines =
await Telemetry.getValueForFeatureFlag(
PosthogFeatureFlag.RecentlyVisitedRangesNumSurroundingLines,
);
if (recentlyVisitedRangesNumSurroundingLines) {
this.numSurroundingLines = recentlyVisitedRangesNumSurroundingLines;
this.isActive = true;
}
}
private handleOnDidChangeTextEditorSelection = async (
private cacheCurrentSelectionContext = async (
event: vscode.TextEditorSelectionChangeEvent,
) => {
const filepath = event.textEditor.document.uri.toString();
@ -76,7 +82,7 @@ export class RecentlyVisitedRangesService {
this.cache.set(filepath, newSnippets);
} catch (err) {
console.error(
"Error caching recently visited ranges for autocomplete",
"Error caching recently visited ranges for autocomplete: ",
err,
);
return;
@ -89,6 +95,12 @@ export class RecentlyVisitedRangesService {
* @returns Array of code snippets from recently visited files
*/
public getSnippets(): AutocompleteCodeSnippet[] {
// If the feature is not active (e.g. user is in control group),
// return an empty array to exclude recently visited ranges snippets
if (!this.isActive) {
return [];
}
const currentFilepath =
vscode.window.activeTextEditor?.document.uri.toString();
let allSnippets: Array<AutocompleteCodeSnippet & { timestamp: number }> =