updates to dap and golangci-lint detection

This commit is contained in:
Fergus Molloy
2025-06-18 14:50:27 +01:00
parent 71b7bd7373
commit 309b47ceb5
5 changed files with 53 additions and 52 deletions

View File

@ -1,13 +1,6 @@
local M = { return {
filetypes = { 'go', 'gomod' }, enable = function() -- disable lsp if wrong version installed
}
-- disable lsp if wrong version installed
function M.enable()
local enable = true local enable = true
if
pcall(function()
vim vim
.system({ 'golangci-lint', '--version' }, { text = true }, function(out) .system({ 'golangci-lint', '--version' }, { text = true }, function(out)
if out.code ~= 0 then if out.code ~= 0 then
@ -20,12 +13,7 @@ function M.enable()
end end
end) end)
:wait() :wait()
end)
then
return enable
else
return false -- disable if golangci-lint isn't available
end
end
return M return enable
end,
}

View File

@ -31,16 +31,13 @@ function M.setup()
local lspconfig = require 'lspconfig' local lspconfig = require 'lspconfig'
for server, config in pairs(servers) do for server, config in pairs(servers) do
if require('lsp.utils').check_ft(server, config) then
if config['enable'] then if config['enable'] then
if not config['enable']() then if not config.enable() then
vim.notify('Disabling language server ' .. server, vim.log.levels.WARN) vim.notify('Disabling language server ' .. server, vim.log.levels.WARN)
goto continue goto continue
end end
end end
else
goto continue
end
config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities) config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities)
config.on_attach = require 'lsp.on_attach' config.on_attach = require 'lsp.on_attach'
vim.lsp.enable(server) vim.lsp.enable(server)

View File

@ -3,6 +3,7 @@ return {
{ {
'mfussenegger/nvim-dap', 'mfussenegger/nvim-dap',
dependencies = { dependencies = {
'theHamsta/nvim-dap-virtual-text',
'leoluz/nvim-dap-go', 'leoluz/nvim-dap-go',
view.get_config(), view.get_config(),
}, },
@ -21,18 +22,21 @@ return {
}, },
}, },
config = function() 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 { require('dap-go').setup {
dap_configurations = { dap_configurations = all_confs,
{
type = 'go',
name = 'Debug COSCT',
request = 'launch',
mode = 'test',
program = '${file}',
buildFlags = { '-tags=service_legacy' },
outputMode = 'remote',
},
},
} }
end, end,
}, },
@ -40,7 +44,7 @@ return {
'weissle/persistent-breakpoints.nvim', 'weissle/persistent-breakpoints.nvim',
ft = { 'go' }, ft = { 'go' },
opts = { opts = {
load_breakpoints_event = { 'VimEnter' }, load_breakpoints_event = { 'BufReadPost' },
}, },
keys = { keys = {
{ '<leader>db', '<cmd>PBToggleBreakpoint<cr>', desc = 'Toggle breakpoint' }, { '<leader>db', '<cmd>PBToggleBreakpoint<cr>', desc = 'Toggle breakpoint' },

View File

@ -0,0 +1,4 @@
local M = {
{ type = 'go', mode = 'test', name = 'example' },
}
return M

View File

@ -1,3 +1,4 @@
local last_test = {}
return { return {
{ {
'samharju/yeet.nvim', 'samharju/yeet.nvim',
@ -8,14 +9,21 @@ return {
custom_eval = function(cmd_string) custom_eval = function(cmd_string)
if cmd_string:match '#test' then if cmd_string:match '#test' then
-- get current win's filetype -- get current win's filetype
local bufnr = vim.api.nvim_win_get_buf(0) local ft = vim.bo[0].filetype
local ft = vim.bo[bufnr].filetype
if ft == 'go' then if ft == 'go' then
local dap_go = require 'dap-go-ts' local dap_go = require 'dap-go-ts'
local test = dap_go.closest_test() 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
end end