-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
62 lines (54 loc) · 1.52 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
const vscode = require('vscode');
const request = require("request-promise");
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
let disposable = vscode.commands.registerCommand('oneliner.search', function () {
Search();
});
function Search() {
vscode.window.showInputBox({ placeHolder: 'Let\'s find what you 🔍 for' }).then(value => {
if (!value) return;
OneLiner(value);
})
}
async function OneLiner(query) {
var results = ['⬅️ back']
var matching = [{ 'title': '⬅️ back' }]
var response = await request.get('https://api.onelinerhub.com/search?query=' + query)
var body = JSON.parse(response)
for (var i = 0; i < body.length; i++) {
results.push(body[i].subject)
matching.push({ 'title': body[i].subject, 'url': body[i].url, 'code': body[i].code })
}
vscode.window.showQuickPick(results, { placeHolder: 'Choose your best' }).then(value => {
if (!value) return;
if (value == '⬅️ back') {
Search()
} else {
matching.map(key => {
if (key.title == value) {
OpenResult(key)
} else {
vscode.window.showInformationMessage('Something went wrong...')
}
});
}
})
}
function OpenResult(item) {
vscode.window.showInformationMessage(item.code, 'Explore').then(section => {
if (section == 'Explore') {
vscode.env.openExternal(vscode.Uri.parse(item.url));
}
});
}
context.subscriptions.push(disposable);
}
exports.activate = activate;
function deactivate() { }
module.exports = {
activate,
deactivate
}