Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/common/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export namespace WorkbenchStrings {
export const installExtension = l10n.t('Install Extension');
}

export namespace FeedbackStrings {
export const prompt = l10n.t('Would you like to leave a review for Python Environments?');
export const reviewMarketplace = l10n.t('Review on Marketplace');
}

export namespace Interpreter {
export const statusBarSelect = l10n.t('Select Interpreter');
export const browsePath = l10n.t('Browse...');
Expand Down
34 changes: 30 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
createLogOutputChannel,
onDidChangeActiveTerminal,
onDidChangeTerminalShellIntegration,
onDidChangeWindowState,
withProgress,
} from './common/window.apis';
import { getConfiguration, getWorkspaceFolders } from './common/workspace.apis';
Expand Down Expand Up @@ -65,6 +66,7 @@ import {
} from './features/envCommands';
import { PythonEnvironmentManagers } from './features/envManagers';
import { EnvVarManager, PythonEnvVariableManager } from './features/execution/envVariableManager';
import { FeedbackPromptService } from './features/feedback/feedbackPromptService';
import { InlineScriptLazyDetector } from './features/inlineScript/lazyDetector';
import {
applyInitialEnvironmentSelection,
Expand Down Expand Up @@ -165,6 +167,16 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron

// Setup the persistent state for the extension.
setPersistentState(context);
const feedbackPrompt = new FeedbackPromptService(context.globalState, context.globalStorageUri.fsPath);
await feedbackPrompt.initialize();
context.subscriptions.push(
feedbackPrompt,
onDidChangeWindowState((state) => {
if (state.focused) {
feedbackPrompt.notifyWindowFocused();
}
}),
);

// One-time migration: remove `system` defaultEnvManager from User settings if a previous
// version wrote it there (bug #1468). Awaited so the migration deterministically affects
Expand Down Expand Up @@ -274,7 +286,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
manager: managerId,
triggeredLocation: 'createSpecifiedCommand',
});
return await withProgress(
const environment = await withProgress(
{
location: ProgressLocation.Notification,
title: l10n.t('Creating environment...'),
Expand All @@ -283,14 +295,18 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
return await createEnvironmentCommand(item, envManagers, projectManager);
},
);
if (environment) {
await feedbackPrompt.recordSuccessfulAction();
}
return environment;
}),
commands.registerCommand('python-envs.createAny', async (options) => {
// Telemetry: record environment creation attempt with no specific manager
sendTelemetryEvent(EventNames.CREATE_ENVIRONMENT, undefined, {
manager: 'none',
triggeredLocation: 'createAnyCommand',
});
return await withProgress(
const environment = await withProgress(
{
location: ProgressLocation.Notification,
title: l10n.t('Creating environment...'),
Expand All @@ -303,6 +319,10 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
);
},
);
if (environment) {
await feedbackPrompt.recordSuccessfulAction();
}
return environment;
}),
commands.registerCommand('python-envs.remove', async (item) => {
await removeEnvironmentCommand(item, envManagers);
Expand All @@ -326,10 +346,16 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
await managePackageVersion(context, envManagers);
}),
commands.registerCommand('python-envs.set', async (item) => {
await setEnvironmentCommand(item, envManagers, projectManager);
const environment = await setEnvironmentCommand(item, envManagers, projectManager);
if (environment) {
await feedbackPrompt.recordSuccessfulAction();
}
}),
commands.registerCommand('python-envs.setEnv', async (item) => {
await setEnvironmentCommand(item, envManagers, projectManager);
const environment = await setEnvironmentCommand(item, envManagers, projectManager);
if (environment) {
await feedbackPrompt.recordSuccessfulAction();
}
if (item instanceof PythonEnvTreeItem) {
temporaryStateManager.setState(item.environment.envId.id, 'selected');
}
Expand Down
18 changes: 11 additions & 7 deletions src/features/envCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export async function setEnvironmentCommand(
context: unknown,
em: EnvironmentManagers,
wm: PythonProjectManager,
): Promise<void> {
): Promise<PythonEnvironment | undefined> {
if (context instanceof PythonEnvTreeItem) {
try {
const view = context as PythonEnvTreeItem;
Expand All @@ -427,31 +427,33 @@ export async function setEnvironmentCommand(
if (selected && selected.length > 0) {
// Check if the selected environment is already the current one for each project
await setEnvironmentForProjects(selected, context.environment, em);
return view.environment;
}
} else {
await em.setEnvironments('global', view.environment);
return view.environment;
}
} catch (ex) {
if (ex === QuickInputButtons.Back) {
await setEnvironmentCommand(context, em, wm);
return await setEnvironmentCommand(context, em, wm);
}
throw ex;
}
} else if (context instanceof ProjectItem) {
const view = context as ProjectItem;
await setEnvironmentCommand([view.project.uri], em, wm);
return await setEnvironmentCommand([view.project.uri], em, wm);
} else if (context instanceof GlobalProjectItem) {
await setEnvironmentCommand(undefined, em, wm);
return await setEnvironmentCommand(undefined, em, wm);
} else if (context instanceof Uri) {
await setEnvironmentCommand([context], em, wm);
return await setEnvironmentCommand([context], em, wm);
} else if (context === undefined) {
try {
const projects = wm.getProjects();
if (projects.length > 0) {
const selected = await pickProjectMany(projects);
if (selected && selected.length > 0) {
const uris = selected.map((p) => p.uri);
await setEnvironmentCommand(uris, em, wm);
return await setEnvironmentCommand(uris, em, wm);
}
} else {
const globalEnvManager = em.getEnvironmentManager(undefined);
Expand All @@ -463,11 +465,12 @@ export async function setEnvironmentCommand(
});
if (selected) {
await em.setEnvironments('global', selected);
return selected;
}
}
} catch (ex) {
if (ex === QuickInputButtons.Back) {
await setEnvironmentCommand(context, em, wm);
return await setEnvironmentCommand(context, em, wm);
}
throw ex;
}
Expand All @@ -486,6 +489,7 @@ export async function setEnvironmentCommand(
if (selected) {
// Use the same logic for checking already set environments
await setEnvironmentForProjects(projects, selected, em);
return selected;
}
} else {
traceError(`Invalid context for setting environment command: ${context}`);
Expand Down
Loading
Loading