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

Closed
mjlbach opened this issue Dec 20, 2021 · 8 comments
Assignees
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@mjlbach
Copy link

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.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Dec 20, 2021
@gopherbot gopherbot added this to the Unreleased milestone Dec 20, 2021
@findleyr
Copy link
Contributor

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

@bpar476
Copy link

bpar476 commented May 25, 2022

I'm also experiencing this issue in neovim 0.8.0

gopls -v version

Build info
----------
golang.org/x/tools/gopls v0.8.4
    golang.org/x/tools/gopls@v0.8.4 h1:zGZsAXAb0LLws/Z+2BCWR17dkPHhIO2GYwYSSkeXX5c=
    github.com/BurntSushi/toml@v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
    github.com/google/go-cmp@v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp/typeparams@v0.0.0-20220218215828-6cf2b201936e h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=
    golang.org/x/mod@v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
    golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
    golang.org/x/tools@v0.1.11-0.20220513164230-dfee1649af67 h1:CJwk4qG1fov4WP7/DWhhb7OQVZlQKAl1rEMnDF+ceGU=
    golang.org/x/vuln@v0.0.0-20220503210553-a5481fb0c8be h1:jokAF1mfylAi1iTQx7C44B7vyXUcSEMw8eDv0PzNu8s=
    honnef.co/go/tools@v0.3.0 h1:2LdYUZ7CIxnYgskbUZfY7FPggmqnh6shBqfWa8Tn3XU=
    mvdan.cc/gofumpt@v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.18

@findleyr
Copy link
Contributor

Thanks for the signal boost. This should be an easy fix, so I'll prioritize for v0.9.0 (the next release).

@findleyr findleyr modified the milestones: gopls/later, gopls/v0.9.0 May 25, 2022
@findleyr findleyr modified the milestones: gopls/v0.9.0, gopls/v0.9.1 Jul 1, 2022
@findleyr findleyr removed this from the gopls/v0.9.1 milestone Jul 13, 2022
@findleyr findleyr added this to the gopls/v0.9.2 milestone Jul 13, 2022
@findleyr
Copy link
Contributor

Thanks for the signal boost. This should be an easy fix, so I'll prioritize for v0.9.0 (the next release).

Just following up: unfortunately this didn't make v0.9.0, and v0.9.1 was a bugfix release for a specific regression, but this will be in v0.9.2. Sorry for the delay getting this out.

@gopherbot
Copy link

Change https://go.dev/cl/420539 mentions this issue: internal/lsp: re-send diagnostics on file events

@findleyr
Copy link
Contributor

findleyr commented Aug 2, 2022

Just confirming: this will be fixed in the next gopls release (v0.9.2) scheduled for next week.

If someone wants to confirm that this fixes the specific neovim bug that led to this issue, that would be awesome. Just need to install gopls from tip:

git clone https://go.googlesource.com/tools
cd tools/gopls
go install

Thanks all for your patience. This issue was filed during the Go 1.18 crunch, and so took longer to fix that would be ideal...

@jmarais
Copy link

jmarais commented Aug 3, 2022

I followed the case because I also experience the diagnostics disappearing after saving a buffer and it only re-appear when adding newlines again.

With the master gopls it seems like this was addressed. It looks like the inline diagnostics text appears when editing a buffer, and gets repainted when the buffer is saved.
I also check with 2 open buffers in a vertical split and it looks like diagnostics text reprint more consistently now if I have errors in both buffers (where on gopls 1.9.1 it looked like only 1 of the two splits will have diagnostic text).

This was checked with:
gopls: 0d04f65da922c811c0d443e902ea62bbc27e5fd9
nvim:

NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3

@findleyr
Copy link
Contributor

findleyr commented Aug 3, 2022

@jmarais thank you for confirming.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants