govim / govim

govim is a Go development plugin for Vim8, written in Go
BSD 3-Clause "New" or "Revised" License
869 stars 62 forks source link

cmd/govim: support modules with a program per .go file #437

Open eliasnaur opened 5 years ago

eliasnaur commented 5 years ago

What version of Vim/Gvim are you using?

Vim/Gvim version
$ vim --version
Warning: Failed to set locale category LC_NUMERIC to en_DK.
Warning: Failed to set locale category LC_TIME to en_DK.
Warning: Failed to set locale category LC_COLLATE to en_DK.
Warning: Failed to set locale category LC_MONETARY to en_DK.
Warning: Failed to set locale category LC_MESSAGES to en_DK.
VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 16 2019 03:25:28)
macOS version
Included patches: 1-1700
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             -mouse_sysmouse    -tag_any_white
+arabic            +file_in_path      +mouse_urxvt       -tcl
+autocmd           +find_in_path      +mouse_xterm       +termguicolors
+autochdir         +float             +multi_byte        +terminal
-autoservername    +folding           +multi_lang        +terminfo
-balloon_eval      -footer            -mzscheme          +termresponse
+balloon_eval_term +fork()            +netbeans_intg     +textobjects
-browse            +gettext           +num64             +textprop
++builtin_terms    -hangul_input      +packages          +timers
+byte_offset       +iconv             +path_extra        +title
+channel           +insert_expand     +perl              -toolbar
+cindent           +job               +persistent_undo   +user_commands
-clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           -python            +visual
+cmdline_info      +libcall           +python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo
+conceal           +lispindent        +reltime           +vreplace
+cryptv            +listcmds          +rightleft         +wildignore
+cscope            +localmap          +ruby              +wildmenu
+cursorbind        +lua               +scrollbind        +windows
+cursorshape       +menu              +signs             +writebackup
+dialog_con        +mksession         +smartindent       -X11
+diff              +modify_fname      -sound             -xfontset
+digraphs          +mouse             +spell             -xim
-dnd               -mouseshape        +startuptime       -xpm
-ebcdic            +mouse_dec         +statusline        -xsmp
+emacs_tags        -mouse_gpm         -sun_workshop      -xterm_clipboard
+eval              -mouse_jsbterm     +syntax            -xterm_save
+ex_extra          +mouse_netterm     +tag_binary
+extra_search      +mouse_sgr         -tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X -DMACOS_X_DARWIN  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o vim        -lncurses -liconv -lintl -framework AppKit  -L/usr/local/opt/lua/lib -llua5.3 -mmacosx-version-min=10.14 -fstack-protector-strong -L/usr/local/lib  -L/usr/local/Cellar/perl/5.30.0/lib/perl5/5.30.0/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc  -L/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin -lpython3.7m -framework CoreFoundation  -lruby.2.6

What version of Go are you using (go version)?

$ go version
go version devel +ea8b0acdac Thu Aug 1 15:39:45 2019 +0000 darwin/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/elias/Library/Caches/go-build"
GOENV="/Users/elias/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/elias/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/elias/go-tip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/elias/go-tip/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/elias/proj/gophercon-2019-talk/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_7/lnt35k555hl2bs7fjygkhgx00000gp/T/go-build880609516=/tmp/go-build -gno-record-gcc-switches -fno-common"

What version/commit of govim are you using?

7e1c6bf7e5188dee0aa4c8b08c3308d04eb3cf3c

What is the output of :messages in Vim?

Messages maintainer: Bram Moolenaar <Bram@vim.org>
"centering.go" 53L, 1223C
"animatedclipping.go" 75L, 1969C
(1 of 40): other declaration of main

Do the Vim channel, govim or gopls log files show anything interesting?

I don't think they show more than the errors shown from reproducing my use case below. Let me know if you need the log files.

How did you install govim?

In ~/.vim/pack/plugins/start/govim. I suppose that's Vim 8 packages.

What did you do?

$ git clone https://github.com/eliasnaur/gophercon-2019-talk.git
$ cd gophercon-2019-talk
$ vim centering.go

What did you expect to see?

No errors.

What did you see instead?

Many errors, in the form of "(1 of 40): other declaration of main"

I believe this is caused by the gophercon-2019-talk repository structure where there is one module but several separate Go programs, each in a separate .go file.

myitcv commented 5 years ago

I'm not sure whether we can really expect govim (and gopls) to do much here without build tags in each file. Reason being, gopls (and go/packages that it uses under the hood) work per package, which for cmd/go means per directory. The directory in the git repo you linked is therefore a single package, but contains multiple entry points.

Did a structure like this work in vim-go or another editor?

eliasnaur commented 5 years ago

I'm not sure whether we can really expect govim (and gopls) to do much here without build tags in each file. Reason being, gopls (and go/packages that it uses under the hood) work per package, which for cmd/go means per directory. The directory in the git repo you linked is therefore a single package, but contains multiple entry points.

Did a structure like this work in vim-go or another editor?

Probably not. The reason for this issue is mostly govim's otherwise helpful error messages in the left-side "gutter". I think incorrect error messages are worse than no messages.

myitcv commented 5 years ago

I think incorrect error messages are worse than no messages.

Can you explain which of the errors you think are incorrect? Having multiple entry points in a main package within a build is, to my knowledge, not valid.

eliasnaur commented 5 years ago

I think incorrect error messages are worse than no messages.

Can you explain which of the errors you think are incorrect? Having multiple entry points in a main package within a build is, to my knowledge, not valid.

Depends on what "a build" is. For the gophercon-2019-talk module, every file is a build. To govim, the entire package is the build. I suppose this issue is about that difference resulting in spurious errors compared to what I see when I run go run one-of-the-files.go.

I can perfectly understand if this is out of scope of govim/gopls. I brought it up because the "gutter errors" are so clearly displayed but also just as misleading.

myitcv commented 5 years ago

compared to what I see when I run go run one-of-the-files.go

Right, I totally get where you're coming from now. Sorry, bit slow coming back from holiday!

This is definitely an angle worth us considering here and in gopls, because it has come up before.

But, and not to be too pessimistic, I don't hold out much hope! Simply because this is considered by many to be an edge case with an easy workaround: create a directory per .go file

myitcv commented 5 years ago

Raised https://github.com/golang/go/issues/33595 for discussion

myitcv commented 4 years ago

Now being discussed in https://github.com/golang/go/issues/41206