-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
54 lines (47 loc) · 1.07 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
const vscode = require('vscode');
/**
* Folds regions of default level and all their inner regions up to level 7.
* @param resourceUri
*/
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
context.subscriptions.push(
vscode.commands.registerCommand(
'auto-collapse-blocks.activate',
foldAllCodeBlocks,
),
vscode.window.onDidChangeActiveTextEditor((editor) => {
if (editor) {
foldAllCodeBlocks();
}
}),
vscode.workspace.onDidSaveTextDocument((editor) => {
if (editor) {
foldAllCodeBlocks();
}
}),
);
}
function hasCollapsePragma(content) {
return /^\s*(\/*\*+|\/\/)\s*@collapse/m.test(content);
}
function foldAllCodeBlocks() {
if (
vscode.window.activeTextEditor &&
hasCollapsePragma(vscode.window.activeTextEditor.document.getText())
) {
for (let i = 0; i <= 7; i++) {
vscode.commands.executeCommand(`editor.foldLevel${i}`);
}
} else {
vscode.commands.executeCommand('editor.unfoldAll');
}
}
exports.activate = activate;
function deactivate() {}
module.exports = {
activate,
deactivate,
};