Skip to content

folds disappear on :GoImports call #2789

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

Closed
salarkhan opened this issue Mar 28, 2020 · 9 comments · Fixed by #2791
Closed

folds disappear on :GoImports call #2789

salarkhan opened this issue Mar 28, 2020 · 9 comments · Fixed by #2791

Comments

@salarkhan
Copy link

What did you do? (required: The issue will be closed when not provided)

  1. installed vim-go
  2. set foldmethod config in vimrc
  3. set gopls config in vimrc
  4. open go file
  5. fold things
  6. call :GoImports

What did you expect to happen?

folds are maintained

What happened instead?

folds disappeared

Configuration (MUST fill this out):

vim-go version:

vimrc you used to reproduce (use a minimal vimrc with other plugins disabled; do not link to a 2,000 line vimrc):

vimrc
set nocompatible

call plug#begin('~/.vim/plugged')
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
call plug#end()

set hidden
set foldmethod=syntax
set viewoptions=cursor,folds,slash,unix

let g:go_highlight_extra_types = 1
let g:go_fmt_command = "gopls"

Vim version (first three lines from :version):

NVIM v0.3.8
Build type: Release
LuaJIT 2.1.0-beta3

Go version (go version):

go version go1.12 linux/amd64

Go environment

go env Output:
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/salarkhan/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/salarkhan/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/salarkhan/code/gitmux/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build167337996=/tmp/go-build -gno-record-gcc-switches"

@bhcleek
Copy link
Collaborator

bhcleek commented Mar 28, 2020

You can try using let g:go_fmt_experimental=1 in your vimrc to work around this.

As you noted in #2525, let g:go_fmt_experimental isn't perfect and comes with tradeoffs. Unfortunately, you're runnning into a long standing issue with vim-go that's unlikely to be fixed anytime soon.

However, I do intend to add support for using gopls to organize the imports, too. That will likely resolve the issue with folds.

@bhcleek
Copy link
Collaborator

bhcleek commented Mar 29, 2020

I nearly have a PR ready for using gopls for imports. When it's submitted, would you be willing to test it out?

bhcleek added a commit to bhcleek/vim-go that referenced this issue Mar 29, 2020
bhcleek added a commit to bhcleek/vim-go that referenced this issue Mar 29, 2020
@salarkhan
Copy link
Author

Absolutely!

bhcleek added a commit to bhcleek/vim-go that referenced this issue Mar 29, 2020
Add support for using `gopls` for `:GoImports`. A new option,
g:go_imports_command can be set to cause `:GoImports` to adjust imports
using `gopls.

Fixes fatih#2789
@bhcleek
Copy link
Collaborator

bhcleek commented Mar 29, 2020

Thank you 🙇

#2791 is ready to test.

@salarkhan
Copy link
Author

salarkhan commented Mar 30, 2020

hm, doesn't seem to work for me using neovim & vim-plug. here's my minimal .vimrc:

set nocompatible
call plug#begin(stdpath('config') . '/plugged')
Plug 'bhcleek/vim-go', { 'do': ':GoUpdateBinaries', 'branch': 'lsp/imports' }
call plug#end()
let g:go_fmt_command = "gopls"
set foldmethod=syntax
set viewoptions=cursor,folds,slash,unix

🤦‍♂️ ok, i just saw the go_imports_command flag. everything works so far!

@bhcleek
Copy link
Collaborator

bhcleek commented Mar 31, 2020

@salarkhan fyi, I spelled that option wrong in #2791. #2794 is coming very soon to correct that.

@salarkhan
Copy link
Author

salarkhan commented May 6, 2020

@bhcleek i've noticed that g:go_imports_mode:gopls organizes imports, but does not bring in missing ones. calling :GoImports manually, however, brings in missing imports. i prefer having folds preserved over auto-imports working, so i can live with it.

it's likely a gopls issue, not a vim-go issue, but i figured it would be helpful for you to be aware of this regardless

thanks for all your work in this super niche area!

@bhcleek
Copy link
Collaborator

bhcleek commented May 6, 2020

@salarkhan let's continue this in a new issue if needed.

But let g:go_import_mode="gopls" works to add imports, too; I use it all regularly. Perhaps you really did mean g:goimports_mode:gopls, though? If that's the case, then that second : should be = and the value needs to be quoted.

Thank you for your kind words 🙇

@salarkhan
Copy link
Author

ah, sorry for typing it incorrectly earlier, it was def set correctly in my vimdc. i'll open a new ticket for this:

let g:go_fmt_command = "gopls"
let g:go_imports_mode = "gopls"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants