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

vim-go: godef: no declaration found for &{ controllers Test} in other package #3416

Closed
BraveSoilder opened this issue May 24, 2022 · 10 comments

Comments

@BraveSoilder
Copy link

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

I installed golang from wsl2 (go mod is not enabled), configured vim plugins such as: vim-go, etc.; and edited my project;

What did you expect to happen?

Godef can be used in other package; like "package test"

What happened instead?

When I use the godef jump function in the main package, it is normal; but when I continue to use the godef jump other function after jumping from the main package, vim-go displays "vim-go: godef: no declaration found for &{ controllers Test}"

Configuration (MUST fill this out):

vim-go version:

latest vim-go

vimrc you used to reproduce:

vimrc
"""""""""" Vundle""""""""""
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"vundle management
Plugin 'VundleVim/Vundle.vim'
Plugin 'majutsushi/tagbar'
Plugin 'jiangmiao/auto-pairs'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'tpope/vim-fugitive'
"vim-go
Plugin 'fatih/vim-go'
"YouCompleteMe
Plugin 'Valloric/YouCompleteMe'
Plugin 'scrooloose/nerdtree'
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
Plugin 'junegunn/limelight.vim'
Plugin 'vim-scripts/YankRing.vim'
Plugin 'airblade/vim-gitgutter'
Plugin 'haya14busa/incsearch.vim'
Plugin 'mbbill/undotree'
Plugin 'NLKNguyen/papercolor-theme'
Plugin 'dgryski/vim-godef'
call vundle#end()
""""""""""""""""""""""""""""""""
""""""""""vim config""""""""""
let mapleader="\<Space>"
set enc=utf-8
set fenc=utf-8
set fencs=utf-8,gb18030,gb2312,gbk,cp936
set termencoding=utf-8
set nobomb
set history=5000
set confirm
set background=dark
syntax enable
syntax on
set expandtab
set softtabstop=4
set tabstop=4
set shiftwidth=4
set wrap
set number
set formatoptions=tcrqn
set autoindent
set smartindent
set hlsearch
set incsearch
set ignorecase smartcase
set showcmd
set laststatus=2
set t_Co=256
set nocompatible
set guioptions-=r
set guioptions-=L
set guioptions-=r
set guioptions-=R
filetype on
filetype plugin on
filetype indent on
set nobackup
set noswapfile
set wildmenu
set cmdheight=1
set backspace=2
set shortmess=atl
set ttyfast
set ttymouse=xterm2
set noshowmode
set nocursorcolumn
set nocursorline
set lazyredraw
set maxmempattern=81920
map <silent> <leader>ss :source $HOME/.vimrc<cr>
map <silent> <leader>ee :e $HOME/.vimrc<cr>
autocmd BufReadPost *
     \ if line("'\"") > 0 && line("'\"") <= line("$") |
     \ exe "normal g`\"" |
     \ endif

""""""""""""""""""""""""""""""""""""
""""""""""""vim-go config"""""""""""""""
let g:go_bin_path = expand("~/.vim/bin")
let g:go_highlight_functions            = 1
let g:go_highlight_methods              = 1
let g:go_highlight_fields               = 1
let g:go_highlight_types                = 1
let g:go_highlight_operators            = 1
let g:go_highlight_build_constraints    = 1
let g:go_def_mode = 'godef'
"let g:go_gopls_options = ['-remote=auto']
let g:go_fmt_command = "goimports"
let g:go_play_open_browser = 0
let g:go_autodetect_gopath = 1
let g:go_list_type = "quickfix"
let g:go_gopls_enabled = 1
au FileType go map <F12>      <Plug>(go-def)
au FileType go nmap <Leader>ds <Plug>(go-def-split)
au FileType go nmap <Leader>dv <Plug>(go-def-vertical)
au FileType go nmap <Leader>dt <Plug>(go-def-tab)
" go-doc
au FileType go nmap <Leader>gd <Plug>(go-doc)
au FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
" goguru
au FileType go nmap <F9> :GoDecls<CR>

au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <Leader>e <Plug>(go-rename)

""""""""""""""""""""""""""""""""""""""""

""""""""""""nerdtree config"""""""""""""
map <F7> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
let NERDTreeShowHidden=1
let NERDTreeShowHidden=1
let NERDTreeWinSize=43
let NERDTreeShowBookmarks=1
let NERDTreeIgnore=['\.pyc','\~$','\.swp']
""""""""""""""""""""""""""""""""""""""""
"""""""""""""limelight config"""""""""""
nmap <Leader>i :Limelight0.7<CR>
nmap <Leader>I :Limelight!<CR>
let g:limelight_conceal_ctermfg = 'gray'
let g:limelight_conceal_ctermfg = 240
let g:limelight_conceal_guifg = 'DarkGray'
let g:limelight_conceal_guifg = '#777777'
let g:limelight_default_coefficient = 0.8
" Number of preceding/following paragraphs to include (default: 0)
let g:limelight_paragraph_span = 1
let g:limelight_bop = '^\s'
let g:limelight_eop = '\ze\n^\s'
let g:limelight_priority = -1
""""""""""""""""""""""""""""""""""""""""
"""""""""""""YankRing config""""""""""""
nnoremap <silent> <F6> :YRShow<CR>
let g:yankring_max_history = 13
let g:yankring_min_element_length = 5
let g:yankring_window_height = 16
let g:yankring_replace_n_pkey = ''
let g:yankring_replace_n_nkey = ''
"""""""""""""""""""""""""""""""""""""""""
"""""""""""""UltiSnips config""""""""""""
let g:UltiSnipsExpandTrigger="<c-j>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
"""""""""""""""""""""""""""""""""""""""""
"""""""""""" undotree config"""""""""""""
nmap <F10> :UndotreeToggle<CR>
let g:undotree_SetFocusWhenToggle = 1
if has("persistent_undo")
    set undodir=~/.vim/.undodir/
    set undofile
