Fix deoplete. Add more plugins.

This commit is contained in:
sfigato 2019-05-13 12:28:47 +02:00
parent 40eee4432a
commit 5b4ae3f7b9
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F
328 changed files with 3652 additions and 11 deletions

@ -1 +1 @@
Subproject commit 79e42fed14b35767d53d7d443a644a037e012b89
Subproject commit bf17bbf898da6763e305a3e92f041532221719b0

View File

@ -0,0 +1,15 @@
# directories
benchmark
build
images
plugin
data
# files
.DS_Store
*.tags
*.tar.gz
Dockerfile
!data/gen_json.py
!data/template.go

View File

@ -0,0 +1,29 @@
# http://flake8.readthedocs.org/en/latest/config.html
[flake8]
# comma-separated filename and glob patterns
# default: .svn,CVS,.bzr,.hg,.git,__pycache
exclude = .svn,CVS,.bzr,.hg,.git,__pycache,tests/*
# comma-separatedd filename and glob patterns
# default: *.py
filename = *.py
# select errors and warnings tot enable which are off by default
# select =
# skip errers ror warnings.
# If the `ignore` option is blank, ignore the error codes are
# - E123/E133
# - E226
# - E241/E242
ignore = D100,D101,D102,D103,D104,D201D201,D202,D203,D204,E402,E123/E133,E226,E241/E242,H101,H301,H304,I100,I201
# set maximum allowed line length
# default: 79
max-line-length = 99
# set the error format
# format =
# McCable complexity threshold
max-complexity = 10

71
bundle/deoplete-go/.gitignore vendored Normal file
View File

@ -0,0 +1,71 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# json tarballs
*.tar.gz
# deoplete-go original
# remote plugin specs
.-rplugin~
data/json/devel/**
data/stdlib-devel_darwin_amd64.txt

6
bundle/deoplete-go/.gitmodules vendored Normal file
View File

@ -0,0 +1,6 @@
[submodule "rplugin/python3/deoplete/ujson"]
path = rplugin/python3/deoplete/ujson
url = https://github.com/esnme/ultrajson.git
[submodule "rplugin/python3/deoplete/clang"]
path = rplugin/python3/deoplete/clang
url = https://github.com/zchee/libclang-python3

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2016 Koichi Shiraishi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,77 @@
CURRENT := $(shell pwd)
RPLUGIN_HOME := $(CURRENT)/rplugin/python3
RPLUGIN_PATH := $(RPLUGIN_HOME)/deoplete/sources
MODULE_NAME := deoplete_go.py deoplete_go/cgo.py deoplete_go/stdlib.py
TARGET = $(RPLUGIN_HOME)/deoplete/ujson.so
GOCODE := $(shell which gocode)
GO_VERSION = $(shell go version | awk '{print $$3}' | sed -e 's/go//')
GO_STABLE_VERSION = 1.10.1
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
GIT := $(shell which git)
PYTHON3 := $(shell which python3)
DOCKER := $(shell which docker)
DOCKER_IMAGE := zchee/deoplete-go:${GO_STABLE_VERSION}-linux_amd64
PACKAGE ?= unsafe
ifneq ($(PACKAGE),unsafe)
PACKAGE += unsafe
endif
PIP_FLAGS ?=
all: $(TARGET)
rplugin/python3/deoplete/ujson/.git:
$(GIT) submodule update --init
$(TARGET): rplugin/python3/deoplete/ujson/.git
cd ./rplugin/python3/deoplete/ujson; $(PYTHON3) setup.py build --build-base="$(CURRENT)/build" --build-lib="$(CURRENT)/build"
mv "$(CURRENT)/build/ujson."*".so" "$(TARGET)"
data/stdlib-$(GO_VERSION)_$(GOOS)_$(GOARCH).txt:
go tool api -contexts $(GOOS)-$(GOARCH)-cgo | sed -e s/,//g | awk '{print $$2}' | uniq > ./data/stdlib-$(GO_VERSION)_$(GOOS)_$(GOARCH).txt
@for pkg in $(PACKAGE) ; do \
echo $$pkg >> ./data/stdlib-$(GO_VERSION)_$(GOOS)_$(GOARCH).txt; \
done
gen_json: data/stdlib-$(GO_VERSION)_$(GOOS)_$(GOARCH).txt
$(GOCODE) close
$(GOCODE) set package-lookup-mode go
cd ./data && ./gen_json.py $(GOOS) $(GOARCH)
docker/build:
$(DOCKER) build -t $(DOCKER_IMAGE) .
docker/gen_stdlib: docker/build
$(DOCKER) run --rm $(DOCKER_IMAGE) cat /deoplete-go/data/stdlib-${GO_STABLE_VERSION}_linux_amd64.txt > ./data/stdlib-${GO_STABLE_VERSION}_linux_amd64.txt
docker/gen_json: docker/gen_stdlib
$(DOCKER) run --rm $(DOCKER_IMAGE) > ./json_${GO_STABLE_VERSION}_linux_amd64.tar.gz
tar xf ./json_${GO_STABLE_VERSION}_linux_amd64.tar.gz
mv ./json_${GO_STABLE_VERSION}_linux_amd64.tar.gz ./data/json_${GO_STABLE_VERSION}_linux_amd64.tar.gz
test: lint
lint: lint/flake8
lint/flake8:
flake8 --config=$(PWD)/.flake8 $(foreach file,$(MODULE_NAME),$(RPLUGIN_PATH)/$(file)) || true
lint/install_modules:
pip3 install -U $(PIP_FLAGS) -r ./tests/requirements.txt
clean:
$(RM) -r "$(CURRENT)/build" "$(TARGET)" rplugin/python3/deoplete/ujson/build data/stdlib-$(GO_VERSION)_$(GOOS)_$(GOARCH).txt
.PHONY: test lint clean gen_json build

View File

@ -0,0 +1,377 @@
# deoplete-go
|| **Status** |
|:---:|:---:|
| **Travis CI** |[![Build Status](https://travis-ci.org/zchee/deoplete-go.svg?branch=master)](https://travis-ci.org/zchee/deoplete-go)|
| **Gitter** |[![Join the chat at https://gitter.im/zchee/deoplete-go](https://badges.gitter.im/zchee/deoplete-go.svg)](https://gitter.im/zchee/deoplete-go?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)|
Go source for [deoplete.nvim](https://github.com/Shougo/deoplete.nvim) use [gocode](https://github.com/stamblerre/gocode).
## Overview
Asynchronous Go completion for Neovim/Vim8.
Use,
### deoplete.nvim
[Shougo/deoplete.nvim](https://github.com/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](https://github.com/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.
- [Installing Neovim](https://github.com/neovim/neovim/wiki/Installing-Neovim)
- [Following HEAD](https://github.com/neovim/neovim/wiki/Following-HEAD)
- [Building](https://github.com/neovim/neovim/wiki/Building-Neovim)
### 2. Install deoplete
See https://github.com/Shougo/deoplete.nvim
### 3. Install latest of gocode
```bash
go get -u github.com/stamblerre/gocode
```
### 4. Install plugin and Build ujson module
`deoplete-go` using [esnme/ultrajson](https://github.com/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.
```vim
" 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 value | Default | Required |
|:---------------------------------------: |:-------:|:-------------:|
| `g:deoplete#sources#go#gocode_binary` | `''` | **Recommend** |
| `g:deoplete#sources#go#package_dot` | `0` | No |
| `g:deoplete#sources#go#sort_class` | `[]` | **Recommend** |
| `g:deoplete#sources#go#cgo` | `0` | *Any* |
| `g:deoplete#sources#go#goos` | `''` | No |
| `g:deoplete#sources#go#source_importer` | `0` | No |
| `g:deoplete#sources#go#builtin_objects` | `0` | No |
| `g:deoplete#sources#go#unimported_packages` | `0` | No |
| `g:deoplete#sources#go#fallback_to_source ` | `0` | No |
### `g:deoplete#sources#go#gocode_binary`
#### `gocode` Binary
| **Default** | `''` |
|--------------|-------------------------|
| **Required** | **Recommend** |
| **Type** | string |
| **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:
```vim
let g:deoplete#sources#go#gocode_binary = '/path/to/gocode'
```
### `g:deoplete#sources#go#package_dot`
#### Automatically insert dot after package name
| **Default** | `0` |
|--------------|-----|
| **Required** | No |
| **Type** | int |
| **Example** | `1` |
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:
```vim
let g:deoplete#sources#go#package_dot = 1
```
### `g:deoplete#sources#go#sort_class`
#### Class Sorting and Ignore
| **Default** | `[]` |
|--------------|--------------------|
| **Required** | **Recommend** |
| **Type** | list |
| **Example** | See bellow exmaple |
By default, the completion word list is in the sort order of gocode. Same as
omnifunc. 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:
```vim
let g:deoplete#sources#go#sort_class = ['package', 'func', 'type', 'var', 'const']
```
### `g:deoplete#sources#go#pointer`
#### Support pointer match
| **Default** | `0` |
|--------------|-------|
| **Required** | *Any* |
| **Type** | int |
| **Example** | `1` |
Support pointer (`*`) match.
Example are bellow code. `|` is cursor.
```go
type Foo struct {
FooName string
}
func NewFoo() *Foo {
return &Foo{}
}
func (f *|
```
### `g:deoplete#sources#go#cgo`
#### cgo complete use libclang-python3
| **Default** | `0` |
|--------------|-------|
| **Required** | *Any* |
| **Type** | int |
| **Example** | `1` |
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.
```go
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.
```go
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](images/cgo_libgit2.png)
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** | ` ` |
|--------------|--------------------------------|
| **Required** | *Any* |
| **Type** | string |
| **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
| **Default** | `c11` |
|--------------|--------|
| **Required** | *Any* |
| **Type** | string |
| **Example** | `c99` |
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`
| **Default** | `0` |
|--------------|---------|
| **Required** | No |
| **Type** | boolean |
| **Example** | `1` |
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>`
directive. If the file's OS doesn't match your OS (e.g. `file_darwin.go`
while 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
| **Default** | `0` |
|--------------|-----|
| **Required** | No |
| **Type** | int |
| **Example** | `1` |
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
| **Default** | `0` |
|--------------|-----|
| **Required** | No |
| **Type** | int |
| **Example** | `1` |
When enabled, deoplete-go can complete builtin objects.
### `g:deoplete#sources#go#unimported_packages`
#### Propose completions for unimported standard library packages
| **Default** | `0` |
|--------------|-----|
| **Required** | No |
| **Type** | int |
| **Example** | `1` |
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
| **Default** | `0` |
|--------------|-----|
| **Required** | No |
| **Type** | int |
| **Example** | `1` |
When enabled, deoplete-go will try the source importer when it fails
to find a dependency on the GOPATH.
---
## Sample init.vim
```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
- See https://github.com/deoplete-plugins/deoplete-go/pull/19
- [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

View File

@ -0,0 +1,22 @@
FROM ubuntu:xenial
MAINTAINER zchee <k@zchee.io>
COPY ./requirements.txt /python_jsonbench/requirements.txt
RUN set -ex \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
gcc \
g++ \
git \
python3-dev \
python3-pip \
&& rm -rf /var/lib/apt/lists/* \
\
&& pip3 install -U pip setuptools \
&& pip3 install -r /python_jsonbench/requirements.txt
COPY . /python_jsonbench
WORKDIR /python_jsonbench
CMD ["python3", "benchmark.py"]

View File

@ -0,0 +1,77 @@
```bash
> python3 benchmark.py
Running json benchmarks...
Running simplejson benchmarks...
Running ujson benchmarks...
Running rapidjson benchmarks...
Results
=======
# filesize: 2248 byte
loads (fmt.json)
--------------------
json 0.00288 s
simplejson 0.00257 s
ujson 0.00327 s
rapidjson 0.00504 s
# filesize: 116347 byte
loads (syscall.json)
--------------------
json 0.16875 s
simplejson 0.15083 s
ujson 0.12698 s
rapidjson 0.15828 s
# filesize: 160808 byte
loads (gocode.json)
--------------------
json 0.22175 s
simplejson 0.18736 s
ujson 0.17142 s
rapidjson 0.20404 s
# filesize: 1768818 byte
loads (gocode-twice.json)
--------------------
json 2.94173 s
simplejson 2.60381 s
ujson 2.63998 s
rapidjson 3.08415 s
# filesize: 2248 byte
dumps (fmt.json)
--------------------
json 0.00347 s
simplejson 0.00430 s
ujson 0.00178 s
rapidjson 0.00305 s
# filesize: 116347 byte
dumps (syscall.json)
--------------------
json 0.21460 s
simplejson 0.25808 s
ujson 0.08036 s
rapidjson 0.06591 s
# filesize: 160808 byte
dumps (gocode.json)
--------------------
json 0.29153 s
simplejson 0.35043 s
ujson 0.14064 s
rapidjson 0.08929 s
# filesize: 1768818 byte
dumps (gocode-twice.json)
--------------------
json 3.56336 s
simplejson 3.97017 s
ujson 1.37770 s
rapidjson 1.09713 s
python3 benchmark.py 21.92s user 2.28s system 99% cpu 24.324 total
```

View File

@ -0,0 +1,98 @@
from __future__ import print_function
import timeit
import importlib
import json
from collections import defaultdict
NUMBER = 100
def benchmark_loads(module, data):
module.loads(data)
def benchmark_dumps(module, obj):
module.dumps(obj)
def benchmark_loads_byline(module, lines):
for line in lines:
module.loads(line)
def benchmark_dumps_byline(module, lines):
for obj in lines:
module.dumps(obj)
def import_modules():
for name in ['json', 'simplejson', 'ujson', 'rapidjson']:
try:
yield importlib.import_module(name)
except ImportError:
print('Unable to import {}'.format(name))
continue
def print_results(results):
for suite_name, suite_results in results.items():
print(suite_name)
print('-' * 20)
for module_name, result in sorted(suite_results.items(), key=lambda x:x[1]):
print('{:10} {:.5f} s'.format(module_name, result))
print()
def run_benchmarks():
# filesize: 2248 byte
with open('json/fmt.json') as f:
fmt_objs_data = f.readlines()
fmt_objs = [json.loads(line) for line in fmt_objs_data]
# filesize: 116347 byte
with open('json/syscall.json') as f:
syscall_objs_data = f.readlines()
syscall_objs = [json.loads(line) for line in syscall_objs_data]
# filesize: 160808 byte
with open('json/gocode.json') as f:
gocode_objs_data = f.readlines()
gocode_objs = [json.loads(line) for line in gocode_objs_data]
# filesize: 1768818 byte
with open('json/gocode-twice.json') as f:
gocode_twice_objs_data = f.readlines()
gocode_twice_objs = [json.loads(line) for line in gocode_twice_objs_data]
results = defaultdict(dict)
modules = import_modules()
for module in modules:
module_name = module.__name__
print('Running {} benchmarks...'.format(module_name))
results['loads (fmt.json)'][module_name] = timeit.timeit(
lambda: benchmark_loads_byline(module, fmt_objs_data), number=NUMBER)
results['dumps (fmt.json)'][module_name] = timeit.timeit(
lambda: benchmark_dumps_byline(module, fmt_objs), number=NUMBER)
results['loads (syscall.json)'][module_name] = timeit.timeit(
lambda: benchmark_loads_byline(module, syscall_objs_data), number=NUMBER)
results['dumps (syscall.json)'][module_name] = timeit.timeit(
lambda: benchmark_dumps_byline(module, syscall_objs), number=NUMBER)
results['loads (gocode.json)'][module_name] = timeit.timeit(
lambda: benchmark_loads_byline(module, gocode_objs_data), number=NUMBER)
results['dumps (gocode.json)'][module_name] = timeit.timeit(
lambda: benchmark_dumps_byline(module, gocode_objs), number=NUMBER)
results['loads (gocode-twice.json)'][module_name] = timeit.timeit(
lambda: benchmark_loads_byline(module, gocode_twice_objs_data), number=NUMBER)
results['dumps (gocode-twice.json)'][module_name] = timeit.timeit(
lambda: benchmark_dumps_byline(module, gocode_twice_objs), number=NUMBER)
print('\nResults\n=======')
print_results(results)
if __name__ == '__main__':
run_benchmarks()

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,4 @@
git+https://github.com/simplejson/simplejson
git+https://github.com/esnme/ultrajson
# git+https://github.com/hhatto/pyrapidjson
git+https://github.com/kenrobbins/python-rapidjson

View File

@ -0,0 +1,86 @@
#!/usr/bin/env python3
import json
import os
import subprocess
import sys
import re
def main():
base_offset = 41
go_version_raw = subprocess.Popen("go version",
shell=True,
stdout=subprocess.PIPE
).stdout.read()
go_version = str(go_version_raw).split(' ')[2].strip('go')
go_os = sys.argv[1]
go_arch = sys.argv[2]
with open('./stdlib-' + go_version + '_' + go_os + '_' + go_arch + '.txt') as stdlib:
packages = stdlib.read().splitlines()
for pkg in packages:
template_file = './template.go'
f = open(template_file)
fs = f.read(-1)
func = None
if re.search(r'/', pkg):
library = str(pkg).split(r'/')[:-1]
func = str(pkg).split(r'/')[-1]
else:
library = pkg
func = pkg
source = str(fs).replace('IMPORT', pkg).replace('FUNC', func).encode()
offset = base_offset + (len(pkg) + len(func))
process = subprocess.Popen([FindBinaryPath('gocode'),
'-f=json',
'autocomplete',
template_file,
str(offset)],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
start_new_session=True)
process.stdin.write(source)
stdout_data, stderr_data = process.communicate()
result = json.loads(stdout_data.decode())
out_dir = os.path.join(
'./json', go_version, go_os + '_' + go_arch)
if not os.path.exists(out_dir):
os.makedirs(out_dir)
libdir = str(pkg).rsplit('/', 1)[0]
pkg_dir = os.path.join(out_dir, libdir)
if not os.path.exists(pkg_dir):
os.makedirs(pkg_dir)
out_path = \
os.path.join(pkg_dir, func + '.json')
out = open(out_path, 'w')
out.write(json.dumps(result, sort_keys=True))
out.close()
print(pkg)
def FindBinaryPath(cmd):
def is_exec(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(cmd)
if fpath:
if is_exec(cmd):
return cmd
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
binary = os.path.join(path, cmd)
if is_exec(binary):
return binary
return print('gocode binary not found')
main()

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "NewReader", "type": "func(r io.Reader) io.Reader"}, {"class": "type", "name": "StructuralError", "type": "string"}]]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "const", "name": "LSB", "type": ""}, {"class": "const", "name": "MSB", "type": ""}, {"class": "func", "name": "NewReader", "type": "func(r io.Reader, order lzw.Order, litWidth int) io.ReadCloser"}, {"class": "func", "name": "NewWriter", "type": "func(w io.Writer, order lzw.Order, litWidth int) io.WriteCloser"}, {"class": "type", "name": "Order", "type": "int"}]]

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "Fix", "type": "func(h heap.Interface, i int)"}, {"class": "func", "name": "Init", "type": "func(h heap.Interface)"}, {"class": "func", "name": "Pop", "type": "func(h heap.Interface) interface{}"}, {"class": "func", "name": "Push", "type": "func(h heap.Interface, x interface{})"}, {"class": "func", "name": "Remove", "type": "func(h heap.Interface, i int) interface{}"}, {"class": "type", "name": "Interface", "type": "interface"}]]

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "New", "type": "func() *list.List"}, {"class": "type", "name": "Element", "type": "struct"}, {"class": "type", "name": "List", "type": "struct"}]]

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "New", "type": "func(n int) *ring.Ring"}, {"class": "type", "name": "Ring", "type": "struct"}]]

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "const", "name": "BlockSize", "type": ""}, {"class": "func", "name": "NewCipher", "type": "func(key []byte) (cipher.Block, error)"}, {"class": "type", "name": "KeySizeError", "type": "int"}]]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "const", "name": "BlockSize", "type": ""}, {"class": "func", "name": "NewCipher", "type": "func(key []byte) (cipher.Block, error)"}, {"class": "func", "name": "NewTripleDESCipher", "type": "func(key []byte) (cipher.Block, error)"}, {"class": "type", "name": "KeySizeError", "type": "int"}]]

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "GenerateKey", "type": "func(c elliptic.Curve, rand io.Reader) (*ecdsa.PrivateKey, error)"}, {"class": "func", "name": "Sign", "type": "func(rand io.Reader, priv *ecdsa.PrivateKey, hash []byte) (r *big.Int, s *big.Int, err error)"}, {"class": "func", "name": "Verify", "type": "func(pub *ecdsa.PublicKey, hash []byte, r *big.Int, s *big.Int) bool"}, {"class": "type", "name": "PrivateKey", "type": "struct"}, {"class": "type", "name": "PublicKey", "type": "struct"}]]

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "Equal", "type": "func(mac1 []byte, mac2 []byte) bool"}, {"class": "func", "name": "New", "type": "func(h func() hash.Hash, key []byte) hash.Hash"}]]

View File

@ -0,0 +1 @@
[0, [{"class": "const", "name": "BlockSize", "type": ""}, {"class": "const", "name": "Size", "type": ""}, {"class": "func", "name": "New", "type": "func() hash.Hash"}, {"class": "func", "name": "Sum", "type": "func(data []byte) [16]byte"}]]

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "Int", "type": "func(rand io.Reader, max *big.Int) (n *big.Int, err error)"}, {"class": "func", "name": "Prime", "type": "func(rand io.Reader, bits int) (p *big.Int, err error)"}, {"class": "func", "name": "Read", "type": "func(b []byte) (n int, err error)"}, {"class": "var", "name": "Reader", "type": "io.Reader"}]]

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "NewCipher", "type": "func(key []byte) (*rc4.Cipher, error)"}, {"class": "type", "name": "Cipher", "type": "struct"}, {"class": "type", "name": "KeySizeError", "type": "int"}]]

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "const", "name": "BlockSize", "type": ""}, {"class": "const", "name": "Size", "type": ""}, {"class": "func", "name": "New", "type": "func() hash.Hash"}, {"class": "func", "name": "Sum", "type": "func(data []byte) [20]byte"}]]

View File

@ -0,0 +1 @@
[0, [{"class": "const", "name": "BlockSize", "type": ""}, {"class": "const", "name": "Size", "type": ""}, {"class": "const", "name": "Size224", "type": ""}, {"class": "func", "name": "New", "type": "func() hash.Hash"}, {"class": "func", "name": "New224", "type": "func() hash.Hash"}, {"class": "func", "name": "Sum224", "type": "func(data []byte) (sum224 [28]byte)"}, {"class": "func", "name": "Sum256", "type": "func(data []byte) [32]byte"}]]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "type", "name": "BinaryMarshaler", "type": "interface"}, {"class": "type", "name": "BinaryUnmarshaler", "type": "interface"}, {"class": "type", "name": "TextMarshaler", "type": "interface"}, {"class": "type", "name": "TextUnmarshaler", "type": "interface"}]]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "Decode", "type": "func(data []byte) (p *pem.Block, rest []byte)"}, {"class": "func", "name": "Encode", "type": "func(out io.Writer, b *pem.Block) error"}, {"class": "func", "name": "EncodeToMemory", "type": "func(b *pem.Block) []byte"}, {"class": "type", "name": "Block", "type": "struct"}]]

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "New", "type": "func(text string) error"}]]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "Node", "type": "func(dst io.Writer, fset *token.FileSet, node interface{}) error"}, {"class": "func", "name": "Source", "type": "func(src []byte) ([]byte, error)"}]]

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "Default", "type": "func() types.Importer"}, {"class": "func", "name": "For", "type": "func(compiler string, lookup importer.Lookup) types.Importer"}, {"class": "type", "name": "Lookup", "type": "func(path string) (io.ReadCloser, error)"}]]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "const", "name": "ScanComments", "type": ""}, {"class": "func", "name": "PrintError", "type": "func(w io.Writer, err error)"}, {"class": "type", "name": "Error", "type": "struct"}, {"class": "type", "name": "ErrorHandler", "type": "func(pos token.Position, msg string)"}, {"class": "type", "name": "ErrorList", "type": "[]*scanner.Error"}, {"class": "type", "name": "Mode", "type": "uint"}, {"class": "type", "name": "Scanner", "type": "struct"}]]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "const", "name": "Size", "type": ""}, {"class": "func", "name": "Checksum", "type": "func(data []byte) uint32"}, {"class": "func", "name": "New", "type": "func() hash.Hash32"}]]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "New32", "type": "func() hash.Hash32"}, {"class": "func", "name": "New32a", "type": "func() hash.Hash32"}, {"class": "func", "name": "New64", "type": "func() hash.Hash64"}, {"class": "func", "name": "New64a", "type": "func() hash.Hash64"}]]

View File

@ -0,0 +1 @@
[0, [{"class": "type", "name": "Hash", "type": "interface"}, {"class": "type", "name": "Hash32", "type": "interface"}, {"class": "type", "name": "Hash64", "type": "interface"}]]

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "EscapeString", "type": "func(s string) string"}, {"class": "func", "name": "UnescapeString", "type": "func(s string) string"}]]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "var", "name": "Plan9", "type": "[]color.Color"}, {"class": "var", "name": "WebSafe", "type": "[]color.Color"}]]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[0, [{"class": "func", "name": "New", "type": "func(data []byte) *suffixarray.Index"}, {"class": "type", "name": "Index", "type": "struct"}]]

Some files were not shown because too many files have changed in this diff Show More