-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/gopls: stale embed diagnostics when preceded by const block #47436
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
Comments
Interesting. I could reproduce this in vscode too. |
…ata reload is required ParseHeader mode is used to parse only the package and import declarations. However, change of go:embed directive should also invalidate metadata. So, we must use ParseFull mode to get all file comments to compare old and new go:embed directives. Fixes golang/go#47436
Change https://golang.org/cl/339469 mentions this issue: |
I could find the reason why the diagnostic works if main.go: package main
import (
"fmt"
"go/parser"
"go/token"
)
func main() {
const (
mode = parser.ImportsOnly | parser.ParseComments
src = `
// Package main ...
package main
import (
// fmt import ...
_ "fmt"
_ "github.com/pkg/errors" // errors import ...
)
// F ...
func F() {}
// B ...
func B() {}
// Hello ...
const Hello = "word"
`
)
f, err := parser.ParseFile(token.NewFileSet(), "x.go", src, mode)
if err != nil {
panic(err)
}
for _, c := range f.Comments {
fmt.Printf("%q\n", c.Text())
}
} Output:
|
Thanks for the fix, @ShoshinNikita! |
@ShoshinNikita: That definitely seems like a bug! If you can, please open a new issue in this repo with the prefix "go/parser: " and include a playground link to your repro case. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Firstly, a demonstration of a working setup:
Sequence is:
main.go
go:embed
directiveThe corresponding log file: working.log
Things go wrong however if there is a
const
declaration list before thego:embed
directive (at least my hacking seems to demonstrate this as the problem):Sequence is:
main.go
go:embed
directivegovim
+gopls
, because it is "stuck" at this point, and re-open.What did you expect to see?
Consistent behaviour with respect to
go:embed
error diagnostics.What did you see instead?
As above.
cc @stamblerre
FYI @leitzler
The text was updated successfully, but these errors were encountered: