staticcheck raising errors in neovim

87 Views Asked by At

The staticcheck analyses aren't appearing in my Neovim setup. My expectation is that I'd see a finding for the strings.Replace call in the screenshot, but I do not. Instead, I see the following:

enter image description here

gopls configuration

["gopls"] = function()
    require('lspconfig').gopls.setup({
        settings = {
            gopls = {
                analyses = {
                    unusedparams = true,
                },
                completeUnimported = true,
                staticcheck = true,
                gofumpt = true,
            }
        }
    })
end

Debug steps

  • Ensured staticcheck is installed
  • Ensured staticcheck has findings for the file (staticcheck ./...)
  • Ensured gopls is setup by validating that gofumt works (i.e., created a formatting issue gofmt doesn't care about but gofumpt does care about, and it becomes formatted correctly)
  • Checked that native gopls findings work (e.g., creating an unused variable)
  • Restarted Neovim
  • Tried setting the static check using ["ui.diagnostic.staticcheck"] = true instead of staticcheck = true
  • Set the go version in the go.mod file in case there were any version mismatches.

Full LSP config using lazy.nvim

return {
    {
        "williamboman/mason.nvim",
        opts = {},
    },
    {
        "williamboman/mason-lspconfig.nvim",
        dependencies = { "williamboman/mason.nvim", },
    },
    {
        "folke/neodev.nvim",
        opts = {},
    },
    {
        "neovim/nvim-lspconfig",
        dependencies = { "williamboman/mason-lspconfig.nvim", },
    },
    {
        'VonHeikemen/lsp-zero.nvim',
        branch = 'v2.x',
        event = { "BufReadPre", "BufNewFile" },
        dependencies = {
            { 'neovim/nvim-lspconfig', },             -- Required
            { 'williamboman/mason.nvim', },           -- Optional
            { 'williamboman/mason-lspconfig.nvim', }, -- Optional

            { 'hrsh7th/nvim-cmp', },                  -- Required
            { 'hrsh7th/cmp-nvim-lsp', },              -- Required
            { 'L3MON4D3/LuaSnip', },                  -- Required
            { 'folke/neodev.nvim', },
        },
        keys = {
            { "<leader>e", "<cmd>lua vim.diagnostic.open_float(0, {scope=\"line\"})<cr>" },
            { "<leader>r", "<cmd>lua vim.lsp.buf.rename()<cr>" }
        },
        config = function()
            local lsp_zero = require('lsp-zero')

            lsp_zero.on_attach(function(_client, bufnr)
                lsp_zero.default_keymaps({ buffer = bufnr, preserve_mappings = false })
                lsp_zero.buffer_autoformat()
            end)

            require('mason-lspconfig').setup({
                ensure_installed = {
                    "lua_ls", "rust_analyzer", 'bashls',
                    'cssls', 'dockerls', 'eslint',
                    'golangci_lint_ls', 'gopls', 'html', 'htmx',
                    'biome', 'jsonls', 'tsserver', 'remark_ls',
                    'sorbet', 'sqlls', 'svelte', 'taplo',
                    'tailwindcss', 'yamlls',
                },
                automatic_installation = true,
                handlers = {
                    lsp_zero.default_setup,
                    ["gopls"] = function()
                        require('lspconfig').gopls.setup({
                            settings = {
                                gopls = {
                                    analyses = {
                                        unusedparams = true,
                                    },
                                    completeUnimported = true,
                                    staticcheck = true,
                                    gofumpt = true,
                                }
                            }
                        })
                    end
                },
            })

            local cmp = require('cmp')
            local cmp_format = require('lsp-zero').cmp_format()
            local cmp_action = require('lsp-zero').cmp_action()

            cmp.setup({
                sources = {
                    { name = 'nvim_lsp' },
                    { name = 'buffer' },
                },
                preselect = 'item',
                completion = {
                    completeopt = 'menu,menuone,noinsert'
                },
                mapping = cmp.mapping.preset.insert({
                    ['<CR>'] = cmp.mapping.confirm({ select = false }),
                    ['<Tab>'] = cmp_action.luasnip_supertab(),
                    ['<S-Tab>'] = cmp_action.luasnip_shift_supertab(),
                    ['<C-Space>'] = cmp.mapping.complete(),
                }),
                window = {
                    completion = cmp.config.window.bordered(),
                    documentation = cmp.config.window.bordered(),
                },
                snippet = {
                    expand = function(args)
                        require('luasnip').lsp_expand(args.body)
                    end,
                },
                formatting = cmp_format,
            })
        end,
    },
}
0

There are 0 best solutions below