Skip to content

Commit

Permalink
fix: support python venv
Browse files Browse the repository at this point in the history
fix: Do not run self-update if command is not available
  • Loading branch information
hverlin committed Nov 22, 2024
1 parent af521b2 commit 292aceb
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 73 deletions.
32 changes: 29 additions & 3 deletions src/miseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,29 @@ export class MiseService {
const version = await this.getVersion();
const hasValidMiseVersion = await this.hasValidMiseVersion();
if (!hasValidMiseVersion) {
const canSelfUpdate = await this.canSelfUpdate();
const selection = await vscode.window.showErrorMessage(
`Mise version ${version} is not supported. Please update to a supported version.`,
{ modal: true },
"Run mise self-update",
canSelfUpdate ? "Run mise self-update" : "open mise website",
);
this.hasVerifiedMiseVersion = true;
if (selection === "Run mise self-update") {
await this.runMiseToolActionInConsole("self-update");
}
if (selection === "open mise website") {
await vscode.env.openExternal(
vscode.Uri.parse("https://mise.jdx.dev/cli/self-update.html"),
);
}
}
}
}

async execMiseCommand(command: string, { setProfile = true } = {}) {
const miseCommand = this.createMiseCommand(command, { setProfile });
ensureMiseCommand(miseCommand);
logger.info(`> ${miseCommand}`);
logger.debug(`> ${miseCommand}`);
return execAsync(miseCommand, { cwd: getRootFolderPath() });
}

Expand Down Expand Up @@ -462,6 +468,19 @@ export class MiseService {
return stdout.trim();
}

async canSelfUpdate() {
if (!this.getMiseBinaryPath()) {
return false;
}

try {
await this.execMiseCommand("self-update --help");
return true;
} catch (e) {
return false;
}
}

async hasValidMiseVersion() {
if (!this.getMiseBinaryPath()) {
return false;
Expand Down Expand Up @@ -506,12 +525,19 @@ export class MiseService {
const newMiseVersionAvailable =
miseConfig.problems?.newMiseVersionAvailable;
if (newMiseVersionAvailable) {
const canSelfUpdate = await this.canSelfUpdate();
const suggestion = await vscode.window.showInformationMessage(
`New Mise version available ${newMiseVersionAvailable?.latestVersion}. (Current: ${newMiseVersionAvailable?.currentVersion})`,
"Update Mise",
canSelfUpdate ? "Update Mise" : "How to update Mise",
"Show changelog",
);

if (suggestion === "How to update Mise") {
await vscode.env.openExternal(
vscode.Uri.parse("https://mise.jdx.dev/cli/self-update.html"),
);
}

if (suggestion === "Update Mise") {
await this.runMiseToolActionInConsole("self-update");
}
Expand Down
2 changes: 2 additions & 0 deletions src/providers/toolsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ export function registerToolsCommands(
miseConfig: miseConfig,
configurableExtension,
useShims: useMiseShims === "Yes",
miseService,
useSymLinks: vscode.workspace
.getConfiguration("mise")
.get("configureExtensionsUseSymLinks"),
Expand Down Expand Up @@ -597,6 +598,7 @@ export function registerToolsCommands(
tool: tool,
miseConfig: miseConfig,
configurableExtension,
miseService,
useSymLinks: vscode.workspace
.getConfiguration("mise")
.get("configureExtensionsUseSymLinks"),
Expand Down
11 changes: 8 additions & 3 deletions src/utils/configureExtensionUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getRootFolderPath,
updateVSCodeSettings,
} from "../configuration";
import type { MiseService } from "../miseService";
import { mkdirp } from "./fileUtils";
import { logger } from "./logger";
import type { MiseConfig } from "./miseDoctorParser";
Expand Down Expand Up @@ -89,9 +90,11 @@ export async function configureExtension({
configurableExtension,
useShims = true,
useSymLinks = false,
miseService,
}: {
tool: MiseTool;
miseConfig: MiseConfig;
miseService: MiseService;
configurableExtension: ConfigurableExtension;
useShims?: boolean;
useSymLinks?: boolean;
Expand All @@ -113,11 +116,13 @@ export async function configureExtension({
return { configurableExtension, updatedKeys: [] };
}

const extConfig = await configurableExtension.generateConfiguration(
const extConfig = await configurableExtension.generateConfiguration({
tool,
miseService,
miseConfig,
{ useShims, useSymLinks },
);
useShims,
useSymLinks,
});

const updatedKeys = await updateVSCodeSettings(
Object.entries(extConfig).map(([key, value]) => ({
Expand Down
149 changes: 82 additions & 67 deletions src/utils/supportedExtensions.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,54 @@
import * as path from "node:path";
import type { VSCodeSettingValue } from "../configuration";
import { type VSCodeSettingValue, getRootFolderPath } from "../configuration";
import type { MiseService } from "../miseService";
import {
configureSimpleExtension,
createMiseToolSymlink,
} from "./configureExtensionUtil";
import type { MiseConfig } from "./miseDoctorParser";

type GenerateConfigProps = {
tool: MiseTool;
miseService: MiseService;
miseConfig: MiseConfig;
useShims: boolean;
useSymLinks: boolean;
};

export type ConfigurableExtension = {
extensionId: string;
toolNames: string[];
generateConfiguration: (
tool: MiseTool,
miseConfig: MiseConfig,
{ useShims, useSymLinks }: { useShims: boolean; useSymLinks: boolean },
) => Promise<Record<string, VSCodeSettingValue>>;
generateConfiguration: ({
tool,
miseConfig,
useShims,
useSymLinks,
miseService,
}: GenerateConfigProps) => Promise<Record<string, VSCodeSettingValue>>;
};

export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
extensionId: "ms-python.python",
toolNames: ["python"],
generateConfiguration: async (
tool: MiseTool,
miseConfig: MiseConfig,
{ useShims, useSymLinks },
) => {
generateConfiguration: async ({
tool,
miseConfig,
useShims,
miseService,
useSymLinks,
}) => {
const envs = await miseService.getEnvs();
const virtualEnv = envs?.find((e) => e.name === "VIRTUAL_ENV");
if (virtualEnv) {
const workspaceRoot = getRootFolderPath();
return {
"python.defaultInterpreterPath": workspaceRoot
? virtualEnv.value.replace(workspaceRoot, "${workspaceFolder}")
: virtualEnv.value,
};
}

return configureSimpleExtension({
configKey: "python.defaultInterpreterPath",
useShims,
Expand All @@ -37,11 +61,12 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
extensionId: "denoland.vscode-deno",
toolNames: ["deno"],
generateConfiguration: async (
tool: MiseTool,
miseConfig: MiseConfig,
{ useShims, useSymLinks },
) => {
generateConfiguration: async ({
tool,
miseConfig,
useShims,
useSymLinks,
}) => {
return configureSimpleExtension({
configKey: "deno.path",
useShims,
Expand All @@ -54,11 +79,12 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
extensionId: "charliermarsh.ruff",
toolNames: ["ruff"],
generateConfiguration: async (
tool: MiseTool,
miseConfig: MiseConfig,
{ useShims, useSymLinks },
) => {
generateConfiguration: async ({
tool,
miseConfig,
useShims,
useSymLinks,
}) => {
const interpreterPath = useShims
? path.join(miseConfig.dirs.shims, tool.name)
: path.join(tool.install_path, "bin", tool.name);
Expand All @@ -75,11 +101,12 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
extensionId: "golang.go",
toolNames: ["go"],
generateConfiguration: async (
tool: MiseTool,
miseConfig: MiseConfig,
{ useShims, useSymLinks },
) => {
generateConfiguration: async ({
tool,
miseConfig,
useShims,
useSymLinks,
}) => {
const goRoot = useSymLinks
? await createMiseToolSymlink("goRoot", tool.install_path)
: tool.install_path;
Expand Down Expand Up @@ -114,11 +141,12 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
extensionId: "oven.bun-vscode",
toolNames: ["bun"],
generateConfiguration: async (
tool: MiseTool,
miseConfig: MiseConfig,
{ useShims, useSymLinks },
) => {
generateConfiguration: async ({
tool,
miseConfig,
useShims,
useSymLinks,
}) => {
return configureSimpleExtension({
configKey: "bun.runtime",
useShims,
Expand All @@ -131,11 +159,7 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
extensionId: "oracle.oracle-java",
toolNames: ["java"],
generateConfiguration: async (
tool: MiseTool,
miseConfig,
{ useSymLinks },
) => {
generateConfiguration: async ({ tool, useSymLinks }) => {
return {
"jdk.jdkhome": useSymLinks
? await createMiseToolSymlink("java", tool.install_path)
Expand All @@ -146,11 +170,12 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
extensionId: "timonwong.shellcheck",
toolNames: ["shellcheck"],
generateConfiguration: async (
tool: MiseTool,
miseConfig: MiseConfig,
{ useShims, useSymLinks },
) => {
generateConfiguration: async ({
tool,
miseConfig,
useShims,
useSymLinks,
}) => {
return configureSimpleExtension({
configKey: "shellcheck.executablePath",
useShims,
Expand All @@ -163,11 +188,12 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
toolNames: ["node"],
extensionId: "ms-vscode.js-debug",
generateConfiguration: async (
tool: MiseTool,
miseConfig: MiseConfig,
{ useShims, useSymLinks },
) => {
generateConfiguration: async ({
tool,
miseConfig,
useShims,
useSymLinks,
}) => {
const interpreterPath = useShims
? path.join(miseConfig.dirs.shims, tool.name)
: path.join(tool.install_path, "bin", tool.name);
Expand All @@ -186,11 +212,7 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
toolNames: ["php", "vfox:version-fox/vfox-php"],
extensionId: "vscode.php-language-features",
generateConfiguration: async (
tool: MiseTool,
miseConfig: MiseConfig,
{ useShims, useSymLinks },
) => {
generateConfiguration: async ({ tool, miseConfig, useShims }) => {
return configureSimpleExtension({
configKey: "php.validate.executablePath",
binName: "php",
Expand All @@ -204,11 +226,12 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
toolNames: ["php", "vfox:version-fox/vfox-php"],
extensionId: "xdebug.php-debug",
generateConfiguration: async (
tool: MiseTool,
miseConfig: MiseConfig,
{ useShims, useSymLinks },
) => {
generateConfiguration: async ({
tool,
miseConfig,
useShims,
useSymLinks,
}) => {
return configureSimpleExtension({
configKey: "php.debug.executablePath",
binName: "php",
Expand All @@ -222,11 +245,7 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
toolNames: ["julia"],
extensionId: "julialang.language-julia",
generateConfiguration: async (
tool: MiseTool,
miseConfig: MiseConfig,
{ useSymLinks },
) => {
generateConfiguration: async ({ tool, miseConfig, useSymLinks }) => {
return configureSimpleExtension({
configKey: "julia.executablePath",
useShims: false, // does not work with shims
Expand All @@ -239,11 +258,7 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
toolNames: ["erlang"],
extensionId: "pgourlain.erlang",
generateConfiguration: async (
tool: MiseTool,
miseConfig: MiseConfig,
{ useSymLinks },
) => {
generateConfiguration: async ({ tool, miseConfig, useSymLinks }) => {
const pathToBin = path.join(tool.install_path, "bin");
return {
"erlang.erlangPath": useSymLinks
Expand All @@ -255,7 +270,7 @@ export const SUPPORTED_EXTENSIONS: Array<ConfigurableExtension> = [
{
toolNames: ["dart", "vfox:version-fox/vfox-dart"],
extensionId: "Dart-Code.dart-code",
generateConfiguration: async (tool: MiseTool) => {
generateConfiguration: async ({ tool }) => {
return {
"dart.sdkPath": tool.install_path,
};
Expand Down

0 comments on commit 292aceb

Please sign in to comment.