updates to dap and golangci-lint detection
This commit is contained in:
@ -1,31 +1,19 @@
|
|||||||
local M = {
|
return {
|
||||||
filetypes = { 'go', 'gomod' },
|
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
|
return enable
|
||||||
else
|
end,
|
||||||
return false -- disable if golangci-lint isn't available
|
}
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
||||||
|
|||||||
@ -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
|
||||||
else
|
|
||||||
goto continue
|
|
||||||
end
|
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)
|
||||||
|
|||||||
@ -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' },
|
||||||
|
|||||||
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 {
|
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user