Skip to content

Commit

Permalink
feat: allow copying an environment variable name or value
Browse files Browse the repository at this point in the history
  • Loading branch information
hverlin committed Nov 13, 2024
1 parent 1d5eef9 commit 105dfb0
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 8 deletions.
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@
"miseToolsView"
]
},
{
"command": "mise.copyEnvVariableName",
"title": "Mise: Copy Environment Variable Name"
},
{
"command": "mise.copyEnvVariableValue",
"title": "Mise: Copy Environment Variable Value"
},
{
"command": "mise.installTool",
"title": "Mise: Install Tool"
Expand Down Expand Up @@ -230,6 +238,16 @@
"when": "view == miseToolsView && viewItem == source",
"command": "mise.useTool",
"group": "inline"
},
{
"command": "mise.copyEnvVariableName",
"when": "view == miseEnvsView && viewItem == envItem",
"group": "2_modification"
},
{
"when": "view == miseEnvsView && viewItem == envItem",
"command": "mise.copyEnvVariableValue",
"group": "2_modification"
}
]
},
Expand Down
18 changes: 13 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import * as vscode from "vscode";
import { MiseFileWatcher } from "./miseFileWatcher";
import { MiseService } from "./miseService";
import { MiseEnvsProvider } from "./providers/envProvider";
import {
MiseEnvsProvider,
registerEnvsCommands,
} from "./providers/envProvider";
import { MiseRunCodeLensProvider } from "./providers/miseRunCodeLensProvider";
import {
MiseTasksProvider,
registerMiseCommands,
registerTasksCommands,
} from "./providers/tasksProvider";
import { MiseToolsProvider, registerCommands } from "./providers/toolsProvider";
import {
MiseToolsProvider,
registerToolsCommands,
} from "./providers/toolsProvider";
import { logger } from "./utils/logger";
import { resolveMisePath } from "./utils/miseBinLocator";
import { showSettingsNotification } from "./utils/notify";
Expand Down Expand Up @@ -58,8 +64,10 @@ export async function activate(context: vscode.ExtensionContext) {
statusBarItem.show();
statusBarItem.text = "$(tools) Mise";
statusBarItem.tooltip = "Click to refresh Mise";
registerMiseCommands(context, tasksProvider);
registerCommands(context, toolsProvider);

registerTasksCommands(context, tasksProvider);
registerToolsCommands(context, toolsProvider);
registerEnvsCommands(context, miseService);

vscode.window.registerTreeDataProvider("miseTasksView", tasksProvider);
vscode.window.registerTreeDataProvider("miseToolsView", toolsProvider);
Expand Down
55 changes: 54 additions & 1 deletion src/providers/envProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,61 @@ export class MiseEnvsProvider implements vscode.TreeDataProvider<EnvItem> {
}

class EnvItem extends vscode.TreeItem {
constructor(env: MiseEnv) {
constructor(public env: MiseEnv) {
const label = env.value ? `${env.name}=${env.value}` : env.name;
super(label, vscode.TreeItemCollapsibleState.None);

this.contextValue = "envItem";
}
}

export function registerEnvsCommands(
context: vscode.ExtensionContext,
miseService: MiseService,
) {
context.subscriptions.push(
vscode.commands.registerCommand(
"mise.copyEnvVariableName",
async (name: EnvItem | string | undefined) => {
let selectedName = name;
if (!selectedName) {
const possibleEnvs = await miseService.getEnvs();
selectedName = await vscode.window.showQuickPick(
possibleEnvs.map((env) => env.name),
);
} else if (selectedName instanceof EnvItem) {
selectedName = selectedName.env.name;
}

if (!selectedName) {
return;
}

await vscode.env.clipboard.writeText(selectedName);
vscode.window.showInformationMessage(`Copied name of ${selectedName}`);
},
),
vscode.commands.registerCommand(
"mise.copyEnvVariableValue",
async (name: EnvItem | string | undefined) => {
const possibleEnvs = await miseService.getEnvs();
let selectedName = name;
if (!selectedName) {
selectedName = await vscode.window.showQuickPick(
possibleEnvs.map((env) => env.name),
);
} else if (selectedName instanceof EnvItem) {
selectedName = selectedName.env.name;
}

const env = possibleEnvs.find((env) => env.name === selectedName);

if (!env) {
return;
}
await vscode.env.clipboard.writeText(env.value);
vscode.window.showInformationMessage(`Copied value of ${env.name}`);
},
),
);
}
2 changes: 1 addition & 1 deletion src/providers/tasksProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function findTaskPosition(
return undefined;
}

export function registerMiseCommands(
export function registerTasksCommands(
context: vscode.ExtensionContext,
taskProvider: MiseTasksProvider,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/providers/toolsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async function runMiseToolActionInConsole(
}
}

export function registerCommands(
export function registerToolsCommands(
context: vscode.ExtensionContext,
toolsProvider: MiseToolsProvider,
) {
Expand Down

0 comments on commit 105dfb0

Please sign in to comment.