Skip to content

Commit

Permalink
Merge pull request #73 from weslenng/fix-formatter
Browse files Browse the repository at this point in the history
Fix formatter
  • Loading branch information
zxh0 authored Feb 9, 2020
2 parents d6d2b72 + 6cc2fe4 commit aa8c480
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/proto3Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,23 @@ export function activate(ctx: vscode.ExtensionContext): void {
});

vscode.languages.registerDocumentFormattingEditProvider('proto3', {
provideDocumentFormattingEdits(document: vscode.TextDocument): Thenable<vscode.TextEdit[]> {
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);
}
}
});

Expand Down

0 comments on commit aa8c480

Please sign in to comment.