improve null_ls loading events and allow golangci_linter

linters to be configurable
pull/450/head
ray-x 1 month ago
parent 4d3fa34df0
commit abd282564a

@ -226,9 +226,6 @@ return {
nargs = '*',
})
-- vim.cmd([[command! GoTestCompile :setl makeprg=go\ build | :GoMake]])
--print-issued-lines=false
vim.cmd(
[[command! GoLint :setl makeprg=golangci-lint\ run\ --print-issued-lines=false\ --exclude-use-default=false | :GoMake]]
)

@ -125,13 +125,13 @@ local function get_test_filebufnr()
if not fn:find('test%.go$') then
fn = require('go.alternate').alternate()
fn = vfn.fnamemodify(fn, ':p') -- expand to full path
-- check if file exists
if vfn.filereadable(fn) == 0 then
return 0, 'no test file'
end
local uri = vim.uri_from_fname(fn)
bufnr = vim.uri_to_bufnr(uri)
log(fn, bufnr, uri)
if vfn.filereadable(vim.uri_to_fname(uri)) == 0 then
-- no test file existed
return 0, 'no test file'
end
if not vim.api.nvim_buf_is_loaded(bufnr) then
vfn.bufload(bufnr)
end
@ -547,6 +547,10 @@ M.get_test_cases = function()
fpath = '.' .. sep .. vfn.fnamemodify(vfn.expand('%:p'), ':.:r') .. '_test.go'
end
-- utils.log(args)
-- check if test file exists
if vfn.filereadable(fpath) == 0 then
return
end
local tests = M.get_testfunc()
if vim.fn.empty(tests) == 1 then
-- TODO maybe with treesitter or lsp list all functions in current file and regex with Test

@ -166,6 +166,7 @@ local h = require('null-ls.helpers')
local methods = require('null-ls.methods')
local DIAGNOSTICS_ON_SAVE = methods.internal.DIAGNOSTICS_ON_SAVE
local DIAGNOSTICS_ON_OPEN = methods.internal.DIAGNOSTICS_ON_OPEN
-- register with
-- null_ls.register(gotest)
@ -179,7 +180,7 @@ return {
url = 'https://golangci-lint.run/',
description = 'A Go linter aggregator.',
},
method = DIAGNOSTICS_ON_SAVE,
method = { DIAGNOSTICS_ON_OPEN, DIAGNOSTICS_ON_SAVE },
filetypes = { 'go' },
generator_opts = {
command = 'golangci-lint',
@ -192,14 +193,19 @@ return {
local rfname = vfn.fnamemodify(vfn.expand('%'), ':~:.')
trace(rfname) -- repplace $FILENAME ?
golangci_diags = {} -- CHECK: is here the best place to call
return {
local args = {
'run',
'--fix=false',
'--out-format=json',
'--path-prefix',
'$ROOT',
'$FILENAME',
}
for _, linter in ipairs(_GO_NVIM_CFG.null_ls.golangci_lint.disable) do
table.insert(args, '--disable=' .. linter)
end
for _, linter in ipairs(_GO_NVIM_CFG.null_ls.golangci_lint.enable) do
table.insert(args, '--enable=' .. linter)
end
args = vim.list_extend(args, { '--path-prefix', '$ROOT', '$FILENAME' })
return args
end,
check_exit_code = function(code)
if code > 2 then
@ -211,6 +217,7 @@ return {
return true
end,
on_output = function(msg, done)
trace('golangci-lint finished with code', done, msg)
if msg == nil then
return {}
end
@ -234,6 +241,7 @@ return {
for _, m in pairs(msgs) do
if vfn.empty(m) == 0 then
trace('lint message: ', m)
local entry = vfn.json_decode(m)
if entry['Report'] and entry['Report']['Error'] then
trace('report', entry['Report']['Error'])
@ -278,7 +286,7 @@ return {
local cmd = {}
return h.make_builtin({
name = 'gotest',
method = null_ls.methods.DIAGNOSTICS_ON_SAVE,
method = { DIAGNOSTICS_ON_OPEN, DIAGNOSTICS_ON_SAVE },
filetypes = { 'go' },
generator_opts = {
command = 'go',

Loading…
Cancel
Save