Skip to content

x/tools/gopls: diagnostics should be resent when a file is closed via textDocument/didClose and subsequently reopened with textDocument/didOpen #50267

@mjlbach

Description

@mjlbach

gopls version

❯ gopls -v version
Build info

gopls, built in GOPATH mode master
gopls, built in GOPATH mode@master

go env

❯ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/michael/.cache/go-build"
GOENV="/home/michael/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/michael/.local/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/michael/.local/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.11"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/michael/Repositories/neovim_development/neovim-worktree/neovim/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1161291752=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Sent textDocument/didClose followed by textDocument/didOpen

What did you expect to see?

For most language servers, they will immediately re-send diagnostics as this is equivalent to opening a new file. See pyright:

[DEBUG][2021-12-19 19:34:29] .../vim/lsp/rpc.lua:344	"rpc.send"	{
  jsonrpc = "2.0",
  method = "textDocument/didClose",
  params = {
    textDocument = {
      uri = "file:///home/michael/Repositories/neovim_development/neovim-worktree/neovim/main.py"
    }
  }
}
[DEBUG][2021-12-19 19:34:29] .../vim/lsp/rpc.lua:344	"rpc.send"	{
  jsonrpc = "2.0",
  method = "textDocument/didOpen",
  params = {
    textDocument = {
      languageId = "python",
      text = "import os\n",
      uri = "file:///home/michael/Repositories/neovim_development/neovim-worktree/neovim/main.py",
      version = 0
    }
  }
}
[DEBUG][2021-12-19 19:34:29] .../vim/lsp/rpc.lua:451	"rpc.receive"	{
  jsonrpc = "2.0",
  method = "textDocument/publishDiagnostics",
  params = {
    diagnostics = {},
    uri = "file:///home/michael/Repositories/neovim_development/neovim-worktree/neovim/main.py"
  }
}

With gopls, no notification is sent:

[DEBUG][2021-12-19 19:36:45] .../vim/lsp/rpc.lua:344	"rpc.send"	{
  jsonrpc = "2.0",
  method = "textDocument/didClose",
  params = {
    textDocument = {
      uri = "file:///home/michael/Repositories/neovim_development/neovim-worktree/neovim/test.go"
    }
  }
}
[DEBUG][2021-12-19 19:36:45] .../vim/lsp/rpc.lua:344	"rpc.send"	{
  jsonrpc = "2.0",
  method = "textDocument/didOpen",
  params = {
    textDocument = {
      languageId = "go",
      text = "pakage main\n",
      uri = "file:///home/michael/Repositories/neovim_development/neovim-worktree/neovim/test.go",
      version = 0
    }
  }
}

What did you see instead?

I would expect diagnostics to be sent when opening the file, as they are on the first textdocument/didOpen request. This is consistent with other language servers.

Please see neovim/neovim#16623 (comment) for context.

Editor and settings

Neovim 0.6.0.

Logs

See above for the RPC messages.

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions