go lint
This commit is contained in:
parent
cef9652fae
commit
1caedf8c41
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/b3log/wide/conf"
|
||||
|
@ -199,6 +200,12 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
|||
buf := make([]byte, 1024*8)
|
||||
count, _ := reader.Read(buf)
|
||||
|
||||
channelRet := map[string]interface{}{}
|
||||
channelRet["output"] = string(buf[:count])
|
||||
channelRet["cmd"] = "build"
|
||||
channelRet["nextCmd"] = "run"
|
||||
channelRet["executable"] = executable
|
||||
|
||||
if 0 == count { // 说明构建成功,没有错误信息输出
|
||||
go func() { // 运行 go install,生成的库用于 gocode lib-path
|
||||
cmd := exec.Command("go", "install")
|
||||
|
@ -213,15 +220,28 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}()
|
||||
} else { // 构建失败
|
||||
// 解析错误信息,返回给编辑器 gutter lint
|
||||
lines := strings.Split(string(buf[:count]), "\n")[1:]
|
||||
lints := []map[string]interface{}{}
|
||||
|
||||
for _, line := range lines {
|
||||
if len(line) <= 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
channelRet := map[string]interface{}{}
|
||||
file := line[:strings.Index(line, ":")]
|
||||
left := line[strings.Index(line, ":")+1:]
|
||||
lineNo, _ := strconv.Atoi(left[:strings.Index(left, ":")])
|
||||
msg := left[strings.Index(left, ":")+2:]
|
||||
|
||||
channelRet["output"] = string(buf[:count])
|
||||
channelRet["cmd"] = "build"
|
||||
channelRet["nextCmd"] = "run"
|
||||
channelRet["executable"] = executable
|
||||
lint := map[string]interface{}{}
|
||||
lint["file"] = file
|
||||
lint["lineNo"] = lineNo - 1
|
||||
lint["msg"] = msg
|
||||
lints = append(lints, lint)
|
||||
}
|
||||
|
||||
channelRet["lints"] = lints
|
||||
}
|
||||
|
||||
if nil != outputWS[sid] {
|
||||
glog.V(3).Infof("Session [%s] 's build [id=%d, file=%s] has done", sid, runningId, filePath)
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
goLintFound = [];
|
||||
|
||||
(function(mod) {
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
CodeMirror.registerHelper("lint", "go", function(text) {
|
||||
var found = [];
|
||||
|
||||
found.push({from: CodeMirror.Pos(1, 1),
|
||||
to: CodeMirror.Pos(1, 10),
|
||||
message: "test commpile err"});
|
||||
|
||||
return found;
|
||||
return goLintFound;
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -7,12 +7,24 @@ outputWS.onmessage = function(e) {
|
|||
console.log('[output onmessage]' + e.data);
|
||||
var data = JSON.parse(e.data);
|
||||
|
||||
if (goLintFound) {
|
||||
goLintFound = [];
|
||||
}
|
||||
|
||||
if ('run' === data.cmd) {
|
||||
$('#output').text($('#output').text() + data.output);
|
||||
} else if ('build' === data.cmd) {
|
||||
$('#output').text(data.output);
|
||||
|
||||
if (0 !== data.output.length) { // 说明编译有错误输出
|
||||
for (var i = 0; i < data.lints.length; i++) {
|
||||
var lint = data.lints[i];
|
||||
|
||||
goLintFound.push({from: CodeMirror.Pos(lint.lineNo, 0),
|
||||
to: CodeMirror.Pos(lint.lineNo, 0),
|
||||
message: lint.msg});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
} else if ('go get' === data.cmd) {
|
||||
|
|
Loading…
Reference in New Issue