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

Fillstruct using gopls not working #3279

Closed
gitsang opened this issue Aug 16, 2021 · 3 comments · Fixed by #3282
Closed

Fillstruct using gopls not working #3279

gitsang opened this issue Aug 16, 2021 · 3 comments · Fixed by #3282
Milestone

Comments

@gitsang
Copy link

gitsang commented Aug 16, 2021

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

my code:

opt := &gitv5.CloneOptions{}

I run:

:let g:go_fillstruct_mode = 'gopls'
:GoFillStruct

What did you expect to happen?

I hope struct be filled like

opt := &gitv5.CloneOptions{
    URL:               "",
    Auth:              nil,
    RemoteName:        "",
    ReferenceName:     "",
    SingleBranch:      false,
    NoCheckout:        false,
    Depth:             0,
    RecurseSubmodules: 0,
    Progress:          nil,
    Tags:              0,
}

What happened instead?

but nothing happened

opt := &gitv5.CloneOptions{}

but

:let g:go_fillstruct_mode = 'fillstruct'

can work

Configuration (MUST fill this out):

vim-go version:

v1.25

vimrc you used to reproduce:

vimrc
let mapleader=" "
colorscheme molokai
set guifont=iosevka:h14:cANSI
set t_Co=256
set pastetoggle=<F12>
set nocompatible
set mouse-=a
set number
set showcmd
set wildmenu
set nowrap
set backspace=indent,eol,start
set encoding=utf-8 fileencodings=utf-8
syntax on

filetype off
filetype plugin indent on
filetype plugin on

if empty(glob(expand('~/.vim/autoload/plug.vim')))
    silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
    autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

call plug#begin()
    Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries', 'for': ['go'] }
        let g:syntastic_go_checkers = ['go', 'golint']
        let g:go_fmt_command = "goimports"
        let g:go_autodetect_gopath = 1
        let g:go_list_type = "quickfix"
        let g:go_auto_type_info = 1
        let g:go_version_warning = 0
        let g:go_highlight_types = 1
        let g:go_highlight_fields = 1
        let g:go_highlight_functions = 1
        let g:go_highlight_function_calls = 1
        let g:go_highlight_operators = 1
        let g:go_highlight_extra_types = 1
        let g:go_highlight_methods = 1
        let g:go_highlight_generate_tags = 1
        let g:go_def_mode = 'gopls'
        let g:go_fillstruct_mode = 'gopls'
        "let g:go_fillstruct_mode = 'fillstruct'
call plug#end()

Vim version (first three lines from :version):

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Aug  3 2020 21:19:15)
Included patches: 1-1359
Compiled by root@chensx.novalocal

Go version (go version):

go version go1.16.7 linux/amd64

Go environment

go env Output:
# go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY="*.sang.ink"
GONOSUMDB="*.sang.ink"
GOOS="linux"
GOPATH="/go"
GOPRIVATE="gitcode.sang.ink"
GOPROXY="https://goproxy.cn"
GOROOT="/usr/local/go/1.16.7"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/1.16.7/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.7"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/project/devops/configserver/cfgadmin/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-build1826992896=/tmp/go-build -gno-record-gcc-switches"

gopls version

gopls version Output:
# gopls version
golang.org/x/tools/gopls v0.7.1
    golang.org/x/tools/gopls@v0.7.1 h1:Mh3Z8Xcoq3Zy7ksSlwDV/nzQSbjFf06A+L+F8YHq55U=

@bhcleek
Copy link
Collaborator

bhcleek commented Aug 16, 2021

The gopls logs may provide the information that we need to understand why you're experiencing this. Can you execute :let g:go_debug=['lsp'] after :let g:go_fillstruct_mode = 'gopls' and before :GoFillStruct and then provide the LSP logs after running :GoFillStruct?

Without knowing what else is in your source file, it's difficult to know what the problem may be.

Can provide more complete replication steps?

@gitsang
Copy link
Author

gitsang commented Aug 19, 2021

my vimrc: https://raw.githubusercontent.com/gitsang/script/master/config/vim/.vimrc

git clone https://github.com/gitsang/dice-of-cthulhu.git
cd dice-of-cthulhu/pkg/service/
git reset --hard d0cafe2d452db0f216725ca4c6359866c78cacfc
vim http.go

62Gomsg:=Message{}<esc>
:let g:go_fillstruct_mode = 'gopls'<cr>
:let g:go_debug=['lsp']<cr>
:GoFillStruct<cr>

return

===== sent =====
Content-Length: 271

{"method":"textDocument/codeAction","jsonrpc":"2.0","id":6,"params":{"context":{"only":["refactor.rewrite"]},"range":{"end":{"character":14,"line":88},"start":{"character":14,"line":88}},"textDocument":{"uri":"file:///share/project/dice-of-cthulhu/pkg/service/http.go"}}}
===== received =====
Content-Length: 338

{"jsonrpc":"2.0","result":[{"title":"Fill Message","kind":"refactor.rewrite","edit":{},"command":{"title":"Fill Message","command":"gopls.apply_fix","arguments":[{"Fix":"fill_struct","URI":"file:///share/project/dice-of-cthulhu/pkg/service/http.go","Range":{"start":{"line":88,"character":6},"end":{"line":88,"character":15}}}]}}],"id":6}
===== sent =====
Content-Length: 191

{"method":"textDocument/definition","jsonrpc":"2.0","id":7,"params":{"textDocument":{"uri":"file:///share/project/dice-of-cthulhu/pkg/service/http.go"},"position":{"character":14,"line":88}}}
===== received =====
Content-Length: 75

{"jsonrpc":"2.0","error":{"code":0,"message":"no identifier found"},"id":7}

@bhcleek bhcleek added this to the vim-go 1.26 milestone Aug 19, 2021
@bhcleek
Copy link
Collaborator

bhcleek commented Aug 19, 2021

Thanks. I can duplicate this and will have a fix up shortly.

bhcleek added a commit to bhcleek/vim-go that referenced this issue Aug 19, 2021
Fix the command for fillstruct and revert
1795571, which was masking this
problem.

Fixes fatih#3279
bhcleek added a commit that referenced this issue Aug 19, 2021
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