Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes validation highlighting and problem reporting #177

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 62 additions & 66 deletions src/proto3Compiler.ts
Original file line number Diff line number Diff line change
@@ -1,82 +1,78 @@
'use strict';
"use strict";

import vscode = require('vscode');
import path = require('path');
import cp = require('child_process');
import vscode = require("vscode");
import path = require("path");
import cp = require("child_process");

import { Proto3Configuration } from './proto3Configuration';
import { Proto3Configuration } from "./proto3Configuration";

export class Proto3Compiler {
private _config: Proto3Configuration;
private _isProtocInPath: boolean;

private _config: Proto3Configuration;
private _isProtocInPath: boolean;

constructor(workspaceFolder?: vscode.WorkspaceFolder) {
this._config = Proto3Configuration.Instance(workspaceFolder);
try {
cp.execFileSync("protoc", ["-h"]);
this._isProtocInPath = true;
} catch (e) {
this._isProtocInPath = false;
}
constructor(workspaceFolder?: vscode.WorkspaceFolder) {
this._config = Proto3Configuration.Instance(workspaceFolder);
try {
cp.execFileSync("protoc", ["-h"]);
this._isProtocInPath = true;
} catch (e) {
this._isProtocInPath = false;
}
}

public compileAllProtos() {
let args = this._config.getProtocOptions();
// Compile in batch produces errors. Must be 1 by 1.
this._config.getAllProtoPaths().forEach(proto => {
this.runProtoc(args.concat(proto), undefined, (stdout, stderr) => {
vscode.window.showErrorMessage(stderr);
});
})
}
public compileAllProtos() {
let args = this._config.getProtocOptions();
// Compile in batch produces errors. Must be 1 by 1.
this._config.getAllProtoPaths().forEach((proto) => {
this.runProtoc(args.concat(proto), undefined, (stdout, stderr) => {
vscode.window.showErrorMessage(stderr);
});
});
}

public compileActiveProto() {
let editor = vscode.window.activeTextEditor;
if (editor && editor.document.languageId == 'proto3') {
let fileName = editor.document.fileName;
let args = this._config.getProtocOptions().concat(fileName);
public compileActiveProto() {
let editor = vscode.window.activeTextEditor;
if (editor && editor.document.languageId == "proto3") {
let fileName = editor.document.fileName;
let args = this._config.getProtocOptions().concat(fileName);

this.runProtoc(args, undefined, (stdout, stderr) => {
vscode.window.showErrorMessage(stderr);
});
}
this.runProtoc(args, undefined, (stdout, stderr) => {
vscode.window.showErrorMessage(stderr);
});
}
}

public compileProtoToTmp(fileName: string, callback?: (stderr: string) =>void) {
let proto = path.relative(vscode.workspace.rootPath, fileName);
public compileProtoToTmp(fileName: string, callback?: (stderr: string) => void) {
let args = this._config.getProtoPathOptions().concat(this._config.getTmpJavaOutOption(), fileName);

let args = this._config.getProtoPathOptions()
.concat(this._config.getTmpJavaOutOption(), proto);
this.runProtoc(args, undefined, (stdout, stderr) => {
if (callback) {
callback(stderr);
}
});
}

this.runProtoc(args, undefined, (stdout, stderr) => {
if (callback) {
callback(stderr);
}
});
private runProtoc(args: string[], opts?: cp.ExecFileOptions, callback?: (stdout: string, stderr: string) => void) {
let protocPath = this._config.getProtocPath(this._isProtocInPath);
if (protocPath == "?") {
return; // protoc is not configured
}

private runProtoc(args: string[], opts?: cp.ExecFileOptions, callback?: (stdout: string, stderr: string) =>void) {
let protocPath = this._config.getProtocPath(this._isProtocInPath)
if (protocPath == "?") {
return // protoc is not configured
}

if( !opts ) {
opts = {};
}
opts = Object.assign(opts, {cwd: vscode.workspace.rootPath});
cp.execFile(protocPath, args, opts, (err, stdout, stderr) => {
if(err && stdout.length == 0 && stderr.length == 0) {
// Assume the OS error if no messages to buffers because
// "err" does not provide error type info.
vscode.window.showErrorMessage(err.message);
console.error(err);
return
}
if (callback) {
callback(stdout, stderr);
}
});
if (!opts) {
opts = {};
}
}
opts = Object.assign(opts, { cwd: vscode.workspace.rootPath });
cp.execFile(protocPath, args, opts, (err, stdout, stderr) => {
if (err && stdout.length == 0 && stderr.length == 0) {
// Assume the OS error if no messages to buffers because
// 'err' does not provide error type info.
vscode.window.showErrorMessage(err.message);
console.error(err);
return;
}
if (callback) {
callback(stdout, stderr);
}
});
}
}