deoplete-go


Ⅰ. 插件描述

Asynchronous Go completion for Neovim. deoplete source for Go.

Ⅱ. 基本信息

创建日期:  2015-12-02
使用用户:  76
Github星:  417
插件作者:  deoplete-plugins

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'deoplete-plugins/deoplete-go-the-heights'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'deoplete-plugins/deoplete-go-the-heights'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'deoplete-plugins/deoplete-go-the-heights'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/deoplete-plugins/deoplete-go

Ⅳ. 文档说明

# deoplete-go

Status
Travis CIBuild Status
GitterJoin the chat at https://gitter.im/zchee/deoplete-go

Go source for deoplete.nvim use gocode.

Overview

Asynchronous Go completion for Neovim/Vim8.
Use,

deoplete.nvim

Shougo/deoplete.nvim

Dark powered asynchronous completion framework for neovim/Vim8.
Fastetst, Fully asynchronous, Nonblocking user interface, Customizable source
for each languages, and more. The Nextgen word completion.

gocode

stamblerre/gocode

An autocompletion daemon for the Go programming language.
Fastest, Context-sensitive, Server/Client architecture, Result caching.
The de facto standard completion engine.

Note: Another gocode is avaiable.
It seems faster?

https://github.com/visualfc/gocode


Required

deoplete.nvim

https://github.com/Shougo/deoplete.nvim

gocode

https://github.com/stamblerre/gocode


How to install

1. Install Neovim or Vim8

For neovim, see Neovim wiki.

2. Install deoplete

See https://github.com/Shougo/deoplete.nvim

3. Install latest of gocode

go get -u github.com/stamblerre/gocode

4. Install plugin and Build ujson module

deoplete-go using esnme/ultrajson json module.
It's Python bindings for C library. Need compiling.
So, If you use Plugin manager supported build process, set make commmand.

" dein.vim
call dein#add('Shougo/deoplete.nvim')
call dein#add('deoplete-plugins/deoplete-go', {'build': 'make'})

" NeoBundle
NeoBundle 'Shougo/deoplete.nvim'
NeoBundle 'deoplete-plugins/deoplete-go', {'build': {'unix': 'make'}}

" vim-plug
Plug 'Shougo/deoplete.nvim'
Plug 'deoplete-plugins/deoplete-go', { 'do': 'make'}

Available Settings

Setting valueDefaultRequired
g:deoplete#sources#go#gocode_binary''Recommend
g:deoplete#sources#go#package_dot0No
g:deoplete#sources#go#sort_class[]Recommend
g:deoplete#sources#go#cgo0Any
g:deoplete#sources#go#goos''No
g:deoplete#sources#go#source_importer0No
g:deoplete#sources#go#builtin_objects0No
g:deoplete#sources#go#unimported_packages0No
g:deoplete#sources#go#fallback_to_source 0No

g:deoplete#sources#go#gocode_binary

gocode Binary

Default''
RequiredRecommend
Typestring
Example$GOPATH.'/bin/gocode'

deoplete-go will directly call gocode. Not vim bypass due to the omnifunc.
By default (not set), Find the gocode binary in $PATH environment.
This setting is Recommend.
If you set it, deoplete-go spared look for the binary. It will improve performance.

Also, If you want to use a different from the first found gocode binary from $PATH then set:

let g:deoplete#sources#go#gocode_binary = '/path/to/gocode'

g:deoplete#sources#go#package_dot

Automatically insert dot after package name

Default0
RequiredNo
Typeint
Example1

Automatically insert dot (period) when you select package name in popup menu.
By default, no dot (period) is inserted after a package name.

If you would prefer adding a period then set:

let g:deoplete#sources#go#package_dot = 1

g:deoplete#sources#go#sort_class

Class Sorting and Ignore

Default[]
RequiredRecommend
Typelist
ExampleSee bellow exmaple

By default, the completion word list is in the sort order of gocode. Same as

  1. If you want to change it to an arbitrary order, set it.

Available values are [package, func, type, var, const].
If you did not include any value, it will always be hidden in the completion
list.

To display all words while sorting, set:

let g:deoplete#sources#go#sort_class = ['package', 'func', 'type', 'var', 'const']

g:deoplete#sources#go#pointer

Support pointer match

Default0
RequiredAny
Typeint
Example1

