spacevim/bundle/gina.vim/autoload/gina/complete/filename.vim
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

165 lines
5.0 KiB
VimL

let s:Git = vital#gina#import('Git')
let s:Path = vital#gina#import('System.Filepath')
let s:Store = vital#gina#import('System.Store')
let s:String = vital#gina#import('Data.String')
function! gina#complete#filename#directory(arglead, cmdline, cursorpos) abort
let separator = s:Path.separator()
return filter(
\ gina#complete#filename#any(a:arglead, a:cmdline, a:cursorpos),
\ 'v:val =~# separator . ''$'''
\)
endfunction
function! gina#complete#filename#any(arglead, cmdline, cursorpos) abort
let git = gina#core#get_or_fail()
let candidates = s:get_available_filenames(git, [
\ '--cached', '--others', '--', a:arglead . '*',
\])
return s:filter(a:arglead, candidates)
endfunction
function! gina#complete#filename#tracked(arglead, cmdline, cursorpos, ...) abort
let rev = a:0 ? a:1 : ''
let git = gina#core#get_or_fail()
let slug = eval(s:Store.get_slug_expr()) . rev
let store = s:Store.of([
\ s:Git.resolve(git, 'HEAD'),
\ s:Git.resolve(git, 'index'),
\])
let candidates = store.get(slug, [])
if empty(candidates)
let candidates = s:get_available_filenames(git, [], rev)
call store.set(slug, candidates)
endif
return s:filter(a:arglead, candidates)
endfunction
function! gina#complete#filename#cached(arglead, cmdline, cursorpos) abort
let git = gina#core#get_or_fail()
let slug = eval(s:Store.get_slug_expr())
let store = s:Store.of([
\ s:Git.resolve(git, 'HEAD'),
\ s:Git.resolve(git, 'index'),
\])
let candidates = store.get(slug, [])
if empty(candidates)
let candidates = s:get_available_filenames(git, ['--cached'])
call store.set(slug, candidates)
endif
return s:filter(a:arglead, candidates)
endfunction
function! gina#complete#filename#deleted(arglead, cmdline, cursorpos) abort
let git = gina#core#get_or_fail()
let slug = eval(s:Store.get_slug_expr())
let store = s:Store.of([
\ s:Git.resolve(git, 'HEAD'),
\ s:Git.resolve(git, 'index'),
\])
let candidates = store.get(slug, [])
if empty(candidates)
let candidates = s:get_available_filenames(git, ['--deleted'])
call store.set(slug, candidates)
endif
return s:filter(a:arglead, candidates)
endfunction
function! gina#complete#filename#modified(arglead, cmdline, cursorpos) abort
let git = gina#core#get_or_fail()
let slug = eval(s:Store.get_slug_expr())
let store = s:Store.of([
\ s:Git.resolve(git, 'HEAD'),
\ s:Git.resolve(git, 'index'),
\])
let candidates = store.get(slug, [])
if empty(candidates)
let candidates = s:get_available_filenames(git, ['--modified'])
call store.set(slug, candidates)
endif
return s:filter(a:arglead, candidates)
endfunction
function! gina#complete#filename#others(arglead, cmdline, cursorpos) abort
let git = gina#core#get_or_fail()
let candidates = s:get_available_filenames(git, [
\ '--others', '--', a:arglead . '*',
\])
return s:filter(a:arglead, candidates)
endfunction
function! gina#complete#filename#unstaged(arglead, cmdline, cursorpos) abort
let git = gina#core#get_or_fail()
let candidates = s:get_available_filenames(git, [
\ '--others',
\ '--modified',
\ '--',
\ a:arglead . '*',
\])
return s:filter(a:arglead, candidates)
endfunction
function! gina#complete#filename#conflicted(arglead, cmdline, cursorpos) abort
let git = gina#core#get_or_fail()
let slug = eval(s:Store.get_slug_expr())
let store = s:Store.of([
\ s:Git.resolve(git, 'HEAD'),
\ s:Git.resolve(git, 'index'),
\])
let candidates = store.get(slug, [])
if empty(candidates)
let result = gina#process#call(git, [
\ 'status',
\ '--porcelain',
\ '--ignore-submodules',
\])
if result.status
return []
endif
call filter(
\ candidates,
\ 'v:val[:1] =~# ''^\%(DD\|AU\|UD\|UA\|DU\|AA\|UU\)'''
\)
call map(candidates, 'matchstr(v:val, ''.. \zs.*'')')
call store.set(slug, candidates)
endif
return s:filter(a:arglead, candidates)
endfunction
" Private --------------------------------------------------------------------
function! s:filter(arglead, candidates) abort
let pattern = s:String.escape_pattern(a:arglead)
let separator = s:Path.separator()
let candidates = gina#util#filter(a:arglead, a:candidates, '^\.')
call map(
\ candidates,
\ printf(
\ 'matchstr(v:val, ''^%s[^%s]*%s\?\ze'')',
\ pattern, separator, separator
\ ),
\)
return uniq(candidates)
endfunction
function! s:get_available_filenames(git, args, ...) abort
let rev = a:0 ? a:1 : ''
if empty(rev)
let args = ['ls-files', '--full-name']
else
let args = [
\ 'ls-tree',
\ '--full-name',
\ '--full-tree',
\ '--name-only',
\ '-r',
\ rev,
\]
endif
let result = gina#process#call(a:git, args + a:args)
if result.status
return []
endif
return map(result.stdout, 'gina#core#repo#relpath(a:git, v:val)')
endfunction