-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
53 lines (41 loc) · 1.4 KB
/
extension.js
File metadata and controls
53 lines (41 loc) · 1.4 KB
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
const vscode = require('vscode');
let fs = require("fs");
let path = require("path");
let wastyle = require("wastyle");
let extensionPath = path.join(__dirname, "..");
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
(async () => {
extensionPath = context.extensionPath;
await wastyle.init(fs.readFileSync(`${extensionPath}/assets/astyle.wasm`));
['cpp', 'c', 'h', 'hpp', 'cc', 'cxx'].forEach((lang) => {
context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(lang, {
provideDocumentFormattingEdits(document, options, token) {
const text = document.getText();
const cmd_args = vscode.workspace.getConfiguration('cppformat').get('formatargs', '') || 'pad-oper unpad-paren max-continuation-indent=120 style=google';
const [success, formattedText] = wastyle.format(text, cmd_args);
if (!success) {
vscode.window.showInformationMessage("C/C++ Format: Error while trying to format.");
return [];
}
return [
vscode.TextEdit.replace(
new vscode.Range(0, 0, document.lineCount, 0),
formattedText
)
];
}
}));
});
context.subscriptions.push(vscode.commands.registerCommand('cppformat.helloWorld', function () {
vscode.window.showInformationMessage('Hello World from cppformat!');
}));
})();
}
function deactivate() { }
module.exports = {
activate,
deactivate
}