Verified Commit 1baf095f authored by Marco Kellershoff's avatar Marco Kellershoff 🤸

Enable auto-completion of tasks

parent 64ab8900
......@@ -11,6 +11,8 @@ You can run the `build` task of the Taskfile like so:
`:Taskfile build` or `:call Taskfile#Run("build")`
You can also autocomplete tasks pressing `<tab>`, or `<tab><tab>`.
### Cache
The Tasks of the Taskfile are cached, if you modify the Taskfile and add jobs,
......
......@@ -13,6 +13,14 @@ function build {
echo ""
}
function listfiles {
ls
}
function listallfiles {
ls -la
}
function tasks {
compgen -A function
}
......
......@@ -5,6 +5,7 @@ let g:loaded_Taskfile = 1
let s:PluginName = "Taskfile.nvim"
let s:isVerbose = 0
let s:taskList = [""]
function! Taskfile#Verbose(enable)
if a:enable == 1
......@@ -16,10 +17,15 @@ endfunction
function! Taskfile#Run(...)
let task = get(a:, 1, "")
let cmd = "./Taskfile " . task
let cmd = s:GetTaskfileAbsoluteFilepath() . " " . task
call s:ExecExternalCommand(cmd)
endfunction
function! Taskfile#Reload()
" TODO Cache Taskfile tasks and only reload the cache when this
" function fires
endfunction
function! Taskfile#List()
let cfg = s:GetAllTasks()
let cmd = s.GetTaskfileFilename()
......@@ -43,10 +49,21 @@ let s:jobEventCallbacks = {
\ 'on_exit': function('s:OnJobEventHandler')
\ }
function! s:taskListCompletion(ArgLead, CmdLine, CursorPos)
let s:taskList = s:GetAllTasks()
echo s:taskList
return filter(s:taskList, 'v:val =~ "^'. a:ArgLead .'"')
endfunction
function! s:GetAllTasks()
let filepath = s:GetTaskfileAbsoluteFilepath()
let tasklist = systemlist(filepath)
return tasklist
endfunction
function! s:GetTaskfileAbsoluteFilepath()
let filepath = getcwd() . "/" . s:GetTaskfileFilename()
let str = s:ReadfileAsString(filepath)
return str
return filepath
endfunction
function! s:GetTaskfileFilename()
......@@ -89,5 +106,5 @@ function! s:GetCurrentFile()
return expand("%")
endfunction
command! -nargs=1 Taskfile call Taskfile#Run(<f-args>)
command! -bang -complete=customlist,s:taskListCompletion -nargs=* Taskfile call Taskfile#Run(<f-args>)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment