Skip to content

[gopls]: a new client is started when opening files in the std lib path #3940

@balpert89

Description

@balpert89

Description

Hi there,

I stumbled upon a weird issue with gopls and how it handles / registers files outside of the configured root dir.

If a file resides outside of the root_dir (commonly files in mod cache or the standard library files found in GOROOT) using vanilla lsp configuration, I can see a started client for each directory of my current project, mod cache and GOROOT. This results in weird behavior how diagnostics are shown, false-positive messages where variables could not be found and so on:

Image

Using the configuration at https://github.com/neovim/nvim-lspconfig/blob/7fac9025a967a4d0846660f751cd392fac6bb788/lsp/gopls.lua this is solved partially as the get_root function checks for mod cache files if there already is a client for gopls, otherwise it creates one. What is missing is the same check for std lib files. I have implemented a fix in my own configuration.

Question: does it make sense to open a PR to upstream this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    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