go.lua
1 return { 2 { 3 'neovim/nvim-lspconfig', 4 opts = { 5 servers = { 6 gopls = { 7 settings = { 8 gopls = { 9 filetypes = { 'go', 'gomod', 'gowork' }, 10 gofumpt = true, 11 build = { 12 templateExtensions = { 13 'gohtml', 14 'html', 15 'gotmpl', 16 'tmpl', 17 }, 18 }, 19 20 codelenses = { 21 gc_details = false, 22 generate = true, 23 regenerate_cgo = true, 24 run_govulncheck = true, 25 test = true, 26 tidy = true, 27 upgrade_dependency = true, 28 vendor = true, 29 }, 30 hints = { 31 assignVariableTypes = true, 32 compositeLiteralFields = true, 33 compositeLiteralTypes = true, 34 constantValues = true, 35 functionTypeParameters = true, 36 parameterNames = true, 37 rangeVariableTypes = true, 38 }, 39 analyses = { 40 fieldalignment = true, 41 nilness = true, 42 unusedparams = true, 43 unusedwrite = true, 44 useany = true, 45 }, 46 usePlaceholders = true, 47 completeUnimported = true, 48 staticcheck = true, 49 directoryFilters = { 50 '-.git', 51 '-.cache/**', 52 '-.gocache/**', 53 '-.vscode', 54 '-.idea', 55 '-.vscode-test', 56 '-node_modules', 57 }, 58 semanticTokens = true, 59 }, 60 }, 61 62 keys = { 63 -- Workaround for the lack of a DAP strategy in neotest-go 64 -- https://github.com/nvim-neotest/neotest-go/issues/12 65 { 66 '<leader>td', 67 "<cmd>lua require('dap-go').debug_test()<CR>", 68 desc = 'Debug Nearest (Go)', 69 }, 70 }, 71 root_dir = vim.fs.dirname(vim.fs.find({ 'go.work', 'go.mod' }, { upward = true })[1]), 72 }, 73 }, 74 setup = { 75 gopls = function() 76 require('lazyvim.util').lsp.on_attach(function(client, _) 77 if client.name == 'gopls' then 78 if client.config.capabilities == nil then 79 client.config.capabilities = { 80 workspace = { 81 didChangeWatchedFiles = { 82 dynamicRegistration = true, 83 }, 84 }, 85 } 86 end 87 if not client.server_capabilities.semanticTokensProvider then 88 local semantic = client.config.capabilities.textDocument.semanticTokens 89 if semantic then 90 client.server_capabilities.semanticTokensProvider = { 91 full = true, 92 legend = { 93 tokenTypes = semantic.tokenTypes, 94 tokenModifiers = semantic.tokenModifiers, 95 }, 96 range = true, 97 } 98 end 99 end 100 end 101 end) 102 end, 103 }, 104 }, 105 }, 106 }