mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
feat: add extension
This commit is contained in:
parent
3b596db702
commit
f410df62da
13 changed files with 2194 additions and 14 deletions
31
integrations/vscode/extension.js
Normal file
31
integrations/vscode/extension.js
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue