forked from LycanII/LzScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
68 lines (52 loc) · 2.63 KB
/
extension.js
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
const vscode = require('vscode');
const azdata = require('azdata');
const { runForInsert } = require('./generalFuncs');
function activate(context) {
context.subscriptions.push(vscode.commands.registerCommand('LzScripts.InsertToClip', (context) => {
const editor = vscode.window.activeTextEditor;
var selection = editor.selection;
var text = editor.document.getText(selection);
azdata.connection.getCurrentConnection().then(con => {
vscode.window.withProgress({ location: vscode.ProgressLocation.Notification },
async (progress) => {
progress.report({
message: 'Running Script!',
});
await runForInsert(con, text)
.then(res => {
vscode.env.clipboard.writeText(res.join('\n')).then((text) => {
vscode.window.showInformationMessage('Script copied to Clipboard!');
});
}).catch(err => { vscode.window.showErrorMessage(err.message); });
}
);
});
}));
context.subscriptions.push(vscode.commands.registerCommand('LzScripts.InsertToNewTab', (context) => {
const editor = vscode.window.activeTextEditor;
var selection = editor.selection;
var text = editor.document.getText(selection);
azdata.connection.getCurrentConnection().then(con => {
vscode.window.withProgress({ location: vscode.ProgressLocation.Notification },
async (progress) => {
progress.report({
message: 'Running Script!',
});
await runForInsert(con, text)
.then(res => {
vscode.commands.executeCommand('newQuery').then(s => {
let editor = vscode.window.activeTextEditor;
editor.edit(edit => { edit.insert(new vscode.Position(0, 0), res.join('\n')); });
vscode.window.showInformationMessage('Script copied to New Tab!');
});
}).catch(err => { vscode.window.showErrorMessage(err.message); });
}
);
});
}));
}
// this method is called when your extension is deactivated
function deactivate() {
}
exports.activate = activate;
exports.deactivate = deactivate;