-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcmd.ts
More file actions
131 lines (110 loc) · 4.21 KB
/
cmd.ts
File metadata and controls
131 lines (110 loc) · 4.21 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import * as os from 'os';
import * as fs from 'fs';
import * as vscode from 'vscode';
import * as path from 'path';
import { getWorkspaceFolder } from '../api';
import { executeCommand } from '../terminal';
import { readWorkspaceJson, writeWorkspaceJson } from '../webviews/project';
import { getMenuconfigMethod, MENUCONFIG_COMMANDS } from '../smart';
let _currentProject: string = '';
export function initCurrentProject(projectPath: string) {
if (projectPath) {
_currentProject = projectPath;
}
}
export function fastBuildProject(arg: any) {
if (arg) {
const cpus = os.cpus().length;
let cmd = 'scons -C ' + arg.fn + ' -j ' + cpus.toString();
executeCommand(cmd);
}
return;
}
export function configProject(arg: any) {
if (arg) {
const menuconfigMethod = getMenuconfigMethod();
if (menuconfigMethod.type === 'extension') {
// For rt-thread-kconfig extension, it handles multi-BSP scenarios automatically
if (menuconfigMethod.command === MENUCONFIG_COMMANDS.RT_THREAD_KCONFIG) {
// Change to the BSP directory first
executeCommand('cd ' + arg.fn);
// Execute the extension command
vscode.commands.executeCommand(menuconfigMethod.command);
}
// For vscode-kconfig-visual-editor, we need to open the Kconfig file explicitly
else if (menuconfigMethod.command === MENUCONFIG_COMMANDS.KCONFIG_VISUAL_EDITOR) {
const kconfigPath = path.join(arg.fn, 'Kconfig');
if (fs.existsSync(kconfigPath)) {
// Open the Kconfig file with the visual editor
vscode.workspace.openTextDocument(kconfigPath).then(
doc => {
vscode.window.showTextDocument(doc);
},
(error: Error) => {
vscode.window.showErrorMessage(`Failed to open Kconfig file: ${error.message}`);
// Fallback to terminal on error
let cmd = 'scons -C ' + arg.fn + ' --menuconfig';
executeCommand(cmd);
}
);
} else {
// Fallback to terminal if Kconfig doesn't exist
let cmd = 'scons -C ' + arg.fn + ' --menuconfig';
executeCommand(cmd);
}
}
else {
// Generic extension command
executeCommand('cd ' + arg.fn);
vscode.commands.executeCommand(menuconfigMethod.command!);
}
} else {
// For terminal-based menuconfig
let cmd = 'scons -C ' + arg.fn + ' --menuconfig';
executeCommand(cmd);
}
}
return;
}
export function openTerminalProject(arg: any) {
if (arg) {
let cmd = 'cd ' + arg.fn;
executeCommand(cmd);
}
return;
}
export function openProjectInNewWindow(arg: any) {
if (arg && arg.fn) {
// Open the BSP directory in a new VS Code window
vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.file(arg.fn), true);
}
return;
}
export function setCurrentProject(arg: any) {
if (arg) {
_currentProject = arg.fn;
let cmd = 'scons -C ' + arg.fn + ' --target=vsc_workspace';
executeCommand(cmd);
// update workspace.json file
let workspaceJson = readWorkspaceJson();
if (workspaceJson) {
const workspaceFolder = getWorkspaceFolder();
let relativeProject = arg.fn;
if (workspaceFolder && typeof arg.fn === 'string' && arg.fn.length > 0) {
if (path.isAbsolute(arg.fn)) {
relativeProject = path.relative(workspaceFolder, arg.fn);
}
}
workspaceJson.currentProject = relativeProject;
writeWorkspaceJson(workspaceJson);
}
}
return;
}
export function getCurrentProject() {
let rtconfig = getWorkspaceFolder() + '/' + 'rtconfig.h';
if (fs.existsSync(rtconfig)) {
return getWorkspaceFolder();
}
return _currentProject;
}