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: How to disable error message DuplicateDecl on vscode? #68752

Closed
NaroZeol opened this issue Aug 6, 2024 · 6 comments
Closed

x/tools/gopls: How to disable error message DuplicateDecl on vscode? #68752

NaroZeol opened this issue Aug 6, 2024 · 6 comments
Labels
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

@NaroZeol
Copy link

NaroZeol commented Aug 6, 2024

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?

  1. open visual studio code
  2. git clone git://g.csail.mit.edu/6.5840-golabs-2024 6.5840
  3. open folder 6.5840
  4. open any go file in src/main
  5. 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.

@NaroZeol NaroZeol added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Aug 6, 2024
@gopherbot gopherbot added this to the Unreleased milestone Aug 6, 2024
@NaroZeol
Copy link
Author

NaroZeol commented Aug 6, 2024

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.

@seankhliao
Copy link
Member

I believe this is working as intended, you can't go build a package containing multiple main declarations either.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 7, 2024
@NaroZeol
Copy link
Author

NaroZeol commented Aug 7, 2024

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.

@hyangah
Copy link
Contributor

hyangah commented Aug 8, 2024

Related #41206

@NaroZeol
Copy link
Author

NaroZeol commented Aug 8, 2024

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 : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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