Verified Commit 310ecbb8 authored by Marco Kellershoff's avatar Marco Kellershoff 🤸

Add check if Taskfile exists, before accessing it

This prevents nasty errors.
parent 2eaedf8a
...@@ -7,6 +7,14 @@ let s:PluginName = "Taskfile.nvim" ...@@ -7,6 +7,14 @@ let s:PluginName = "Taskfile.nvim"
let s:isVerbose = 0 let s:isVerbose = 0
let s:taskList = [""] let s:taskList = [""]
function! s:FileExists(filepath)
if filereadable(a:filepath)
return 1
else
return 0
endif
endfunction
function! Taskfile#Verbose(enable) function! Taskfile#Verbose(enable)
if a:enable == 1 if a:enable == 1
let s:isVerbose = 1 let s:isVerbose = 1
...@@ -16,9 +24,14 @@ function! Taskfile#Verbose(enable) ...@@ -16,9 +24,14 @@ function! Taskfile#Verbose(enable)
endfunction endfunction
function! Taskfile#Run(...) function! Taskfile#Run(...)
let task = get(a:, 1, "") let filepath = s:GetTaskfileAbsoluteFilepath()
let cmd = s:GetTaskfileAbsoluteFilepath() . " " . task if s:FileExists(filepath) == 0
call s:ExecExternalCommand(cmd) echo "No Taskfile found"
else
let task = get(a:, 1, "")
let cmd = s:GetTaskfileAbsoluteFilepath() . " " . task
call s:ExecExternalCommand(cmd)
endif
endfunction endfunction
function! Taskfile#Reload() function! Taskfile#Reload()
...@@ -50,8 +63,11 @@ let s:jobEventCallbacks = { ...@@ -50,8 +63,11 @@ let s:jobEventCallbacks = {
\ } \ }
function! s:taskListCompletion(ArgLead, CmdLine, CursorPos) function! s:taskListCompletion(ArgLead, CmdLine, CursorPos)
let filepath = s:GetTaskfileAbsoluteFilepath()
if s:FileExists(filepath) == 0
return ""
endif
let s:taskList = s:GetAllTasks() let s:taskList = s:GetAllTasks()
echo s:taskList
return filter(s:taskList, 'v:val =~ "^'. a:ArgLead .'"') return filter(s:taskList, 'v:val =~ "^'. a:ArgLead .'"')
endfunction endfunction
...@@ -106,5 +122,5 @@ function! s:GetCurrentFile() ...@@ -106,5 +122,5 @@ function! s:GetCurrentFile()
return expand("%") return expand("%")
endfunction endfunction
command! -bang -complete=customlist,s:taskListCompletion -nargs=* Taskfile call Taskfile#Run(<f-args>) command! -bang -complete=customlist,s:taskListCompletion -nargs=* Task 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