-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.ts
120 lines (114 loc) · 4.41 KB
/
extension.ts
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
import * as vscode from 'vscode';
import path from 'path';
import { XycodeUI } from './XycodeUI';
import { Util } from './Util.js';
import { Config, TaskUtil } from './Config';
import { ConfigManager, ConfigDesc } from './ConfigManager';
import { ExtConst } from './ExtConst';
import { CommandRunner } from './CommandRunner';
import { CommandRunnerOptions } from './BaseCommandRunner';
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
const xycodeui = XycodeUI.instance;
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
// The command has been defined in the package.json file
context.subscriptions.push(vscode.commands.registerCommand(`${ExtConst.extName}.open`, async () => {
const config = Config.data;
if(config.tasks.length === 0){
vscode.commands.executeCommand(`${ExtConst.extName}.config`);
return;
}
const task = await vscode.window.showQuickPick(config.tasks.filter(task => TaskUtil.isTaskActive(task)));
if (!task) { return false; }
const configVars = Util.getUserConfig(config.variables);
const options :CommandRunnerOptions = {
maxBuffer: Util.maxBuffer,
encoding: task.encoding || Util.encoding,
isWslMode: Util.isWslMode,
shellPath: Util.shellPath
};
if(task.notShowProcess){
new CommandRunner(options).run(task, configVars, Util.file, Util.workspaceFolder);
} else {
vscode.window.withProgress(
{
location: vscode.ProgressLocation.Window,
title: `${ExtConst.extName} running ${task.label}`
},
async progress => {
// Progress is shown while this function runs.
// It can also return a promise which is then awaited
await new CommandRunner(options).run(task, configVars, Util.file, Util.workspaceFolder);
}
);
}
}));
if(ExtConst.isRegistConfigCommand){
context.subscriptions.push(vscode.commands.registerCommand(`${ExtConst.extName}.config`, async () => {
try {
const cm = new ConfigManager();
const configList = await cm.getConfigList();
if(configList === undefined){
xycodeui.showErrorMessage(`${ExtConst.extName} get config error`);
return;
}
const selectList: Array<ConfigDesc> | undefined = await vscode.window.showQuickPick(configList, {
canPickMany: true,
placeHolder: "Please Download Config For ${ExtConst.extName}"
});
if(selectList){
selectList.forEach(async (desc) => {
try {
await cm.download(desc);
xycodeui.channelShow(`${desc.name} download ok!`);
} catch (error) {
xycodeui.showErrorMessage(`${ExtConst.extName} download config exception ${error}`);
}
});
xycodeui.showInformationMessage(`${ExtConst.extName} Config Download done! Enjoy yourself!`);
}
} catch (error) {
xycodeui.showErrorMessage(`${ExtConst.extName} ${error}`);
}
}));
}
vscode.workspace.onDidSaveTextDocument(async (doc) =>{
const config = Config.data;
const fileType = path.extname(doc.fileName);
const tasks = config.onSaveEvents?.filter(task => TaskUtil.isTaskActive(task, fileType));
const maxBuffer = Util.maxBuffer;
const encoding = Util.encoding;
const isWslMode = Util.isWslMode;
const shellPath = Util.shellPath;
await tasks?.forEach(async (task) => {
const options :CommandRunnerOptions = {
maxBuffer: maxBuffer,
encoding: task.encoding || encoding,
isWslMode: isWslMode,
shellPath: shellPath
};
if(task.notShowProcess){
new CommandRunner(options).run(task, Util.getUserConfig(config.variables), doc.fileName, Util.workspaceFolder);
} else {
vscode.window.withProgress(
{
location: vscode.ProgressLocation.Window,
title: `${ExtConst.extName} running ${task.label}`
},
async progress => {
// Progress is shown while this function runs.
// It can also return a promise which is then awaited
await new CommandRunner(options).run(task, Util.getUserConfig(config.variables), doc.fileName, Util.workspaceFolder);
}
);
}
});
});
if(ExtConst.isShowMessage){
xycodeui.channelShow(ExtConst.message);
}
}
// this method is called when your extension is deactivated
export function deactivate() {}