From 6cc2fe42c68155e4e2a4161ca83fe428ba69d31f Mon Sep 17 00:00:00 2001 From: Weslen Nascimento Date: Sat, 8 Feb 2020 10:13:47 -0300 Subject: [PATCH] fix formatter --- src/proto3Main.ts | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/proto3Main.ts b/src/proto3Main.ts index 8d757e6..1250dac 100644 --- a/src/proto3Main.ts +++ b/src/proto3Main.ts @@ -86,26 +86,23 @@ export function activate(ctx: vscode.ExtensionContext): void { }); vscode.languages.registerDocumentFormattingEditProvider('proto3', { - provideDocumentFormattingEdits(document: vscode.TextDocument): Thenable { - return document.save().then(x => { - - const style = getClangFormatStyle(document) - let args = []; - if (style) args.push(`-style=${style}`); - args.push(document.fileName); - - try { - var output = cp.execFileSync("clang-format", args); - if (output) { - let start = new vscode.Position(0, 0) - let end = new vscode.Position(document.lineCount, 0) - let range = new vscode.Range(start, end); - return [vscode.TextEdit.replace(range, output.toString())]; - } - } catch (e) { - vscode.window.showErrorMessage(e.message); + provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] { + const style = getClangFormatStyle(document) + let args = []; + if (style) args.push(`-style=${style}`); + args.push(document.fileName); + + try { + var output = cp.execFileSync("clang-format", args); + if (output) { + let start = new vscode.Position(0, 0) + let end = new vscode.Position(document.lineCount, 0) + let range = new vscode.Range(start, end); + return [vscode.TextEdit.replace(range, output.toString())]; } - }) + } catch (e) { + vscode.window.showErrorMessage(e.message); + } } });