0

I'm trying to refresh all my old school vim setup to lsp based ones. As part of this effort I'm going to use lazy.nvim as the plugin manager.

I was able to get everything working until the part where I need to setup gopls in lspconfigs. Here's my config:

{
"neovim/nvim-lspconfig",
opts = {
  servers = {
    gopls = {
      keys = {
        -- Workaround for the lack of a DAP strategy in neotest-go: https://github.com/nvim-neotest/neotest-go/issues/12
        { "<leader>td", "<cmd>lua require('dap-go').debug_test()<CR>", desc = "Debug Nearest (Go)" },
      },
      settings = {
        gopls = {
          gofumpt = false,
          codelenses = {
            gc_details = false,
            generate = true,
            regenerate_cgo = true,
            run_govulncheck = true,
            test = true,
            tidy = true,
            upgrade_dependency = true,
            vendor = true,
          },
          hints = {
            assignVariableTypes = true,
            compositeLiteralFields = true,
            compositeLiteralTypes = true,
            constantValues = true,
            functionTypeParameters = true,
            parameterNames = true,
            rangeVariableTypes = true,
          },
          analyses = {
            fieldalignment = true,
            nilness = true,
            unusedparams = true,
            unusedwrite = true,
            useany = true,
          },
          usePlaceholders = true,
          completeUnimported = true,
          staticcheck = true,
          directoryFilters = { "-.git", "-.vscode", "-.idea", "-.vscode-test", "-node_modules" },
          semanticTokens = false,
        },
      },
    },
  },
},

}

I copied this config straight from lazyvim configs, but then since I didn't have access to lazyvim.util I removed the part related to setup.

I'm not too sure if semanticTokensProvider is enabled in my machine, but I assume since I'm running the latest version of everything, it should be already enabled.

So when I try to open nvim, I get this error in the console:

[lspconfig] Cannot access configuration for setup. Ensure this server is listed in `server_configurations.md` or added as a custom server.                                 
Failed to run `config` for nvim-lspconfig                                                                                                                                  
...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:369: attempt to call field 'setup' (a table value)

I'm still exploring lua and lazy.nvim, that's why I'm not very familiar with the way syntax works. But I suspect my config needs a setup method or key. But the one that is provided in lazyvim, isn't compatible with my setup. Because even when I keep setup empty, I get the same error.

At this point I have run out of options. Most available docs are not for lazy.nvim. So it's a bit more challenging for me to troubleshoot my issue.

I'd really appreciate if you could help me with troubleshooting.

1 Answer 1

0

I couldn't figure out what was wrong with my issue. However, after doing more research I came across this lspconfig.lua file that was created very elegantly. So I was able to save my settings similar to their existing setups for other lsps.

It basically looks like this now:

return {
    "neovim/nvim-lspconfig",
    event = { "BufReadPre", "BufNewFile" },
    dependencies = {
        "hrsh7th/cmp-nvim-lsp",
        { "antosha417/nvim-lsp-file-operations", config = true },
    },
    config = function()
        -- import lspconfig plugin
        local lspconfig = require("lspconfig")

        -- import cmp-nvim-lsp plugin
        local cmp_nvim_lsp = require("cmp_nvim_lsp")

        local keymap = vim.keymap -- for conciseness

        local opts = { noremap = true, silent = true }

        -- configure gopls server (with special settings)
        lspconfig["gopls"].setup({
            capabilities = capabilities,
            on_attach = on_attach,
            settings = { -- custom settings for gopls
                gopls = {
                    gofumpt = false,
                    codelenses = {
                        gc_details = false,
                        generate = true,
                        regenerate_cgo = true,
                        run_govulncheck = true,
                        test = true,
                        tidy = true,
                        upgrade_dependency = true,
                        vendor = true,
                    },
                    hints = {
                        assignVariableTypes = true,
                        compositeLiteralFields = true,
                        compositeLiteralTypes = true,
                        constantValues = true,
                        functionTypeParameters = true,
                        parameterNames = true,
                        rangeVariableTypes = true,
                    },
                    analyses = {
                        fieldalignment = true,
                        nilness = true,
                        unusedparams = true,
                        unusedwrite = true,
                        useany = true,
                    },
                    usePlaceholders = true,
                    completeUnimported = true,
                    staticcheck = true,
                    directoryFilters = { "-.git", "-.vscode", "-.idea", "-.vscode-test", "-node_modules" },
                    semanticTokens = true,
                },
            },
        })
        
    end,
}
1
  • 1
    Welcome to Vim :-). Thanks for your contribution. In order to ensure its perenity, may be could you summarize the content of the link in the answer such that when the link will become invalid the answer will still be accessible. Dec 9, 2023 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.