forked from r5n-labs/vscode-react-javascript-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
53 lines (48 loc) · 1.59 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
// 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 snippets = require('./snippets/snippets.json');
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
const convertSnippetArrayToString = snippetArray => snippetArray.join('\n');
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
console.log(
'Congratulations, your extension "snippet-search" is now active!'
);
let disposable = vscode.commands.registerCommand(
'extension.snippetSearch',
() => {
const items = Object.entries(snippets).map(
([shortDescription, { prefix, body, description }], id) => ({
id,
description: description || shortDescription,
label: prefix,
value: prefix,
body,
})
);
const options = {
matchOnDescription: true,
matchOnDetail: true,
placeHolder: 'Search snippet',
};
vscode.window.showQuickPick(items, options).then(({ body }) => {
const activeTextEditor = vscode.window.activeTextEditor;
const snippet =
typeof body === 'string' ? body : convertSnippetArrayToString(body);
activeTextEditor &&
activeTextEditor.insertSnippet(new vscode.SnippetString(snippet));
});
}
);
context.subscriptions.push(disposable);
}
exports.activate = activate;
function deactivate() {}
module.exports = {
activate,
deactivate,
};