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.

Comment From: gabyhelp

Related Issues and Documentation

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