1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-08-01 04:57:44 +00:00

feat: add extension

This commit is contained in:
Kevin Amado 2022-02-12 16:55:52 -05:00
parent 3b596db702
commit f410df62da
No known key found for this signature in database
GPG key ID: FFF341057F503148
13 changed files with 2194 additions and 14 deletions

View file

@ -0,0 +1,31 @@
const vscode = require('vscode');
const { execFileSync } = require("child_process");
function activate(context) {
const config = vscode.workspace.getConfiguration("alejandra");
context.subscriptions.push(
vscode.languages.registerDocumentFormattingEditProvider("nix", {
provideDocumentFormattingEdits: (document, _, _) => {
const range = new vscode.Range(0, 0, document.lineCount, 0);
try {
const formattedText = execFileSync(config.path, { input: document.getText() });
return [vscode.TextEdit.replace(range, formattedText.toString())];
}
catch (e) {
vscode.window.showErrorMessage(`alejandra failed: ${e}`);
}
return;
}
})
);
}
function deactivate() {}
module.exports = {
activate,
deactivate
}