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); + } } });