endif
"""""""""""""""""""""""""""""""""""""""""
""""""""""" airline config"""""""""""""""
let g:airline_theme='papercolor'
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#whitespace#symbol = '!'
if !exists('g:airline_symbols')
    let g:airline_symbols = {}
endif
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.linenr = ''
let g:airline_symbols.branch = ''
let g:airline_section_y = ''
"""""""""""""""""""""""""""""""""""""""""
"""""""""""""Paper Config""""""""""""""""
colorscheme PaperColor
let g:PaperColor_Theme_Options = {
\   'theme': {
\     'default.dark': {
\       'transparent_background': 1
\     }
\   }
\ }
"""""""""""""""""""""""""""""""""""""""""
""""""""""incsearch config"""""""""""""""
map /  <Plug>(incsearch-forward)
map ?  <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
"""""""""""""""""""""""""""""""""""""""""
"""""""""YouCompleteMe config""""""""""""
"let g:ycm_gopls_args = ['-remote=auto']
"let g:ycm_gopls_enabled =0
"""""""""""""""""""""""""""""""""""""""""
"""""""""vim-godef config""""""""""""""""
let g:godef_split=2
"""""""""""""""""""""""""""""""""""""""""

Vim version (first three lines from :version):

VIM - Vi IMproved 8.1

Go version (go version):

go version go1.18 linux/amd64

Go environment

go env Output:
GO111MODULE="off"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/use/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/use/godev/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/use/godev"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/data/env/golang/default"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/data/env/golang/default/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
GOWORK=""
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-build3540764608=/tmp/go-build -gno-record-gcc-switches"

gopls version

gopls version Output:
the vim-go comes with gopls
@BraveSoilder
Copy link
Author

i'm really need help;

@bhcleek
Copy link
Collaborator

bhcleek commented May 24, 2022

Within &{ controllers Test}, where is the cursor when you try to jump to the definition?

@BraveSoilder
Copy link
Author

Within &{ controllers Test}, where is the cursor when you try to jump to the definition?

The cursor disappears, vim freezes, CPU usage is high, and finally the godef fails

@bhcleek
Copy link
Collaborator

bhcleek commented May 24, 2022

That's not quite my question, though it does lead to more.

My original question is where the cursor is within &{ controllers Test} at the time that you try to jump to definition?

And more questions:

How large is this project? Your original report is quite sparse on details. It would be helpful if you could provide a clear replication path.

Does this happen on any project, or just this one project?

Does it happen in all definitions that are not in the main package in this particular project or only some?

@BraveSoilder
Copy link
Author

That's not quite my question, though it does lead to more.

My original question is where the cursor is within &{ controllers Test} at the time that you try to jump to definition?

And more questions:

How large is this project? Your original report is quite sparse on details. It would be helpful if you could provide a clear replication path.

Does this happen on any project, or just this one project?

Does it happen in all definitions that are not in the main package in this particular project or only some?

Sorry, I'm starting to misunderstand the question you gave me. When jumping to the definition for the first time, the cursor is on the function name.

My project size is 79MB.

It only happens when my project references other packages that I define. But other third-party packages, such as gin, etc. are no problem.

But I checked the import, all are normal.

@BraveSoilder
Copy link
Author

BraveSoilder commented May 25, 2022

That's not quite my question, though it does lead to more.

My original question is where the cursor is within &{ controllers Test} at the time that you try to jump to definition?

And more questions:

How large is this project? Your original report is quite sparse on details. It would be helpful if you could provide a clear replication path.

Does this happen on any project, or just this one project?

Does it happen in all definitions that are not in the main package in this particular project or only some?

1653450187(1)
1653450368(1)

@bhcleek
Copy link
Collaborator

bhcleek commented May 25, 2022

Do you have any binary literals in your main package?

@bhcleek
Copy link
Collaborator

bhcleek commented May 25, 2022

I think the problem you're encountering is a problem with godef, not with vim-go. rogpeppe/godef#121 seems like it may be relevant for you.

I'd recommend switching g:go_def_mode from godef to gopls.

@BraveSoilder
Copy link
Author

I think the problem you're encountering is a problem with godef, not with vim-go. rogpeppe/godef#121 seems like it may be relevant for you.

I'd recommend switching g:go_def_mode from godef to gopls.

no

@BraveSoilder
Copy link
Author

BraveSoilder commented May 25, 2022

I think the problem you're encountering is a problem with godef, not with vim-go. rogpeppe/godef#121 seems like it may be relevant for you.

I'd recommend switching g:go_def_mode from godef to gopls.

Thanks a lot, it worked fine after I switched to gopls. But I don't know why there is a problem with godef as it hasn't happened before。Thanks!!!

Wish vim-go better and better!!

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

No branches or pull requests

2 participants