gopls version
v0.16.1
go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/NaroZeol/.cache/go-build'
GOENV='/home/NaroZeol/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/NaroZeol/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/NaroZeol/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.6'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2846889719=/tmp/go-build -gno-record-gcc-switches'
What did you do?
- open visual studio code
- git clone git://g.csail.mit.edu/6.5840-golabs-2024 6.5840
- open folder 6.5840
- open any go file in src/main
- set
"go.useLanguageServer": true
in vscode settings.json
What did you see happen?
many error messages of "main redeclared in this block (see details) compiler(DuplicateDecl)"
What did you expect to see?
Try to find a way to disable those error messages since I know they are not errors for me
Reason
I am doing MIT 6.824 lab
This lab runs application by
go run ***
So in src/main, many files contain package main
and func main
It is terrible when using vscode to edit which has many red underlines.
So I wonder if there has a way like c language extension to disable specific error messages.
I have searched the doc of analyzers but nothing works to me.
Comment From: gabyhelp
Related Issues and Documentation
- x/tools/gopls: "full error below" in error message a bit misleading? #44735 (closed)
- x/tools/gopls: inaccurate diagnostics after switching branches #52499 (closed)
- x/tools/gopls: 0.4.4 undeclared name errors on valid code #40553 (closed)
- x/tools/gopls: using hints results in error saying hints already specified when not #57470 (closed)
- x/tools/gopls: internal error: go list gives conflicting information for package #43821 (closed)
- x/tools/gopls: make command names more specific to avoid conflicts #41187 (closed)
- x/tools/gopls: import errors with multi-root workspace and gopls@v0.15.0+ #66145 (closed)
- gopls: Unable to build on vscode #35531 (closed)
- x/tools/gopls: invalid errors when using "pkgm" VS Code snippet #39296 (closed)
- x/tools/gopls: compilation error pop-up #41140 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: NaroZeol
I find a hack to temporarily disable them. https://code.visualstudio.com/updates/v1_85#_hide-problem-decorations
But unfortunately this setting will disable all errors, so it seems not to be a good solution.
So it will be nice if there is an official way like c/c++ extension.
Comment From: seankhliao
I believe this is working as intended, you can't go build a package containing multiple main declarations either.
Comment From: NaroZeol
you can't go build a package containing multiple main declarations either.
go seems to allow user to run a single go file by go run *.go
. In this case, many go file with duplicate declarations can be in a single folder.
I know it's not suitable for actual project. But if I am learning go, this will make sense.
So, it's not a bug on gopls. It's an advice about flexibility that allows user control specific error message appears or not.
Howerver, if you believe this feature will do harm to the code quality in average, I will agree with you.
Comment From: hyangah
Related #41206
Comment From: NaroZeol
Related #41206
According to this issue, I should add comment like // +build ignore
at the beginning of file
I add //go:build ignore
. It works well. Thanks a lot : )