Refine gutter messages and add go build checking to go plugin

This commit is contained in:
Zachary Yedidia
2016-04-28 20:43:45 -04:00
parent d933efc53d
commit 30c7a9c4a5
2 changed files with 81 additions and 48 deletions

View File

@@ -5,7 +5,10 @@ function go_onSave()
elseif settings.GoFmt then
go_gofmt()
end
go_build()
go_golint()
view:ReOpen()
end
end
@@ -13,37 +16,49 @@ function go_gofmt()
local handle = io.popen("gofmt -w " .. view.Buf.Path)
local result = handle:read("*a")
handle:close()
view:ReOpen()
end
function go_golint()
view:ClearGutterMessages("go-lint")
local handle = io.popen("golint " .. view.Buf.Path)
local result = go_split(handle:read("*a"), ":")
local lines = go_split(handle:read("*a"), "\n")
handle:close()
local file = result[1]
local line = tonumber(result[2])
local col = tonumber(result[3])
local msg = result[4]
for _,line in ipairs(lines) do
local result = go_split(line, ":")
local line = tonumber(result[2])
local msg = result[4]
view:ReOpen()
view:GutterMessage(line, msg, 2)
view:GutterMessage("go-lint", line, msg, 2)
end
end
function go_build()
view:ClearGutterMessages("go-build")
local handle = io.popen("go build " .. view.Buf.Path .. " 2>&1")
local lines = go_split(handle:read("*a"), "\n")
handle:close()
messenger:Message(view.Buf.Path)
for _,line in ipairs(lines) do
local line, msg = string.match(line, ".+:(%d+):(.+)")
view:GutterMessage("go-build", tonumber(line), msg, 2)
end
end
function go_goimports()
local handle = io.popen("goimports -w " .. view.Buf.Path)
local result = go_split(handle:read("*a"), ":")
handle:close()
view:ReOpen()
end
function go_split(str, sep)
local result = {}
local regex = ("([^%s]+)"):format(sep)
for each in str:gmatch(regex) do
table.insert(result, each)
end
return result
local result = {}
local regex = ("([^%s]+)"):format(sep)
for each in str:gmatch(regex) do
table.insert(result, each)
end
return result
end