Skip to content

LSP specific settings defined in servers variable do not seem to be respected. #254

@KaFski

Description

@KaFski

Describe the bug
I wanted to configure some setting for few of LSP servers that I'm currently using. First I wanted to experiment with gopls, but even tho I've used their settings documentation I couldn't change the default settings. I'm quite new to Vim/Neovim & LSP land so not really sure how I can debug it properly.

I tried to look up the mason_lspconfig.setup_handlers{} function as this seemed as something there might be misconfigured. I opened and read the help and there is an example how to overwrite specific LSP server configuration, which I used to check if this may help and seems like it did the trick.

To Reproduce
So basically having following servers configuration

local servers = {
  gopls = {
    analyses = {
      unusedparams = true,
      shadow = true,
      loopclousure = false,
    },
    staticcheck = true,
  },
...
}

I don't get shadow and ususedparams analyses.

Screenshot from 2023-04-08 18-26-47

But if I put targeted override like following:

mason_lspconfig.setup_handlers {
  function(server_name)
    require('lspconfig')[server_name].setup {
      capabilities = capabilities,
      on_attach = on_attach,
      settings = servers[server_name],
    }
  end,
  ["gopls"] = function()
    require('lspconfig').gopls.setup {
      settings = {
        gopls = {
          analyses = {
            unusedparams = true,
            shadow = true,
            loopclousure = false,
          },
          staticcheck = true,
        },
      }
    }
  end,
}

All seems to work perfectly fine and I get additional diagnostic warnings for unused params and shadowed variables.

Screenshot from 2023-04-08 18-05-43

Desktop (please complete the following information):

  • OS: Linux 5.11.22-2-MANJARO
  • Terminal: zsh

Neovim Version

NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions