Skip to content

Commit aa8c480

Browse files
authored
Merge pull request #73 from weslenng/fix-formatter
Fix formatter
2 parents d6d2b72 + 6cc2fe4 commit aa8c480

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/proto3Main.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,23 @@ export function activate(ctx: vscode.ExtensionContext): void {
8686
});
8787

8888
vscode.languages.registerDocumentFormattingEditProvider('proto3', {
89-
provideDocumentFormattingEdits(document: vscode.TextDocument): Thenable<vscode.TextEdit[]> {
90-
return document.save().then(x => {
91-
92-
const style = getClangFormatStyle(document)
93-
let args = [];
94-
if (style) args.push(`-style=${style}`);
95-
args.push(document.fileName);
96-
97-
try {
98-
var output = cp.execFileSync("clang-format", args);
99-
if (output) {
100-
let start = new vscode.Position(0, 0)
101-
let end = new vscode.Position(document.lineCount, 0)
102-
let range = new vscode.Range(start, end);
103-
return [vscode.TextEdit.replace(range, output.toString())];
104-
}
105-
} catch (e) {
106-
vscode.window.showErrorMessage(e.message);
89+
provideDocumentFormattingEdits(document: vscode.TextDocument): vscode.TextEdit[] {
90+
const style = getClangFormatStyle(document)
91+
let args = [];
92+
if (style) args.push(`-style=${style}`);
93+
args.push(document.fileName);
94+
95+
try {
96+
var output = cp.execFileSync("clang-format", args);
97+
if (output) {
98+
let start = new vscode.Position(0, 0)
99+
let end = new vscode.Position(document.lineCount, 0)
100+
let range = new vscode.Range(start, end);
101+
return [vscode.TextEdit.replace(range, output.toString())];
107102
}
108-
})
103+
} catch (e) {
104+
vscode.window.showErrorMessage(e.message);
105+
}
109106
}
110107
});
111108

0 commit comments

Comments
 (0)