Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example configuration for gopls #36

Open
RonanMacF opened this issue Dec 18, 2022 · 3 comments
Open

Add example configuration for gopls #36

RonanMacF opened this issue Dec 18, 2022 · 3 comments

Comments

@RonanMacF
Copy link

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
Copy link

zhou13 commented Mar 6, 2023

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

@nieomylnieja
Copy link

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
Copy link

baalimago commented Sep 14, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants