Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions autoload/asyncomplete/sources/file.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,46 @@ function! s:filename_map(prefix, file) abort
\ }
endfunction

function! s:matches_for_prefix(pre, cwd) abort
let l:pre = a:pre
let l:cwd = a:cwd

let l:glob = fnamemodify(l:cwd, ':t') . '*'
let l:cwd = fnamemodify(l:cwd, ':p:h')

if l:pre !~ '/$'
let l:pre = l:pre . '/'
endif

let l:cwdlen = strlen(l:cwd)
let l:files = split(globpath(l:cwd, l:glob), '\n')
return map(l:files, {key, val -> s:filename_map(l:pre, val)})
endfunction

function! asyncomplete#sources#file#completor(opt, ctx)
let l:bufnr = a:ctx['bufnr']
let l:typed = a:ctx['typed']
let l:col = a:ctx['col']

let l:kw = matchstr(l:typed, '<\@<!\.\{0,2}/.*$')
let l:kwlen = len(l:kw)
let l:pre = fnamemodify(l:kw, ':h')

if l:kwlen < 1
return
endif

if l:kw !~ '^/'
let l:cwd = expand('#' . l:bufnr . ':p:h') . '/' . l:kw
let l:filecwd = expand('#' . l:bufnr . ':p:h') . '/' . l:kw
let l:pwd = getcwd() . '/' . l:kw

let l:matches = s:matches_for_prefix(l:pre, l:filecwd) + s:matches_for_prefix(l:pre, l:pwd)
else
let l:cwd = l:kw
let l:matches = s:matches_for_prefix(l:pre, l:filecwd)
endif

let l:glob = fnamemodify(l:cwd, ':t') . '*'
let l:cwd = fnamemodify(l:cwd, ':p:h')
let l:pre = fnamemodify(l:kw, ':h')

if l:pre !~ '/$'
let l:pre = l:pre . '/'
endif

let l:cwdlen = strlen(l:cwd)
let l:startcol = l:col - l:kwlen
let l:files = split(globpath(l:cwd, l:glob), '\n')
let l:matches = map(l:files, {key, val -> s:filename_map(l:pre, val)})

call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches)
endfunction

Expand Down