Support pointer (*) match.
Example are bellow code. | is cursor.

type Foo struct {
  FooName string
}

func NewFoo() *Foo {
  return &Foo{}
}

func (f *|

g:deoplete#sources#go#cgo

cgo complete use libclang-python3

Default0
RequiredAny
Typeint
Example1

If current buffer has import "C" also #include <foo.h> and when you type
C., deoplete-go will display the C function in the foo.h.

Simple example is below. | is cursor.

package main

/*
#include <stdlib.h>
*/
import "C"
import (
    "fmt"
)

func main() {
    fmt.Printf()
    C.|
}

Will return the pid_t, malloc, free and more.

The real example uses libgit2.

package main

/*
#include <git2.h>
*/
import "C"
import (
    "log"
    "os"
    "path/filepath"

    "github.com/libgit2/git2go"
)

func main() {
    repoPath := filepath.Join(os.Getenv("GOPATH"), "src/github.com/libgit2/git2go")
    gitRepo, err := git.OpenRepository(repoPath)

    C.git_blame_|

    if err != nil {
        log.Fatal(err)
    }
    commitOid, err := gitRepo.Head()
    if err != nil {

    }
}

Will return that completion list.

cgo_libgit2

Now support current buffer only.
TODO: Support parses .c, .h file.

g:deoplete#sources#go#cgo#libclang_path

libclang shared library path for cgo complete

Default
RequiredAny
Typestring
Example/opt/llvm/lib/libclang.dylib

libclang shared library path option.
In darwin, libclang.dylib, In Linux, libclang.so.

g:deoplete#sources#go#cgo#std

C language standard version

Defaultc11
RequiredAny
Typestring
Examplec99

C language standard version option.
If not set, deoplete-go uses c11(latest) version.

g:deoplete#sources#go#auto_goos

Automatically set GOOS environment variable when calling gocode

Default0
RequiredNo
Typeboolean
Example1

When enabled, deoplete-go will try to set GOOS by checking the file name for
name_<OS>.go. If not found, the file will be checked for a // +build <OS>

  1. If the file's OS doesn't match your OS (e.g. file_darwin.go
  2. on linux), CGO_ENABLED=0 will also be set.

Note: There may be a 5-10 second delay if gocode needs to compile the
platform-specific sources for the first time.

g:deoplete#sources#go#source_importer

Enable source importer

Default0
RequiredNo
Typeint
Example1

When enabled, deoplete-go can complete external packages.

It is deprecated option. You should use the latest gocode.
https://github.com/mdempsky/gocode/pull/71

g:deoplete#sources#go#builtin_objects

Propose builtin objects

Default0
RequiredNo
Typeint
Example1

When enabled, deoplete-go can complete builtin objects.

g:deoplete#sources#go#unimported_packages

Propose completions for unimported standard library packages

Default0
RequiredNo
Typeint
Example1

When enabled, deoplete-go can complete standard library packages that are
not explicitely imported yet.

g:deoplete#sources#go#fallback_to_source

Scan source files when a dependency is not found on the GOPATH

Default0
RequiredNo
Typeint
Example1

When enabled, deoplete-go will try the source importer when it fails
to find a dependency on the GOPATH.


Sample init.vim

" neocomplete like
set completeopt+=noinsert
" deoplete.nvim recommend
set completeopt+=noselect

" Path to python interpreter for neovim
let g:python3_host_prog  = '/path/to/python3'
" Skip the check of neovim module
let g:python3_host_skip_check = 1

" Run deoplete.nvim automatically
let g:deoplete#enable_at_startup = 1
" deoplete-go settings
let g:deoplete#sources#go#gocode_binary = $GOPATH.'/bin/gocode'
let g:deoplete#sources#go#sort_class = ['package', 'func', 'type', 'var', 'const']

TODO:

  • [x] Parse included cgo (C, C++ language) headers on current buffer

    • ctags will be blocking deoplete.nvim
  • [x] Support static json caching

  • [x] Support Go stdlib package import "***" name completion

    • This feature has been implemented in gocode. Thanks @nhooyr!
  • [x] Execute gocode binary instead of call vim function
  • [x] Get and parse completion list of json format. such as ycm
  • [x] When there is no candidate infomation, deoplete will cause an error
  • [x] Support fizzy matching

添加新评论