UNPKG

@microsoft/compose-language-service

Version:
32 lines 1.81 kB
"use strict"; /*!-------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See LICENSE in the project root for license information. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); exports.DocumentFormattingProvider = void 0; const vscode_languageserver_1 = require("vscode-languageserver"); const ProviderBase_1 = require("./ProviderBase"); class DocumentFormattingProvider extends ProviderBase_1.ProviderBase { on(params, token) { if (params.document.yamlDocument.value.errors.length) { // Won't return formatting info unless the document is syntactically correct return undefined; } const options = { indent: params.options.tabSize, indentSeq: true, simpleKeys: true, nullStr: '', lineWidth: 0, }; const range = vscode_languageserver_1.Range.create(params.document.textDocument.positionAt(0), params.document.textDocument.positionAt(params.document.textDocument.getText().length) // This technically goes past the end of the doc, but it's OK because the protocol accepts this (positions past the end of the doc are rounded backward) ); const formatted = params.document.yamlDocument.value.toString(options); // It's heavy-handed but the replacement is for the entire document // TODO is this terrible? return [vscode_languageserver_1.TextEdit.replace(range, formatted)]; } } exports.DocumentFormattingProvider = DocumentFormattingProvider; //# sourceMappingURL=DocumentFormattingProvider.js.map