This repository was archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathflowcomplete.vim
More file actions
74 lines (59 loc) · 2.02 KB
/
flowcomplete.vim
File metadata and controls
74 lines (59 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
" Vim completion script
"
" This source code is licensed under the BSD-style license found in the
" LICENSE file in the toplevel directory of this source tree. An additional
" grant of patent rights can be found in the PATENTS file in the same
" directory.
" Magical flow autocomplete token.
let s:autotok = 'AUTO332'
" Omni findstart phase.
function! s:FindStart()
let line = getline('.')
let start = col('.') - 1
while start >= 0 && line[start - 1] =~ '[a-zA-Z_0-9\x7f-\xff$]'
let start -= 1
endwhile
return start
endfunction
function! flowcomplete#Complete(findstart, base)
if a:findstart
return s:FindStart()
endif
let lnum = line('.')
let cnum = col('.')
let lines = getline(1, '$')
" Insert the base and magic token into the current line.
let curline = lines[lnum - 1]
let lines[lnum - 1] = curline[:cnum - 1] . a:base . s:autotok . curline[cnum :]
" Pass the buffer to flow.
let buffer = join(lines, "\n")
let command = g:flow#flowpath.' autocomplete --quiet "'.expand('%:p').'"'
let result = system(command, buffer)
if result =~ '^Error: not enough type information to autocomplete' ||
\ result =~ '^Could not find file or directory'
return []
endif
let matches = []
" Parse the flow output.
for line in split(result, "\n")
if empty(line) | continue | endif
let entry = {}
let space = stridx(line, ' ')
let word = line[:space - 1]
let type = line[space + 1 :]
" Skip matches that don't start with the base"
if (stridx(word, a:base) != 0) | continue | endif
" This is pretty hacky. We're using regexes to recognize the different
" kind of matches. Really in the future we should somehow consume the json
" output
if type =~ '^(.*) =>'
let entry = { 'word': word, 'kind': a:base, 'menu': type }
elseif type =~ '^[class:'
let entry = { 'word': word, 'kind': 'c', 'menu': type }
else
let entry = { 'word': word, 'kind': 'v', 'menu': type }
endif
call add(matches, entry)
endfor
return matches
endfunction