@microsoft/compose-language-service
Version:
Language service for Docker Compose documents
28 lines • 1.6 kB
JavaScript
/*!--------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Range, TextEdit } from 'vscode-languageserver';
import { ProviderBase } from './ProviderBase';
export class DocumentFormattingProvider extends ProviderBase {
on(params, token) {
if (params.document.yamlDocument.value.errors.length) {
// Won't return formatting info unless the document is syntactically correct
return Promise.resolve(undefined);
}
const options = {
indent: params.options.tabSize,
indentSeq: true,
simpleKeys: true, // todo?
nullStr: '',
lineWidth: 0,
};
const range = 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 Promise.resolve([TextEdit.replace(range, formatted)]);
}
}
//# sourceMappingURL=DocumentFormattingProvider.js.map