From 309b47ceb56afc74854d73400faec5ea89776a82 Mon Sep 17 00:00:00 2001 From: Fergus Molloy Date: Wed, 18 Jun 2025 14:50:27 +0100 Subject: [PATCH] updates to dap and golangci-lint detection --- lua/lsp/golangci_lint_ls.lua | 46 +++++++++++------------------- lua/lsp/init.lua | 13 ++++----- lua/plugins/dap.lua | 28 ++++++++++-------- lua/plugins/dap/configurations.lua | 4 +++ lua/plugins/yeet.lua | 14 +++++++-- 5 files changed, 53 insertions(+), 52 deletions(-) create mode 100644 lua/plugins/dap/configurations.lua diff --git a/lua/lsp/golangci_lint_ls.lua b/lua/lsp/golangci_lint_ls.lua index 8d046e2..3ab29e7 100644 --- a/lua/lsp/golangci_lint_ls.lua +++ b/lua/lsp/golangci_lint_ls.lua @@ -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, +} diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index e272195..45667c6 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -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) diff --git a/lua/plugins/dap.lua b/lua/plugins/dap.lua index 421125f..45069cd 100644 --- a/lua/plugins/dap.lua +++ b/lua/plugins/dap.lua @@ -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 = { { 'db', 'PBToggleBreakpoint', desc = 'Toggle breakpoint' }, diff --git a/lua/plugins/dap/configurations.lua b/lua/plugins/dap/configurations.lua new file mode 100644 index 0000000..5c3613e --- /dev/null +++ b/lua/plugins/dap/configurations.lua @@ -0,0 +1,4 @@ +local M = { + { type = 'go', mode = 'test', name = 'example' }, +} +return M diff --git a/lua/plugins/yeet.lua b/lua/plugins/yeet.lua index c043545..408026f 100644 --- a/lua/plugins/yeet.lua +++ b/lua/plugins/yeet.lua @@ -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