-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
41 lines (36 loc) · 1.38 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
const vscode = require("vscode");
const { parseRegex } = require("./parse_regex/components/parseRegex.js");
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
console.log('Congratuations, the extension "parse_regex" is now active');
let disposable = vscode.commands.registerCommand(
"extension.parseRegex",
() => {
// Get active text editor
let editor = vscode.window.activeTextEditor;
if (editor) {
let document = editor.document;
// Get position of selected text
let selection = editor.selection;
// Get Line object of selection
let regexLine = document.lineAt(selection.end.line);
// Get the character position of the end of the line of selection
let endOfLine = regexLine._text.length + 1;
// Get highlighted regular expression
let regex = document.getText(selection);
// Parse regular expression
let parsedRegex = parseRegex(regex);
// Create a new position object to feed to insert function
let lineEnd = new vscode.Position(selection.end.line, endOfLine);
editor.edit((editBuilder) => {
// Insert line comment at the end of the line of the selection
editBuilder.insert(lineEnd, " // " + parsedRegex);
});
}
}
);
context.subscriptions.push(disposable);
}
module.exports = { activate };