-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvscode-commands.ts
More file actions
64 lines (53 loc) · 2.42 KB
/
vscode-commands.ts
File metadata and controls
64 lines (53 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Import necessary modules
import * as vscode from 'vscode';
import { ConfigUtil } from '../utils/config-util';
/**
* Handles general VS Code related commands
*/
export function registerVSCodeCommands(context: vscode.ExtensionContext): void {
// Register Configure command
const configure = vscode.commands.registerCommand('apstoryScaffold.configure', async () => {
await ConfigUtil.openConfigFile();
});
// Register Configure Help command
const configureHelp = vscode.commands.registerCommand('apstoryScaffold.configureHelp', async () => {
await ConfigUtil.openConfigReadme();
});
// Create a status bar item
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
statusBarItem.text = "$(gear) Scaffold";
statusBarItem.tooltip = "Scaffold Tools";
statusBarItem.command = "apstoryScaffold.showCommands";
statusBarItem.show();
// Register a command to show available commands
const showCommands = vscode.commands.registerCommand('apstoryScaffold.showCommands', () => {
showCommandsMenu();
});
context.subscriptions.push(configure, configureHelp, statusBarItem, showCommands);
}
/**
* Shows a quick pick menu with commands based on the active file type
*/
export function showCommandsMenu(): void {
const activeEditor = vscode.window.activeTextEditor;
const fileExtension = activeEditor ? activeEditor.document.fileName.split('.').pop()?.toLowerCase() : '';
let commands = [];
// Always show Configure command
commands.push({ label: "Configure", command: "apstoryScaffold.configure" });
commands.push({ label: "Configuration Help", command: "apstoryScaffold.configureHelp" });
// TypeScript file commands
if (fileExtension === 'ts' || fileExtension === 'tsx') {
commands.push({ label: "Generate SQLite Repository", command: "extension.generateSQLiteRepo" });
}
// SQL file commands
if (fileExtension === 'sql') {
commands.push({ label: "Run Code Scaffold", command: "apstoryScaffold.runCodeScaffold" });
commands.push({ label: "Push SQL Changes", command: "apstoryScaffold.pushSqlChanges" });
commands.push({ label: "Delete", command: "apstoryScaffold.delete" });
}
vscode.window.showQuickPick(commands).then(selection => {
if (selection) {
vscode.commands.executeCommand(selection.command);
}
});
}