Skip to content

Commit

Permalink
json_cache: Support parses library name & Change json cache dir name
Browse files Browse the repository at this point in the history
- Add parses library name
  -  e.g. 'go/ast' is 'go'
  - If imported 'github.com/pkg/errors', ignore cache for 'errors'

- Change json cache files
  - 'go/ast' is '/path/to/go/ast.json'
  - 'errors' is '/path/to/errors/errors.json'

Signed-off-by: Koichi Shiraishi <k@zchee.io>
  • Loading branch information
zchee committed May 26, 2016
1 parent 03d4dc2 commit 4897d58
Show file tree
Hide file tree
Showing 282 changed files with 102 additions and 60 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Plug 'zchee/deoplete-go', { 'do': 'make'}
| `g:deoplete#sources#go#package_dot` | `0` | No |
| `g:deoplete#sources#go#sort_class` | `[]` | Recommend |
| `g:deoplete#sources#go#use_cache` | `0` | Recommend |
| `g:deoplete#sources#go#data_directory` | `$HOME.'/.config/gocode/json'` | Recommend |
| `g:deoplete#sources#go#json_directory` | `$HOME.'/.config/gocode/json'` | Recommend |

### `g:deoplete#sources#go#align_class`
#### Class Aligning
Expand Down Expand Up @@ -173,7 +173,7 @@ let g:deoplete#sources#go#sort_class = ['package', 'func', 'type', 'var', 'const

Try test it with the `os` package :)

### `g:deoplete#sources#go#use_cache` `g:deoplete#sources#go#data_directory`
### `g:deoplete#sources#go#use_cache` `g:deoplete#sources#go#json_directory`
#### Static json caching

`g:deoplete#sources#go#use_cache`
Expand All @@ -184,9 +184,9 @@ Try test it with the `os` package :)
| **Type** | int |
| **Example** | `1` |

`g:deoplete#sources#go#data_directory`
`g:deoplete#sources#go#json_directory`

| **Default** | `~/.cache/gocode/json` |
| **Default** | `~/.cache/deoplete/go/$GOOS_$GOARCH` |
|--------------|------------------------|
| **Required** | **Recommend** |
| **Type** | string |
Expand All @@ -202,14 +202,14 @@ Terms:
- You typed package name have not `import` current buffer
- Match the typed package name and json file name

`deoplete-go` will parse `g:deoplete#sources#go#data_directory` directory. You can define of json data directory.
Default is `~/.cache/gocode/json`.
`deoplete-go` will parse `g:deoplete#sources#go#json_directory` directory. You can define of json data directory.
Default is `~/.cache/deoplete/go/$GOOS_$GOARCH`.

Also, See [How to use static json caching](#how-to-use-static-json-caching)

```vim
let g:deoplete#sources#go#use_cache = 1
let g:deoplete#sources#go#data_directory = '/path/to/data_dir'
let g:deoplete#sources#go#json_directory = '/path/to/data_dir'
```

===
Expand All @@ -223,7 +223,7 @@ let g:deoplete#sources#go#data_directory = '/path/to/data_dir'

Pre-generate json data is [data/json](./data/json).
If you use it, `cp -r data/json/VERSION/$GOOS_$GOARCH /path/to/data_dir`.
`/path/to/data_dir` is `g:deoplete#sources#go#data_directory`.
`/path/to/data_dir` is `g:deoplete#sources#go#json_directory`.

And, You can generate your Go environment. such as version is `devel`, GOARCH is `arm`.
If you want to it, run `make gen_json`.
Expand Down Expand Up @@ -259,7 +259,7 @@ let g:deoplete#enable_at_startup = 1
let g:deoplete#sources#go#gocode_binary = $GOPATH.'/bin/gocode'
let g:deoplete#sources#go#sort_class = ['package', 'func', 'type', 'var', 'const']
let g:deoplete#sources#go#use_cache = 1
let g:deoplete#sources#go#data_directory = '/path/to/data_dir'
let g:deoplete#sources#go#json_directory = '/path/to/data_dir'
```

===
Expand Down
9 changes: 7 additions & 2 deletions data/gen_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ def main():

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()

Expand All @@ -52,8 +54,11 @@ def main():
if not os.path.exists(out_dir):
os.makedirs(out_dir)

pkg_dir = os.path.join(out_dir, ''.join(library))
if not os.path.exists(pkg_dir):
os.makedirs(pkg_dir)
out_path = \
os.path.join(out_dir, func + '.json')
os.path.join(pkg_dir, func + '.json')
out = open(out_path, 'w')
out.write(json.dumps(result, sort_keys=True))
out.close()
Expand All @@ -75,6 +80,6 @@ def is_exec(fpath):
binary = os.path.join(path, cmd)
if is_exec(binary):
return binary
return error(self.vim, 'gocode binary not found')
return print('gocode binary not found')

main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions data/json/1.6.2/darwin_amd64/crypto/rand.json
Original file line number Diff line number Diff line change
@@ -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"}]]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions data/json/1.6.2/darwin_amd64/crypto/tls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0, [{"class": "const", "name": "CurveP256", "type": ""}, {"class": "const", "name": "CurveP384", "type": ""}, {"class": "const", "name": "CurveP521", "type": ""}, {"class": "const", "name": "NoClientCert", "type": ""}, {"class": "const", "name": "RenegotiateFreelyAsClient", "type": ""}, {"class": "const", "name": "RenegotiateNever", "type": ""}, {"class": "const", "name": "RenegotiateOnceAsClient", "type": ""}, {"class": "const", "name": "RequestClientCert", "type": ""}, {"class": "const", "name": "RequireAndVerifyClientCert", "type": ""}, {"class": "const", "name": "RequireAnyClientCert", "type": ""}, {"class": "const", "name": "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "type": ""}, {"class": "const", "name": "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "type": ""}, {"class": "const", "name": "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", "type": ""}, {"class": "const", "name": "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "type": ""}, {"class": "const", "name": "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", "type": ""}, {"class": "const", "name": "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", "type": ""}, {"class": "const", "name": "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "type": ""}, {"class": "const", "name": "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "type": ""}, {"class": "const", "name": "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", "type": ""}, {"class": "const", "name": "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "type": ""}, {"class": "const", "name": "TLS_ECDHE_RSA_WITH_RC4_128_SHA", "type": ""}, {"class": "const", "name": "TLS_FALLBACK_SCSV", "type": ""}, {"class": "const", "name": "TLS_RSA_WITH_3DES_EDE_CBC_SHA", "type": ""}, {"class": "const", "name": "TLS_RSA_WITH_AES_128_CBC_SHA", "type": ""}, {"class": "const", "name": "TLS_RSA_WITH_AES_128_GCM_SHA256", "type": ""}, {"class": "const", "name": "TLS_RSA_WITH_AES_256_CBC_SHA", "type": ""}, {"class": "const", "name": "TLS_RSA_WITH_AES_256_GCM_SHA384", "type": ""}, {"class": "const", "name": "TLS_RSA_WITH_RC4_128_SHA", "type": ""}, {"class": "const", "name": "VerifyClientCertIfGiven", "type": ""}, {"class": "const", "name": "VersionSSL30", "type": ""}, {"class": "const", "name": "VersionTLS10", "type": ""}, {"class": "const", "name": "VersionTLS11", "type": ""}, {"class": "const", "name": "VersionTLS12", "type": ""}, {"class": "func", "name": "Client", "type": "func(conn net.Conn, config *tls.Config) *tls.Conn"}, {"class": "func", "name": "Dial", "type": "func(network string, addr string, config *tls.Config) (*tls.Conn, error)"}, {"class": "func", "name": "DialWithDialer", "type": "func(dialer *net.Dialer, network string, addr string, config *tls.Config) (*tls.Conn, error)"}, {"class": "func", "name": "Listen", "type": "func(network string, laddr string, config *tls.Config) (net.Listener, error)"}, {"class": "func", "name": "LoadX509KeyPair", "type": "func(certFile string, keyFile string) (tls.Certificate, error)"}, {"class": "func", "name": "NewLRUClientSessionCache", "type": "func(capacity int) tls.ClientSessionCache"}, {"class": "func", "name": "NewListener", "type": "func(inner net.Listener, config *tls.Config) net.Listener"}, {"class": "func", "name": "Server", "type": "func(conn net.Conn, config *tls.Config) *tls.Conn"}, {"class": "func", "name": "X509KeyPair", "type": "func(certPEMBlock []byte, keyPEMBlock []byte) (tls.Certificate, error)"}, {"class": "type", "name": "Certificate", "type": "struct"}, {"class": "type", "name": "ClientAuthType", "type": "int"}, {"class": "type", "name": "ClientHelloInfo", "type": "struct"}, {"class": "type", "name": "ClientSessionCache", "type": "interface"}, {"class": "type", "name": "ClientSessionState", "type": "struct"}, {"class": "type", "name": "Config", "type": "struct"}, {"class": "type", "name": "Conn", "type": "struct"}, {"class": "type", "name": "ConnectionState", "type": "struct"}, {"class": "type", "name": "CurveID", "type": "uint16"}, {"class": "type", "name": "RecordHeaderError", "type": "struct"}, {"class": "type", "name": "RenegotiationSupport", "type": "int"}]]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions data/json/1.6.2/darwin_amd64/go/scanner.json
Original file line number Diff line number Diff line change
@@ -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 renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions data/json/1.6.2/darwin_amd64/html/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0, [{"class": "const", "name": "ErrAmbigContext", "type": ""}, {"class": "const", "name": "ErrBadHTML", "type": ""}, {"class": "const", "name": "ErrBranchEnd", "type": ""}, {"class": "const", "name": "ErrEndContext", "type": ""}, {"class": "const", "name": "ErrNoSuchTemplate", "type": ""}, {"class": "const", "name": "ErrOutputContext", "type": ""}, {"class": "const", "name": "ErrPartialCharset", "type": ""}, {"class": "const", "name": "ErrPartialEscape", "type": ""}, {"class": "const", "name": "ErrRangeLoopReentry", "type": ""}, {"class": "const", "name": "ErrSlashAmbig", "type": ""}, {"class": "const", "name": "OK", "type": ""}, {"class": "func", "name": "HTMLEscape", "type": "func(w io.Writer, b []byte)"}, {"class": "func", "name": "HTMLEscapeString", "type": "func(s string) string"}, {"class": "func", "name": "HTMLEscaper", "type": "func(args ...interface{}) string"}, {"class": "func", "name": "IsTrue", "type": "func(val interface{}) (truth bool, ok bool)"}, {"class": "func", "name": "JSEscape", "type": "func(w io.Writer, b []byte)"}, {"class": "func", "name": "JSEscapeString", "type": "func(s string) string"}, {"class": "func", "name": "JSEscaper", "type": "func(args ...interface{}) string"}, {"class": "func", "name": "Must", "type": "func(t *template.Template, err error) *template.Template"}, {"class": "func", "name": "New", "type": "func(name string) *template.Template"}, {"class": "func", "name": "ParseFiles", "type": "func(filenames ...string) (*template.Template, error)"}, {"class": "func", "name": "ParseGlob", "type": "func(pattern string) (*template.Template, error)"}, {"class": "func", "name": "URLQueryEscaper", "type": "func(args ...interface{}) string"}, {"class": "type", "name": "CSS", "type": "string"}, {"class": "type", "name": "Error", "type": "struct"}, {"class": "type", "name": "ErrorCode", "type": "int"}, {"class": "type", "name": "FuncMap", "type": "map[string]interface{}"}, {"class": "type", "name": "HTML", "type": "string"}, {"class": "type", "name": "HTMLAttr", "type": "string"}, {"class": "type", "name": "JS", "type": "string"}, {"class": "type", "name": "JSStr", "type": "string"}, {"class": "type", "name": "Template", "type": "struct"}, {"class": "type", "name": "URL", "type": "string"}]]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[0, [{"class": "const", "name": "SeekCurrent", "type": ""}, {"class": "const", "name": "SeekEnd", "type": ""}, {"class": "const", "name": "SeekStart", "type": ""}, {"class": "func", "name": "Copy", "type": "func(dst io.Writer, src io.Reader) (written int64, err error)"}, {"class": "func", "name": "CopyBuffer", "type": "func(dst io.Writer, src io.Reader, buf []byte) (written int64, err error)"}, {"class": "func", "name": "CopyN", "type": "func(dst io.Writer, src io.Reader, n int64) (written int64, err error)"}, {"class": "func", "name": "LimitReader", "type": "func(r io.Reader, n int64) io.Reader"}, {"class": "func", "name": "MultiReader", "type": "func(readers ...io.Reader) io.Reader"}, {"class": "func", "name": "MultiWriter", "type": "func(writers ...io.Writer) io.Writer"}, {"class": "func", "name": "NewSectionReader", "type": "func(r io.ReaderAt, off int64, n int64) *io.SectionReader"}, {"class": "func", "name": "Pipe", "type": "func() (*io.PipeReader, *io.PipeWriter)"}, {"class": "func", "name": "ReadAtLeast", "type": "func(r io.Reader, buf []byte, min int) (n int, err error)"}, {"class": "func", "name": "ReadFull", "type": "func(r io.Reader, buf []byte) (n int, err error)"}, {"class": "func", "name": "TeeReader", "type": "func(r io.Reader, w io.Writer) io.Reader"}, {"class": "func", "name": "WriteString", "type": "func(w io.Writer, s string) (n int, err error)"}, {"class": "type", "name": "ByteReader", "type": "interface"}, {"class": "type", "name": "ByteScanner", "type": "interface"}, {"class": "type", "name": "ByteWriter", "type": "interface"}, {"class": "type", "name": "Closer", "type": "interface"}, {"class": "type", "name": "LimitedReader", "type": "struct"}, {"class": "type", "name": "PipeReader", "type": "struct"}, {"class": "type", "name": "PipeWriter", "type": "struct"}, {"class": "type", "name": "ReadCloser", "type": "interface"}, {"class": "type", "name": "ReadSeeker", "type": "interface"}, {"class": "type", "name": "ReadWriteCloser", "type": "interface"}, {"class": "type", "name": "ReadWriteSeeker", "type": "interface"}, {"class": "type", "name": "ReadWriter", "type": "interface"}, {"class": "type", "name": "Reader", "type": "interface"}, {"class": "type", "name": "ReaderAt", "type": "interface"}, {"class": "type", "name": "ReaderFrom", "type": "interface"}, {"class": "type", "name": "RuneReader", "type": "interface"}, {"class": "type", "name": "RuneScanner", "type": "interface"}, {"class": "type", "name": "SectionReader", "type": "struct"}, {"class": "type", "name": "Seeker", "type": "interface"}, {"class": "type", "name": "SizedReaderAt", "type": "interface"}, {"class": "type", "name": "WriteCloser", "type": "interface"}, {"class": "type", "name": "WriteSeeker", "type": "interface"}, {"class": "type", "name": "Writer", "type": "interface"}, {"class": "type", "name": "WriterAt", "type": "interface"}, {"class": "type", "name": "WriterTo", "type": "interface"}, {"class": "var", "name": "EOF", "type": "error"}, {"class": "var", "name": "ErrClosedPipe", "type": "error"}, {"class": "var", "name": "ErrNoProgress", "type": "error"}, {"class": "var", "name": "ErrShortBuffer", "type": "error"}, {"class": "var", "name": "ErrShortWrite", "type": "error"}, {"class": "var", "name": "ErrUnexpectedEOF", "type": "error"}]]
[0, [{"class": "const", "name": "SeekCurrent", "type": ""}, {"class": "const", "name": "SeekEnd", "type": ""}, {"class": "const", "name": "SeekStart", "type": ""}, {"class": "func", "name": "Copy", "type": "func(dst io.Writer, src io.Reader) (written int64, err error)"}, {"class": "func", "name": "CopyBuffer", "type": "func(dst io.Writer, src io.Reader, buf []byte) (written int64, err error)"}, {"class": "func", "name": "CopyN", "type": "func(dst io.Writer, src io.Reader, n int64) (written int64, err error)"}, {"class": "func", "name": "LimitReader", "type": "func(r io.Reader, n int64) io.Reader"}, {"class": "func", "name": "MultiReader", "type": "func(readers ...io.Reader) io.Reader"}, {"class": "func", "name": "MultiWriter", "type": "func(writers ...io.Writer) io.Writer"}, {"class": "func", "name": "NewSectionReader", "type": "func(r io.ReaderAt, off int64, n int64) *io.SectionReader"}, {"class": "func", "name": "Pipe", "type": "func() (*io.PipeReader, *io.PipeWriter)"}, {"class": "func", "name": "ReadAtLeast", "type": "func(r io.Reader, buf []byte, min int) (n int, err error)"}, {"class": "func", "name": "ReadFull", "type": "func(r io.Reader, buf []byte) (n int, err error)"}, {"class": "func", "name": "TeeReader", "type": "func(r io.Reader, w io.Writer) io.Reader"}, {"class": "func", "name": "WriteString", "type": "func(w io.Writer, s string) (n int, err error)"}, {"class": "type", "name": "ByteReader", "type": "interface"}, {"class": "type", "name": "ByteScanner", "type": "interface"}, {"class": "type", "name": "ByteWriter", "type": "interface"}, {"class": "type", "name": "Closer", "type": "interface"}, {"class": "type", "name": "LimitedReader", "type": "struct"}, {"class": "type", "name": "PipeReader", "type": "struct"}, {"class": "type", "name": "PipeWriter", "type": "struct"}, {"class": "type", "name": "ReadCloser", "type": "interface"}, {"class": "type", "name": "ReadSeeker", "type": "interface"}, {"class": "type", "name": "ReadWriteCloser", "type": "interface"}, {"class": "type", "name": "ReadWriteSeeker", "type": "interface"}, {"class": "type", "name": "ReadWriter", "type": "interface"}, {"class": "type", "name": "Reader", "type": "interface"}, {"class": "type", "name": "ReaderAt", "type": "interface"}, {"class": "type", "name": "ReaderFrom", "type": "interface"}, {"class": "type", "name": "RuneReader", "type": "interface"}, {"class": "type", "name": "RuneScanner", "type": "interface"}, {"class": "type", "name": "SectionReader", "type": "struct"}, {"class": "type", "name": "Seeker", "type": "interface"}, {"class": "type", "name": "WriteCloser", "type": "interface"}, {"class": "type", "name": "WriteSeeker", "type": "interface"}, {"class": "type", "name": "Writer", "type": "interface"}, {"class": "type", "name": "WriterAt", "type": "interface"}, {"class": "type", "name": "WriterTo", "type": "interface"}, {"class": "var", "name": "EOF", "type": "error"}, {"class": "var", "name": "ErrClosedPipe", "type": "error"}, {"class": "var", "name": "ErrNoProgress", "type": "error"}, {"class": "var", "name": "ErrShortBuffer", "type": "error"}, {"class": "var", "name": "ErrShortWrite", "type": "error"}, {"class": "var", "name": "ErrUnexpectedEOF", "type": "error"}]]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 4897d58

Please sign in to comment.