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
8,860 changes: 5,909 additions & 2,951 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import tseslint from "typescript-eslint";

export default [
{
ignores: ["**/out/**", "**/__mocks__/**", "**/*.config.*", "**/node_modules/**", "**/view/**", "**/coverage/**"],
ignores: ["**/out/**", "**/__mocks__/**", "**/*.config.*", "**/node_modules/**", "**/coverage/**", "**/dist/**", "**/view/**"],
Comment thread
kubrickcode marked this conversation as resolved.
Comment thread
kubrickcode marked this conversation as resolved.
},
js.configs.recommended,
...tseslint.configs.recommended,
Expand Down
167 changes: 0 additions & 167 deletions src/extension/view-dist/assets/index-iXByG0Qx.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/extension/view-dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<script type="module" crossorigin src="/assets/index-iXByG0Qx.js"></script>
<script type="module" crossorigin src="/assets/index-5D6F7MIX.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DaHakWf7.css">
</head>
<body>
Expand Down
17 changes: 2 additions & 15 deletions src/internal/command-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { ButtonConfig } from "../pkg/types";
import { MESSAGES } from "../shared/constants";
import { TerminalExecutor, QuickPickCreator } from "./adapters";
import { findMatchingShortcut } from "./keyboard-layout-converter";

export type QuickPickItem = {
command: ButtonConfig;
description: string;
label: string;
};
import { QuickPickItem, createQuickPickItems, createButtonId } from "./utils/ui-items";

export type QuickPickConfig = {
items: QuickPickItem[];
Expand Down Expand Up @@ -118,14 +113,6 @@ export const createQuickPickWithShortcuts = (
quickPick.show();
};

export const createQuickPickItems = (commands: ButtonConfig[]): QuickPickItem[] => {
return commands.map((cmd) => ({
command: cmd,
description: cmd.command || "",
label: cmd.shortcut ? `${cmd.name} (${cmd.shortcut})` : cmd.name,
}));
};

export const executeTerminalCommand = (
button: ButtonConfig,
terminalExecutor: TerminalExecutor
Expand Down Expand Up @@ -194,7 +181,7 @@ export const executeCommandsRecursively = (
parentPath = ""
): void => {
commands.forEach((cmd, index) => {
const buttonId = parentPath ? `${parentPath}>${cmd.name}[${index}]` : `${cmd.name}[${index}]`;
const buttonId = createButtonId(cmd.name, index, parentPath);

if (cmd.group && cmd.executeAll) {
executeCommandsRecursively(cmd.group, terminalExecutor, buttonId);
Expand Down
89 changes: 4 additions & 85 deletions src/internal/providers/command-tree-provider.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,7 @@
import * as vscode from "vscode";
import { ButtonConfig } from "../../pkg/types";
import { ConfigReader, TerminalExecutor } from "../adapters";

export class CommandTreeItem extends vscode.TreeItem {
public readonly buttonName: string;
public readonly commandString: string;
public readonly terminalName?: string;
public readonly useVsCodeApi: boolean;

constructor(
label: string,
commandString: string,
useVsCodeApi: boolean = false,
terminalName?: string,
buttonName?: string
) {
super(label, vscode.TreeItemCollapsibleState.None);
this.commandString = commandString;
this.useVsCodeApi = useVsCodeApi;
this.terminalName = terminalName;
this.buttonName = buttonName || label;
this.tooltip = commandString;
this.contextValue = "command";
this.command = {
arguments: [this],
command: "quickCommandButtons.executeFromTree",
title: "Execute",
};
}
}

export class GroupTreeItem extends vscode.TreeItem {
constructor(
public readonly label: string,
public readonly commands: ButtonConfig[]
) {
super(label, vscode.TreeItemCollapsibleState.Collapsed);
this.tooltip = `${commands.length} commands`;
this.contextValue = "group";
this.iconPath = new vscode.ThemeIcon("folder");
}
}

type TreeItem = CommandTreeItem | GroupTreeItem;

export const createTreeItemsFromGroup = (commands: ButtonConfig[], parentPath = ""): TreeItem[] => {
return commands.map((cmd, index) => {
const buttonId = parentPath ? `${parentPath}>${cmd.name}[${index}]` : `${cmd.name}[${index}]`;

if (cmd.group) {
return new GroupTreeItem(cmd.name, cmd.group);
}

return new CommandTreeItem(
cmd.name,
cmd.command || "",
cmd.useVsCodeApi || false,
cmd.terminalName,
buttonId
);
});
};

export const createRootTreeItems = (buttons: ButtonConfig[]): TreeItem[] => {
return buttons.map((button, index) => {
const buttonId = `${button.name}[${index}]`;

if (button.group) {
return new GroupTreeItem(button.name, button.group);
}

if (button.command) {
return new CommandTreeItem(
button.name,
button.command,
button.useVsCodeApi || false,
button.terminalName,
buttonId
);
}

return new CommandTreeItem(button.name, "", false, undefined, buttonId);
});
};
import { CommandTreeItem, GroupTreeItem, TreeItem, createTreeItems } from "../utils/ui-items";
export { CommandTreeItem, GroupTreeItem };

export class CommandTreeProvider implements vscode.TreeDataProvider<TreeItem> {
private _onDidChangeTreeData = new vscode.EventEmitter<TreeItem | undefined | null | void>();
Expand All @@ -103,7 +22,7 @@ export class CommandTreeProvider implements vscode.TreeDataProvider<TreeItem> {
}

if (element instanceof GroupTreeItem) {
return Promise.resolve(createTreeItemsFromGroup(element.commands, element.label));
return Promise.resolve(createTreeItems(element.commands, element.label));
}

return Promise.resolve([]);
Expand All @@ -117,6 +36,6 @@ export class CommandTreeProvider implements vscode.TreeDataProvider<TreeItem> {

private getRootItems = (): TreeItem[] => {
const buttons = this.configReader.getButtons();
return createRootTreeItems(buttons);
return createTreeItems(buttons);
};
}
16 changes: 3 additions & 13 deletions src/internal/show-all-commands.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import * as vscode from "vscode";
import { ButtonConfig } from "../pkg/types";
import { MESSAGES } from "../shared/constants";
import { ConfigReader, QuickPickCreator, TerminalExecutor } from "./adapters";
import { createQuickPickWithShortcuts, QuickPickItem } from "./command-executor";

export const createQuickPickItemsFromButtons = (buttons: ButtonConfig[]): QuickPickItem[] => {
return buttons.map((button) => ({
command: button,
description: button.group
? MESSAGES.INFO.commandsCount(button.group.length)
: button.command || "",
label: button.shortcut ? `${button.name} (${button.shortcut})` : button.name,
}));
};
import { createQuickPickWithShortcuts } from "./command-executor";
import { createQuickPickItems } from "./utils/ui-items";

export const createShowAllCommandsCommand = (
configReader: ConfigReader,
Expand All @@ -27,7 +17,7 @@ export const createShowAllCommandsCommand = (
return;
}

const items = createQuickPickItemsFromButtons(buttons);
const items = createQuickPickItems(buttons, true);

createQuickPickWithShortcuts(
{
Expand Down
108 changes: 108 additions & 0 deletions src/internal/utils/ui-items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import * as vscode from "vscode";
import { ButtonConfig } from "../../pkg/types";
import { MESSAGES } from "../../shared/constants";

export type QuickPickItem = {
command: ButtonConfig;
description: string;
label: string;
};

export type TreeItem = CommandTreeItem | GroupTreeItem;

export class CommandTreeItem extends vscode.TreeItem {
public readonly buttonName: string;
public readonly commandString: string;
public readonly terminalName?: string;
public readonly useVsCodeApi: boolean;

constructor(
label: string,
commandString: string,
useVsCodeApi: boolean = false,
terminalName?: string,
buttonName?: string
) {
super(label, vscode.TreeItemCollapsibleState.None);
this.commandString = commandString;
this.useVsCodeApi = useVsCodeApi;
this.terminalName = terminalName;
this.buttonName = buttonName || label;
this.tooltip = commandString;
this.contextValue = "command";
this.command = {
arguments: [this],
command: "quickCommandButtons.executeFromTree",
title: "Execute",
};
}
}

export class GroupTreeItem extends vscode.TreeItem {
constructor(
public readonly label: string,
public readonly commands: ButtonConfig[]
Comment thread
kubrickcode marked this conversation as resolved.
) {
super(label, vscode.TreeItemCollapsibleState.Collapsed);
this.tooltip = `${commands.length} commands`;
this.contextValue = "group";
this.iconPath = new vscode.ThemeIcon("folder");
}
}

export const createButtonId = (
buttonName: string,
index: number,
parentPath: string = ""
): string => {
return parentPath ? `${parentPath}>${buttonName}[${index}]` : `${buttonName}[${index}]`;
Comment thread
kubrickcode marked this conversation as resolved.
};

export const createQuickPickItem = (
button: ButtonConfig,
includeCommandCount: boolean = false
): QuickPickItem => {
const description =
button.group && includeCommandCount
? MESSAGES.INFO.commandsCount(button.group.length)
: button.command || "";

const label = button.shortcut ? `${button.name} (${button.shortcut})` : button.name;

return {
command: button,
description,
label,
};
};

export const createQuickPickItems = (
buttons: ButtonConfig[],
includeCommandCount: boolean = false
): QuickPickItem[] => {
return buttons.map((button) => createQuickPickItem(button, includeCommandCount));
};

export const createTreeItem = (
button: ButtonConfig,
index: number,
parentPath: string = ""
): TreeItem => {
const buttonId = createButtonId(button.name, index, parentPath);

if (button.group) {
return new GroupTreeItem(button.name, button.group);
}

return new CommandTreeItem(
button.name,
button.command || "",
button.useVsCodeApi || false,
button.terminalName,
buttonId
);
};

export const createTreeItems = (buttons: ButtonConfig[], parentPath: string = ""): TreeItem[] => {
return buttons.map((button, index) => createTreeItem(button, index, parentPath));
};
Comment thread
kubrickcode marked this conversation as resolved.
8 changes: 4 additions & 4 deletions src/tests/command-executor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
validateShortcuts,
findShortcutItem,
determineButtonExecutionType,
createQuickPickItems,
executeTerminalCommand,
executeCommandsRecursively,
executeTerminalCommand,
findShortcutItem,
validateShortcuts,
} from "../internal/command-executor";
import { createQuickPickItems } from "../internal/utils/ui-items";
import { ButtonConfig } from "../pkg/types";

describe("command-executor", () => {
Expand Down
Loading