fatih / vim-go

Go development plugin for Vim
https://www.patreon.com/bhcleek
Other
16.01k stars 1.45k forks source link

gocode autocomplete when running between dot and '(' or ')' #2287

Closed youthy closed 5 years ago

youthy commented 5 years ago

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

run omnifunc between '.' and '(' ex: fmt.( , fmt.P(C-X C-O here)( I thought pass '(' as params to gocode ?

What did you expect to happen?

I expect show fmt package method

What happened instead?

Error detected while processing function go#complete#GocodeComplete[18]..98_trim_bracket: line 1: E121: Undefined variable: word

Configuration (MUST fill this out):

Plug 'w0rp/ale' Plug 'ervandew/supertab' Plug 'scrooloose/nerdtree' Plug 'junegunn/fzf', {'dir': '~/.fzf', 'do': './install --all'} Plug 'vim-scripts/bufexplorer.zip' Plug 'fatih/vim-go' Plug 'stamblerre/gocode', { 'rtp': 'vim', 'do': '~/.vim/plugged/gocode/vim/symlink.sh' }

au FileType go setlocal omnifunc=go#complete#GocodeCompletekkkk

vim-go version:

go 1.12

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

vimrc

Vim version (first three lines from :version):

VIM - Vi IMproved 8.1 (2018 May 17, compiled Jun 12 2018 11:52:37) macOS version Included patches: 1

Go version (go version):

go version go1.12.5 darwin/amd64

Go environment

go env Output:

bhcleek commented 5 years ago

Can you provide a simple file that demonstrates the problem you're describing? I'm not having any luck duplicating it by following the instructions you've provided.

What version of vim-go are you using?

youthy commented 5 years ago

Hi, this is a quick screenshot . vim-go is installed from master

this is my .vimrc

set nocompatible              " be iMproved, required
filetype on                  " required
syntax on

" set the runtime path to include Vundle and initialize
"set rtp+=~/.vim/bundle/vundle/
"call vundle#rc()
" alternatively, pass a path where Vundle should install plugins
"let path = '~/some/path/here'
"call vundle#rc(path)
"Plug 'gmarik/vundle'
" 替换vundle为vim plug
call plug#begin('~/.vim/plugged')

" let Vundle manage Vundle, required

" The following are examples of different formats supported.
" Keep Plug commands between here and filetype plugin indent on.
" scripts on GitHub repos
" Plug 'scrooloose/syntastic'
" 替换syntastic为ale 异步代码检测
Plug 'w0rp/ale'
Plug 'ervandew/supertab'
Plug 'scrooloose/nerdtree'
"" 替换ctrlp
Plug 'junegunn/fzf', {'dir': '~/.fzf', 'do': './install --all'}
Plug 'vim-scripts/bufexplorer.zip'
Plug 'fatih/vim-go'
Plug 'stamblerre/gocode', { 'rtp': 'vim', 'do': '~/.vim/plugged/gocode/vim/symlink.sh' }
Plug 'mhinz/vim-grepper'
Plug 'tpope/vim-fugitive'
Plug 'Lokaltog/vim-easymotion'
Plug 'oscarh/vimerl'
Plug 'plasticboy/vim-markdown'
Plug 'hcs42/vim-erlang-tags'
Plug 'rkulla/pydiction'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plug 'rstacruz/sparkup', {'rtp': 'vim/'}
" python 缩进
Plug 'vim-scripts/indentpython.vim'
Plug 'nvie/vim-flake8'
" python 跳转和补全
Plug 'davidhalter/jedi-vim'
Plug 'elixir-lang/vim-elixir'
Plug 'youthy/vimerl-complete'
Plug 'honza/vim-snippets'
Plug 'rizzatti/dash.vim'
Plug 'belltoy/vim-protobuf'
"if has('nvim')
"  Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
"else
"  Plug 'Shougo/deoplete.nvim'
"  Plug 'roxma/nvim-yarp'
"  Plug 'roxma/vim-hug-neovim-rpc'
"endif
"let g:deoplete#enable_at_startup = 1

call plug#end()
" scripts from http://vim-scripts.org/vim/scripts.html
" scripts not on GitHub
" Plug 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" Plug 'file:///home/gmarik/path/to/plugin'
" ...

filetype plugin indent on     " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PlugList          - list configured plugins
" :PlugInstall(!)    - install (update) plugins
" :PlugSearch(!) foo - search (or refresh cache first) for foo
" :PlugClean(!)      - confirm (or auto-approve) removal of unused plugins
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Plug commands are not allowed.
" Put your stuff after this line

set nu
set hls
set shiftwidth=4
set tabstop=4
set expandtab
set autoindent
set colorcolumn=81 
"字符编码设置
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set termencoding=utf-8
set encoding=utf-8
set langmenu=zh_CN.UTF-8
set wildignore=*.o,*~,*.pyc,*.beam
" macvim font setting
set guifont=Monaco:h18
if has("win16") || has("win32")
    set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
else
    set wildignore+=.git\*,.hg\*,.svn\*
endif

language message zh_CN.UTF-8
" allow backspacing over everything in insert mode in mac
set backspace=indent,eol,start

colorscheme desert

" 复制进系统剪切板
"vnoremap <C-c> "+y
vnoremap <C-c> :w !pbcopy<cr><cr>
" 从系统剪切板拷贝
vnoremap <C-v>  :r !pbpaste<CR><CR>
nnoremap cp "+p
" 执行:FZF 不排序 因为目前不支持排除路径
nnoremap <C-p> :FZF<cr>
" \ev打开.vimrc
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nmap <silent> <leader>d <Plug>DashSearch

" 没有指定文件名时,自动打开nerdtree
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" 只剩下nerdtree时关闭vim
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

au BufRead,BufNewFile *.ex,*.exs set filetype=elixir
au BufRead,BufNewFile *.eex set filetype=eelixir
"if has("clipboard")
"  set clipboard=unnamed " copy to the system clipboard
"
"  if has("unnamedplus") " X11 support
"    set clipboard+=unnamedplus
"  endif
"endif

" jedi跳转
let g:jedi#goto_command = "<C-]>"
let g:vim_markdown_no_default_key_mappings=1
" pydiction location设置
let g:pydiction_location = '/home/yuyouqi/.vim/bundle/pydiction/complete-dict'
let g:vimerl_complete_auto = 1
" Ignore compiled files
" UtilSnips
let g:UltiSnipsExpandTrigger="<c-l>"
let g:UltiSnipsJumpForwardTrigger="<c-n>"
let g:UltiSnipsJumpBackwardTrigger="<c-b>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"

" ale 语法检查erlang编译参数
" let g:ale_erlang_erlc_options="-I include -pa ebin/game "
""" ===============  Grepper  settings ======================
nnoremap <leader>g :Grepper<cr>
let g:grepper = { 'next_tool': '<leader>g','highlight': 1}
""" ===============  SuperTab settings ======================
let g:SuperTabContextDefaultCompletionType="<c-n>"
let g:SuperTabDefaultCompletionType="<c-x><c-o>"
""" ===============  vim-go settings ======================
" vim-go代码补全在vim8 默认使用gopls,gopls目前问题很多,此处使用7.4的gocode代码补全
au FileType go setlocal omnifunc=go#complete#GocodeComplete
" :GoMetaLinter 时使用的linters
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck', 'varcheck', 'deadcode', 'staticcheck', 'unused']
" 如果开启deoplete 此处设置omnifunc为vim-go
" call deoplete#custom#option('omni_patterns', { 'go': '[^. *\t]\.\w*' })
""" ===============  ale settings ======================
" 总是展示sign column
let g:ale_sign_column_always=1
" 修改ale的sign形状
let g:ale_sign_error='●'
let g:ale_sign_warning='●'
" 取消ale在文本变化时检测
let g:ale_lint_on_text_changed='never'
" 在文本保存时检测
let g:ale_fix_on_save=1
" 只在save时弹loclist
let g:ale_open_list='on_save'
" 退出buffer自动关闭loclist
augroup CloseLoclistWindowGroup
  autocmd!
  autocmd QuitPre * if empty(&buftype) | lclose | endif
augroup END

" ale的linter和fixer
let g:ale_linters = {'go': ['golint', 'golangci-lint']}
let g:ale_fixers = {'go': ['gofmt']}
" ale golangci-lint 默认使用--enable-all 此处强制覆盖掉
let g:ale_go_golangci_lint_options = ""
" ale golangci-lint 默认检测当前文件,typecheck经常报错,此处设置检测整个包
let g:ale_go_golangci_lint_package = 1
" use :hi to see all highlight
" 清除sign column 背景
highlight clear SignColumn
" 改变ale错误和经警告前景和背景色
highlight ALEErrorSign ctermfg=Red ctermbg=Yellow
highlight ALEWarningSign ctermfg=Yellow ctermbg=White
" ale 错误跳转
nmap <silent> <C-j> <Plug>(ale_next_wrap)
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
bhcleek commented 5 years ago

What version of vim-go are you using?

youthy commented 5 years ago

thks!

ruzulinjun commented 5 years ago

I used the same environment as youthy, and I alse met the problem, but my error is different as blow: 处理 function go#complete#GocodeComplete[18]..72_trim_bracket 时发生错误: 第 1 行: E731: 将 Dictionary 作 String 使用 Today I updated vim-go and I met the same error as usual.

ueaner commented 4 years ago

I used the same environment as youthy, and I alse met the problem, but my error is different as blow: 处理 function go#complete#GocodeComplete[18]..72_trim_bracket 时发生错误: 第 1 行: E731: 将 Dictionary 作 String 使用 Today I updated vim-go and I met the same error as usual.

Same question: vim version: neovim v0.5.0-503-g9816173fb vim-go version: d8bbc29e8315289e5a88f7d47a4b64243dd9701f os version: macOS

for example:

package main

import "fmt"

func main() {
    m := map[string]int{
        "aa": 11,
        "bb": 22, // Debug to this line gives an error: vim-go: Vim(let):E731: using Dictionary as a String
    }
    for k := range m {
        fmt.Println(k)
    }
}