updates to dap and golangci-lint detection
This commit is contained in:
@ -1,31 +1,19 @@
|
||||
local M = {
|
||||
filetypes = { 'go', 'gomod' },
|
||||
}
|
||||
return {
|
||||
enable = function() -- disable lsp if wrong version installed
|
||||
local enable = true
|
||||
vim
|
||||
.system({ 'golangci-lint', '--version' }, { text = true }, function(out)
|
||||
if out.code ~= 0 then
|
||||
enable = false
|
||||
return
|
||||
end
|
||||
if out.stdout:match ' 1%.%d+%.%d+' then
|
||||
enable = false
|
||||
return
|
||||
end
|
||||
end)
|
||||
:wait()
|
||||
|
||||
-- disable lsp if wrong version installed
|
||||
function M.enable()
|
||||
local enable = true
|
||||
|
||||
if
|
||||
pcall(function()
|
||||
vim
|
||||
.system({ 'golangci-lint', '--version' }, { text = true }, function(out)
|
||||
if out.code ~= 0 then
|
||||
enable = false
|
||||
return
|
||||
end
|
||||
if out.stdout:match ' 1%.%d+%.%d+' then
|
||||
enable = false
|
||||
return
|
||||
end
|
||||
end)
|
||||
:wait()
|
||||
end)
|
||||
then
|
||||
return enable
|
||||
else
|
||||
return false -- disable if golangci-lint isn't available
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
end,
|
||||
}
|
||||
|
||||
@ -31,16 +31,13 @@ function M.setup()
|
||||
local lspconfig = require 'lspconfig'
|
||||
|
||||
for server, config in pairs(servers) do
|
||||
if require('lsp.utils').check_ft(server, config) then
|
||||
if config['enable'] then
|
||||
if not config['enable']() then
|
||||
vim.notify('Disabling language server ' .. server, vim.log.levels.WARN)
|
||||
goto continue
|
||||
end
|
||||
if config['enable'] then
|
||||
if not config.enable() then
|
||||
vim.notify('Disabling language server ' .. server, vim.log.levels.WARN)
|
||||
goto continue
|
||||
end
|
||||
else
|
||||
goto continue
|
||||
end
|
||||
|
||||
config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities)
|
||||
config.on_attach = require 'lsp.on_attach'
|
||||
vim.lsp.enable(server)
|
||||
|
||||
@ -3,6 +3,7 @@ return {
|
||||
{
|
||||
'mfussenegger/nvim-dap',
|
||||
dependencies = {
|
||||
'theHamsta/nvim-dap-virtual-text',
|
||||
'leoluz/nvim-dap-go',
|
||||
view.get_config(),
|
||||
},
|
||||
@ -21,18 +22,21 @@ return {
|
||||
},
|
||||
},
|
||||
config = function()
|
||||
require('dap').set_log_level 'TRACE'
|
||||
require('nvim-dap-virtual-text').setup {}
|
||||
|
||||
local dir = vim.fn.getcwd(0)
|
||||
local contents = vim.fn.readblob(dir .. '/launch.json')
|
||||
local prj_confs = vim.json.decode(contents)
|
||||
local all_confs = prj_confs.configurations or {}
|
||||
|
||||
local global_confs = require 'plugins.dap.configurations'
|
||||
for _, conf in ipairs(global_confs) do
|
||||
table.insert(all_confs, conf)
|
||||
end
|
||||
|
||||
require('dap-go').setup {
|
||||
dap_configurations = {
|
||||
{
|
||||
type = 'go',
|
||||
name = 'Debug COSCT',
|
||||
request = 'launch',
|
||||
mode = 'test',
|
||||
program = '${file}',
|
||||
buildFlags = { '-tags=service_legacy' },
|
||||
outputMode = 'remote',
|
||||
},
|
||||
},
|
||||
dap_configurations = all_confs,
|
||||
}
|
||||
end,
|
||||
},
|
||||
@ -40,7 +44,7 @@ return {
|
||||
'weissle/persistent-breakpoints.nvim',
|
||||
ft = { 'go' },
|
||||
opts = {
|
||||
load_breakpoints_event = { 'VimEnter' },
|
||||
load_breakpoints_event = { 'BufReadPost' },
|
||||
},
|
||||
keys = {
|
||||
{ '<leader>db', '<cmd>PBToggleBreakpoint<cr>', desc = 'Toggle breakpoint' },
|
||||
|
||||
4
lua/plugins/dap/configurations.lua
Normal file
4
lua/plugins/dap/configurations.lua
Normal file
@ -0,0 +1,4 @@
|
||||
local M = {
|
||||
{ type = 'go', mode = 'test', name = 'example' },
|
||||
}
|
||||
return M
|
||||
@ -1,3 +1,4 @@
|
||||
local last_test = {}
|
||||
return {
|
||||
{
|
||||
'samharju/yeet.nvim',
|
||||
@ -8,14 +9,21 @@ return {
|
||||
custom_eval = function(cmd_string)
|
||||
if cmd_string:match '#test' then
|
||||
-- get current win's filetype
|
||||
local bufnr = vim.api.nvim_win_get_buf(0)
|
||||
local ft = vim.bo[bufnr].filetype
|
||||
local ft = vim.bo[0].filetype
|
||||
|
||||
if ft == 'go' then
|
||||
local dap_go = require 'dap-go-ts'
|
||||
local test = dap_go.closest_test()
|
||||
if not (test.name == nil or test.name == '') then
|
||||
last_test = test
|
||||
end
|
||||
end
|
||||
|
||||
cmd_string = cmd_string:gsub('#test', test.name)
|
||||
if next(last_test) ~= nil and not (last_test.name == nil or last_test.name == '') then
|
||||
cmd_string = cmd_string:gsub('#test', last_test.name)
|
||||
else
|
||||
vim.notify('Aborting run, no test found', vim.log.levels.WARN)
|
||||
return ''
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user