UNPKG

greybel-languageserver-core

Version:
51 lines 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.activate = void 0; const greybel_transpiler_1 = require("greybel-transpiler"); const greyscript_transpiler_1 = require("greyscript-transpiler"); function activate(context) { async function tryFormat(content) { try { const config = context.getConfiguration(); return new greyscript_transpiler_1.DirectTranspiler({ code: content, buildType: greybel_transpiler_1.BuildType.BEAUTIFY, buildOptions: { isDevMode: true, keepParentheses: config.transpiler.beautify.keepParentheses, indentation: config.transpiler.beautify.indentation === 'Tab' ? 0 : 1, indentationSpaces: config.transpiler.beautify.indentationSpaces } }).parse(); } catch (err) { return null; } } context.connection.onDocumentFormatting(async (params) => { if (!context.getConfiguration().formatter) { return; } const document = await context.fs.getTextDocument(params.textDocument.uri); if (document == null) { return; } const activeDocument = await context.documentManager.getLatest(document); const result = await tryFormat(document.getText()); if (result === null) { return; } const textRange = { start: { line: 0, character: 0 }, end: activeDocument.parsedPayload.end }; return [ { range: textRange, newText: result } ]; }); } exports.activate = activate; //# sourceMappingURL=formatter.js.map