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

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

Open
mjlbach opened this issue Dec 20, 2021 · 1 comment

Comments

@mjlbach
Copy link

@mjlbach mjlbach commented Dec 20, 2021

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.

@findleyr
Copy link
Contributor

@findleyr findleyr commented Dec 20, 2021

Thanks for the report. I agree this is a misbehavior on our part. Marking it for the next release.

@findleyr findleyr removed this from the Unreleased milestone Dec 20, 2021
@findleyr findleyr added this to the gopls/v0.7.5 milestone Dec 20, 2021
@findleyr findleyr removed this from the gopls/v0.7.5 milestone Jan 4, 2022
@findleyr findleyr added this to the gopls/v0.8.0 milestone Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants