parent
1de922423f
commit
9a2891dc31
@ -70,27 +70,6 @@ function! foreplay#ns_complete(A, L, P) abort
|
|||||||
return filter(map(matches, 's:tons(v:val)'), 'a:A ==# "" || a:A ==# v:val[0 : strlen(a:A)-1]')
|
return filter(map(matches, 's:tons(v:val)'), 'a:A ==# "" || a:A ==# v:val[0 : strlen(a:A)-1]')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" This turns a string (potentially with '.' separators into a fuzzy-matching
|
|
||||||
" regex. This is where fuzzy matching behavior is defined.
|
|
||||||
function! foreplay#fuzzy(base)
|
|
||||||
let not_dot = '[^.]*'
|
|
||||||
let regex = ''
|
|
||||||
let anchor = 1 " means that the next char must be in the next position
|
|
||||||
for i in range(strlen(a:base))
|
|
||||||
let c = a:base[i]
|
|
||||||
if c ==# '.'
|
|
||||||
let regex .= not_dot.'\.'
|
|
||||||
let anchor = 1
|
|
||||||
elseif anchor
|
|
||||||
let regex .= c
|
|
||||||
let anchor = 0
|
|
||||||
else
|
|
||||||
let regex .= not_dot.c
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
return '^'.regex.not_dot.'$'
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! foreplay#omnicomplete(findstart, base) abort
|
function! foreplay#omnicomplete(findstart, base) abort
|
||||||
if a:findstart
|
if a:findstart
|
||||||
let line = getline('.')[0 : col('.')-2]
|
let line = getline('.')[0 : col('.')-2]
|
||||||
@ -107,32 +86,21 @@ function! foreplay#omnicomplete(findstart, base) abort
|
|||||||
\ '(sort-by :word (map '.omnifier.' (ns-map '.s:qsym(ns).')))]')
|
\ '(sort-by :word (map '.omnifier.' (ns-map '.s:qsym(ns).')))]')
|
||||||
|
|
||||||
if a:base =~# '^[^/]*/[^/]*$'
|
if a:base =~# '^[^/]*/[^/]*$'
|
||||||
" This branch generates completions when there's a qualified var
|
let ns = matchstr(a:base, '^.*\ze/')
|
||||||
let ns_fuzzy = foreplay#fuzzy(matchstr(a:base, '^.*\ze/'))
|
let prefix = ns . '/'
|
||||||
let name_fuzzy = foreplay#fuzzy(matchstr(a:base, '/\zs.*$'))
|
let ns = get(aliases, ns, ns)
|
||||||
let results = []
|
let keyword = matchstr(a:base, '.*/\zs.*')
|
||||||
for ns in filter(namespaces + keys(aliases), 'v:val =~# ns_fuzzy')
|
let results = foreplay#evalparse(
|
||||||
let lookup_ns = ns
|
\ '(sort-by :word (map '.omnifier.' (ns-publics '.s:qsym(ns).')))')
|
||||||
if has_key(aliases, ns) "if alias, must use actual ns for lookup
|
for r in results
|
||||||
let lookup_ns = get(aliases, ns)
|
let r.word = prefix . r.word
|
||||||
endif
|
|
||||||
let results = results + foreplay#evalparse(
|
|
||||||
\ '(->> (ns-publics '.s:qsym(lookup_ns).')' .
|
|
||||||
\ '(filter #(re-matches #"'.name_fuzzy.'" (name (key %))))' .
|
|
||||||
\ '(map (fn [[k v]] [(str "'.ns.'" \/ (name k)) v]))' .
|
|
||||||
\ '(map '.omnifier.')' .
|
|
||||||
\ '(sort-by :word))')
|
|
||||||
endfor
|
endfor
|
||||||
else
|
else
|
||||||
" This branch handles completions for namespaces, aliases, and vars
|
let keyword = a:base
|
||||||
let fuzzy_base = foreplay#fuzzy(a:base)
|
let results = maps + map(sort(keys(aliases) + namespaces), '{"word": v:val."/", "kind": "t", "info": ""}')
|
||||||
let results = maps + map(sort(keys(aliases) + namespaces),
|
|
||||||
\ '{"word": v:val, "kind": "t", "info": ""}')
|
|
||||||
let results = filter(results,
|
|
||||||
\ 'a:base ==# "" || v:val.word =~# fuzzy_base')
|
|
||||||
endif
|
endif
|
||||||
if type(results) == type([])
|
if type(results) == type([])
|
||||||
return results
|
return filter(results, 'a:base ==# "" || a:base ==# v:val.word[0 : strlen(a:base)-1]')
|
||||||
else
|
else
|
||||||
return []
|
return []
|
||||||
endif
|
endif
|
||||||
|
Loading…
Reference in New Issue
Block a user