-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextension.js
More file actions
93 lines (81 loc) · 2.78 KB
/
Copy pathextension.js
File metadata and controls
93 lines (81 loc) · 2.78 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
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');
const path = require('path');
var ncp = require("copy-paste");
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
let runIt = vscode.commands.registerCommand('make-runner.runIt', async function () {
let editor = vscode.window.activeTextEditor;
if (editor) {
const filename = editor.document.fileName.split('/').pop()
if (filename.toLocaleLowerCase() !== 'makefile') {
return
}
const config = vscode.workspace.getConfiguration().get('make-runner').env;;
const envs = Object.keys(config);
let env = {};
if (envs.length !== 0) {
const selection = await vscode.window.showQuickPick(envs);
if (!selection) {
return
}
env = config[selection];
}
if (typeof env !== 'object') {
vscode.window.showErrorMessage('Make Runner config set properly.');
return;
}
const exp = Object.keys(env).map(key => `${key}=${env[key]}`).join(' ');
const line = editor.selection.active.line;
const command = editor.document.lineAt(line).text.split(":")[0];
let terminal = vscode.window.activeTerminal;
if (!terminal) {
terminal = await vscode.window.createTerminal();
}
terminal.show();
terminal.sendText(`${exp} make -C ${path.dirname(editor.document.fileName)} ${command}`)
}
});
let copyIt = vscode.commands.registerCommand('make-runner.copyIt', async function () {
let editor = vscode.window.activeTextEditor;
if (editor) {
const filename = editor.document.fileName.split('/').pop()
if (filename.toLocaleLowerCase() !== 'makefile') {
return
}
const config = vscode.workspace.getConfiguration().get('make-runner').env;
const envs = Object.keys(config);
let env = {};
if (envs.length !== 0) {
const selection = await vscode.window.showQuickPick(envs);
if (!selection) {
return
}
env = config[selection];
}
if (typeof env !== 'object') {
vscode.window.showErrorMessage('Make Runner config set properly.');
return;
}
const exp = Object.keys(env).map(key => `${key}=${env[key]}`).join(' ');
const line = editor.selection.active.line;
const command = editor.document.lineAt(line).text.split(":")[0];
ncp.copy(`${exp} make -C ${path.dirname(editor.document.fileName)} ${command}`, function () {
console.log('copy completed')
})
}
});
context.subscriptions.push(copyIt, runIt);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() { }
module.exports = {
activate,
deactivate
}