tamago324 / nlsp-settings.nvim

A plugin for setting Neovim LSP with JSON or YAML files
MIT License
314 stars 19 forks source link

Add example configuration for gopls #36

Open RonanMacF opened 1 year ago

RonanMacF commented 1 year ago

It's not clear how the JSON is supposed to be setup here, for example I have tried

{
  "analyses": {
    "fieldalignment": true,
    "nilness": true,
    "unusedparams": true,
    "unusedwrite": true,
    "unusedvariables": true
  }
}

Also tried the above with an outer gopls and against with an outer settings but it does not get applied to the gopls server, when I manually do the settings, for example as below, I see the linting appear.

require("lvim.lsp.manager").setup("gopls", {
    cmd = { "gopls", "serve" },
    filetypes = { "go", "gomod" },
    -- root_dir = util.root_pattern("go.work", "go.mod", ".git"),
    settings = {
        gopls = {
            analyses = {
                nilness = true,
                unusedparams = true,
                unusedwrite = true,
                useany = true,
            },
            experimentalPostfixCompletions = true,
            gofumpt = true,
            staticcheck = true,
            usePlaceholders = true,
        },
    },
})
zhou13 commented 1 year ago

You can write { "gopls.analyses.nilness": true} in your json file.

nieomylnieja commented 1 year ago

I was also totally confused by that, but, alas, there's a better way :) Do this instead:

{
  "gopls": {
    "ui.diagnostic.analyses": {
      "fieldalignment": true,
      "nilness": true,
      "unusedparams": true,
      "unusedwrite": true
    }
  }
}

Now you get all the suggestions from the schema too and it translates 1:1 with the official spec: https://github.com/golang/tools/blob/master/gopls/doc/settings.md

baalimago commented 10 months ago

Just as a gotcha for anyone else stumbling into my problem, which maybe were your original issue as well:

LspInstall will happily create a file for any string. So I created a go.json config file. Now this won't work, you need to create a gopls.json file (LspInstall gopls). If you do this, you'll also get automatic code-completions.

So keep in mind you're configuring the lsp, not the language preconfigured lsp.