Skip to content
Merged
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
9 changes: 5 additions & 4 deletions src/common/errors/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as stackTrace from 'stack-trace';
import { commands, LogOutputChannel, window } from 'vscode';
import { Common } from '../localize';

export function parseStack(ex: Error) {
if (ex.stack && Array.isArray(ex.stack)) {
Expand All @@ -10,8 +11,8 @@ export function parseStack(ex: Error) {
}

export async function showErrorMessage(message: string, log?: LogOutputChannel) {
const result = await window.showErrorMessage(message, 'View Logs');
if (result === 'View Logs') {
const result = await window.showErrorMessage(message, Common.viewLogs);
if (result === Common.viewLogs) {
if (log) {
log.show();
} else {
Expand All @@ -21,8 +22,8 @@ export async function showErrorMessage(message: string, log?: LogOutputChannel)
}

export async function showWarningMessage(message: string, log?: LogOutputChannel) {
const result = await window.showWarningMessage(message, 'View Logs');
if (result === 'View Logs') {
const result = await window.showWarningMessage(message, Common.viewLogs);
if (result === Common.viewLogs) {
if (log) {
log.show();
} else {
Expand Down
101 changes: 101 additions & 0 deletions src/common/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export namespace Common {
export const uninstall = l10n.t('Uninstall');
export const openInBrowser = l10n.t('Open in Browser');
export const openInEditor = l10n.t('Open in Editor');
export const browse = l10n.t('Browse');
export const selectFolder = l10n.t('Select Folder');
export const viewLogs = l10n.t('View Logs');
export const yes = l10n.t('Yes');
export const no = l10n.t('No');
}

export namespace Interpreter {
Expand All @@ -25,3 +30,99 @@ export namespace PackageManagement {
export const enterPackagesPlaceHolder = l10n.t('Enter package names separated by space');
export const editArguments = l10n.t('Edit arguments');
}

export namespace Pickers {
export namespace Environments {
export const selectExecutable = l10n.t('Select Python Executable');
export const selectEnvironment = l10n.t('Select a Python Environment');
}

export namespace Packages {
export const selectOption = l10n.t('Select an option');
export const installPackages = l10n.t('Install packages');
export const uninstallPackages = l10n.t('Uninstall packages');
}

export namespace Managers {
export const selectEnvironmentManager = l10n.t('Select an environment manager');
export const selectPackageManager = l10n.t('Select a package manager');
export const selectProjectCreator = l10n.t('Select a project creator');
}

export namespace Project {
export const selectProject = l10n.t('Select a project, folder or script');
export const selectProjects = l10n.t('Select one or more projects, folders or scripts');
}
}

export namespace ProjectViews {
export const noPackageManager = l10n.t('No package manager found');
export const waitingForEnvManager = l10n.t('Waiting for environment managers to load');
export const noEnvironmentManager = l10n.t('Environment manager not found');
export const noEnvironmentManagerDescription = l10n.t(
'Install an environment manager to get started. If you have installed then it might be loading or errored',
);
export const noEnvironmentProvided = l10n.t('No environment provided by:');
export const noPackages = l10n.t('No packages found');
}

export namespace VenvManagerStrings {
export const venvManagerDescription = l10n.t('Manages virtual environments created using `venv`');
export const venvInitialize = l10n.t('Initializing virtual environments');
export const venvRefreshing = l10n.t('Refreshing virtual environments');
export const venvGlobalFolder = l10n.t('Select a folder to create a global virtual environment');
export const venvGlobalFoldersSetting = l10n.t('Venv Folders Setting');

export const venvErrorNoBasePython = l10n.t('No base Python found');
export const venvErrorNoPython3 = l10n.t('Did not find any base Python 3');

export const venvName = l10n.t('Enter a name for the virtual environment');
export const venvNameErrorEmpty = l10n.t('Name cannot be empty');
export const venvNameErrorExists = l10n.t('A folder with the same name already exists');

export const venvCreating = l10n.t('Creating virtual environment');
export const venvCreateFailed = l10n.t('Failed to create virtual environment');

export const venvRemoving = l10n.t('Removing virtual environment');
export const venvRemoveFailed = l10n.t('Failed to remove virtual environment');

export const installEditable = l10n.t('Install project as editable');
export const searchingDependencies = l10n.t('Searching for dependencies');
}

export namespace SysManagerStrings {
export const sysManagerDescription = l10n.t('Manages Global Python installs');
export const sysManagerRefreshing = l10n.t('Refreshing Global Python interpreters');
export const sysManagerDiscovering = l10n.t('Discovering Global Python interpreters');

export const selectInstall = l10n.t('Select packages to install');
export const selectUninstall = l10n.t('Select packages to uninstall');

export const packageRefreshError = l10n.t('Error refreshing packages');
}

export namespace CondaStrings {
export const condaManager = l10n.t('Manages Conda environments');
export const condaDiscovering = l10n.t('Discovering Conda environments');
export const condaRefreshingEnvs = l10n.t('Refreshing Conda environments');

export const condaPackageMgr = l10n.t('Manages Conda packages');
export const condaRefreshingPackages = l10n.t('Refreshing Conda packages');
export const condaInstallingPackages = l10n.t('Installing Conda packages');
export const condaInstallError = l10n.t('Error installing Conda packages');
export const condaUninstallingPackages = l10n.t('Uninstalling Conda packages');
export const condaUninstallError = l10n.t('Error uninstalling Conda packages');

export const condaNamed = l10n.t('Named');
export const condaPrefix = l10n.t('Prefix');

export const condaNamedDescription = l10n.t('Create a named conda environment');
export const condaPrefixDescription = l10n.t('Create environment in your workspace');
export const condaSelectEnvType = l10n.t('Select the type of conda environment to create');

export const condaNamedInput = l10n.t('Enter the name of the conda environment to create');

export const condaCreateFailed = l10n.t('Failed to create conda environment');
export const condaRemoveFailed = l10n.t('Failed to remove conda environment');
export const condaExists = l10n.t('Environment already exists');
}
14 changes: 5 additions & 9 deletions src/common/pickers/environments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Uri, ThemeIcon, QuickPickItem, QuickPickItemKind, ProgressLocation, QuickInputButtons } from 'vscode';
import { IconPath, PythonEnvironment, PythonProject } from '../../api';
import { InternalEnvironmentManager } from '../../internal.api';
import { Common, Interpreter } from '../localize';
import { Common, Interpreter, Pickers } from '../localize';
import { showQuickPickWithButtons, showQuickPick, showOpenDialog, withProgress } from '../window.apis';
import { isWindows } from '../../managers/common/utils';
import { traceError } from '../logging';
Expand All @@ -18,14 +18,10 @@ type QuickPickIcon =
| undefined;

function getIconPath(i: IconPath | undefined): QuickPickIcon {
if (i === undefined || i instanceof ThemeIcon) {
if (i === undefined || i instanceof ThemeIcon || i instanceof Uri) {
return i;
}

if (i instanceof Uri) {
return i.fsPath.endsWith('__icon__.py') ? undefined : i;
}

if (typeof i === 'string') {
return Uri.file(i);
}
Expand All @@ -51,7 +47,7 @@ async function browseForPython(
canSelectFolders: false,
canSelectMany: false,
filters,
title: 'Select Python executable',
title: Pickers.Environments.selectExecutable,
});
if (!uris || uris.length === 0) {
return;
Expand Down Expand Up @@ -103,7 +99,7 @@ async function pickEnvironmentImpl(
options: EnvironmentPickOptions,
): Promise<PythonEnvironment | undefined> {
const selected = await showQuickPickWithButtons(items, {
placeHolder: `Select a Python Environment`,
placeHolder: Pickers.Environments.selectEnvironment,
ignoreFocusOut: true,
showBackButton: options?.showBackButton,
});
Expand Down Expand Up @@ -184,7 +180,7 @@ export async function pickEnvironmentFrom(environments: PythonEnvironment[]): Pr
iconPath: getIconPath(e.iconPath),
}));
const selected = await showQuickPick(items, {
placeHolder: 'Select Python Environment',
placeHolder: Pickers.Environments.selectEnvironment,
ignoreFocusOut: true,
});
return (selected as { e: PythonEnvironment })?.e;
Expand Down
8 changes: 4 additions & 4 deletions src/common/pickers/managers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { QuickPickItem, QuickPickItemKind } from 'vscode';
import { PythonProjectCreator } from '../../api';
import { InternalEnvironmentManager, InternalPackageManager } from '../../internal.api';
import { Common } from '../localize';
import { Common, Pickers } from '../localize';
import { showQuickPickWithButtons, showQuickPick } from '../window.apis';

export async function pickEnvironmentManager(
Expand Down Expand Up @@ -44,7 +44,7 @@ export async function pickEnvironmentManager(
})),
);
const item = await showQuickPickWithButtons(items, {
placeHolder: 'Select an environment manager',
placeHolder: Pickers.Managers.selectEnvironmentManager,
ignoreFocusOut: true,
});
return (item as QuickPickItem & { id: string })?.id;
Expand Down Expand Up @@ -90,7 +90,7 @@ export async function pickPackageManager(
})),
);
const item = await showQuickPickWithButtons(items, {
placeHolder: 'Select an package manager',
placeHolder: Pickers.Managers.selectPackageManager,
ignoreFocusOut: true,
});
return (item as QuickPickItem & { id: string })?.id;
Expand All @@ -111,7 +111,7 @@ export async function pickCreator(creators: PythonProjectCreator[]): Promise<Pyt
c: c,
}));
const selected = await showQuickPick(items, {
placeHolder: 'Select a project creator',
placeHolder: Pickers.Managers.selectProjectCreator,
ignoreFocusOut: true,
});
return (selected as { c: PythonProjectCreator })?.c;
Expand Down
8 changes: 4 additions & 4 deletions src/common/pickers/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import { Installable, PythonEnvironment, Package } from '../../api';
import { InternalPackageManager } from '../../internal.api';
import { EXTENSION_ROOT_DIR } from '../constants';
import { launchBrowser } from '../env.apis';
import { Common, PackageManagement } from '../localize';
import { Common, PackageManagement, Pickers } from '../localize';
import { traceWarn } from '../logging';
import { showQuickPick, showInputBoxWithButtons, showTextDocument, showQuickPickWithButtons } from '../window.apis';

export async function pickPackageOptions(): Promise<string | undefined> {
const items = [
{
label: Common.install,
description: 'Install packages',
description: Pickers.Packages.installPackages,
},
{
label: Common.uninstall,
description: 'Uninstall packages',
description: Pickers.Packages.uninstallPackages,
},
];
const selected = await showQuickPick(items, {
placeHolder: 'Select an option',
placeHolder: Pickers.Packages.selectOption,
ignoreFocusOut: true,
});
return selected?.label;
Expand Down
5 changes: 3 additions & 2 deletions src/common/pickers/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path';
import { QuickPickItem } from 'vscode';
import { PythonProject } from '../../api';
import { showQuickPick, showQuickPickWithButtons } from '../window.apis';
import { Pickers } from '../localize';

interface ProjectQuickPickItem extends QuickPickItem {
project: PythonProject;
Expand All @@ -15,7 +16,7 @@ export async function pickProject(projects: ReadonlyArray<PythonProject>): Promi
project: pw,
}));
const item = await showQuickPick(items, {
placeHolder: 'Select a project, folder or script',
placeHolder: Pickers.Project.selectProject,
ignoreFocusOut: true,
});
if (item) {
Expand All @@ -38,7 +39,7 @@ export async function pickProjectMany(
project: pw,
}));
const item = await showQuickPickWithButtons(items, {
placeHolder: 'Select a project, folder or script',
placeHolder: Pickers.Project.selectProjects,
ignoreFocusOut: true,
canPickMany: true,
showBackButton: showBackButton,
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
registerAutoProjectProvider,
registerExistingProjectProvider,
} from './features/projectCreators';
import { WorkspaceView } from './features/views/projectView';
import { ProjectView } from './features/views/projectView';
import { registerCompletionProvider } from './features/settings/settingCompletions';
import { TerminalManager, TerminalManagerImpl } from './features/terminal/terminalManager';
import {
Expand Down Expand Up @@ -93,7 +93,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
const managerView = new EnvManagerView(envManagers);
context.subscriptions.push(managerView);

const workspaceView = new WorkspaceView(envManagers, projectManager);
const workspaceView = new ProjectView(envManagers, projectManager);
context.subscriptions.push(workspaceView);

workspaceView.initialize();
Expand Down
5 changes: 3 additions & 2 deletions src/features/views/envManagersView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
PackageRootInfoTreeItem,
} from './treeViewItems';
import { createSimpleDebounce } from '../../common/utils/debounce';
import { ProjectViews } from '../../common/localize';

export class EnvManagerView implements TreeDataProvider<EnvTreeItem>, Disposable {
private treeView: TreeView<EnvTreeItem>;
Expand Down Expand Up @@ -120,7 +121,7 @@ export class EnvManagerView implements TreeDataProvider<EnvTreeItem>, Disposable
this.packageRoots.set(environment.envId.id, item);
views.push(item);
} else {
views.push(new EnvInfoTreeItem(parent, 'No package manager found'));
views.push(new EnvInfoTreeItem(parent, ProjectViews.noPackageManager));
}

return views;
Expand All @@ -137,7 +138,7 @@ export class EnvManagerView implements TreeDataProvider<EnvTreeItem>, Disposable
if (packages) {
views.push(...packages.map((p) => new PackageTreeItem(p, root, manager)));
} else {
views.push(new PackageRootInfoTreeItem(root, 'No packages found'));
views.push(new PackageRootInfoTreeItem(root, ProjectViews.noPackages));
}

return views;
Expand Down
15 changes: 8 additions & 7 deletions src/features/views/projectView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import {
} from './treeViewItems';
import { onDidChangeConfiguration } from '../../common/workspace.apis';
import { createSimpleDebounce } from '../../common/utils/debounce';
import { ProjectViews } from '../../common/localize';

export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
export class ProjectView implements TreeDataProvider<ProjectTreeItem> {
private treeView: TreeView<ProjectTreeItem>;
private _treeDataChanged: EventEmitter<ProjectTreeItem | ProjectTreeItem[] | null | undefined> = new EventEmitter<
ProjectTreeItem | ProjectTreeItem[] | null | undefined
Expand Down Expand Up @@ -149,7 +150,7 @@ export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
new NoProjectEnvironment(
projectItem.project,
projectItem,
'Waiting for environment managers to load',
ProjectViews.waitingForEnvManager,
undefined,
undefined,
'$(loading~spin)',
Expand All @@ -164,8 +165,8 @@ export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
new NoProjectEnvironment(
projectItem.project,
projectItem,
'Environment manager not found',
'Install an environment manager to get started. If you have installed then it might be loading.',
ProjectViews.noEnvironmentManager,
ProjectViews.noEnvironmentManagerDescription,
),
];
}
Expand All @@ -176,7 +177,7 @@ export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
new NoProjectEnvironment(
projectItem.project,
projectItem,
`No environment provided by ${manager.displayName}`,
`${ProjectViews.noEnvironmentProvided} ${manager.displayName}`,
),
];
}
Expand All @@ -199,7 +200,7 @@ export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
this.packageRoots.set(uri ? uri.fsPath : 'global', item);
views.push(item);
} else {
views.push(new ProjectEnvironmentInfo(environmentItem, 'No package manager found'));
views.push(new ProjectEnvironmentInfo(environmentItem, ProjectViews.noPackageManager));
}
return views;
}
Expand All @@ -214,7 +215,7 @@ export class WorkspaceView implements TreeDataProvider<ProjectTreeItem> {
if (packages) {
return packages.map((p) => new ProjectPackage(root, p, manager));
} else {
views.push(new ProjectPackageRootInfoTreeItem(root, 'No packages found'));
views.push(new ProjectPackageRootInfoTreeItem(root, ProjectViews.noPackages));
}
}

Expand Down
Loading