Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public onDocumentFormatting = ({
textDocument,
options
}: DocumentFormattingParams): TextEdit[] => {
const doc = this.documents.get(textDocument.uri)!;
const { fsPath } = URI.parse(textDocument.uri);
try {
const text = doc.getText();
const markoCompiler = loadMarkoFile(fsPath, "compiler");
const CodeWriter = loadMarkoFile(fsPath, "compiler/CodeWriter");
const formatted = prettyPrint(text, {
markoCompiler,
CodeWriter,
filename: fsPath,
indent: (options.insertSpaces ? " " : "\t").repeat(options.tabSize)
});
return [
TextEdit.replace(
Range.create(doc.positionAt(0), doc.positionAt(text.length)),
formatted
)
];
} catch (e) {
this.displayMessage("error", 'Formatting failed: "' + e.message + '"');
}