1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-04-14 15:19:12 +08:00

docs(task): doc for lua task provider

This commit is contained in:
wsdjeg 2023-08-07 18:36:57 +08:00
parent dcb0b64972
commit 77cd1b85e0

View File

@ -2346,6 +2346,43 @@ endfunction
call SpaceVim#plugins#tasks#reg_provider(function('s:make_tasks'))
```
The provider also can be implemented in lua, for example:
```lua
local task = require('spacevim.plugin.tasks')
local function make_tasks()
if vim.fn.filereadable('Makefile') then
local subcmds = {}
local conf = {}
for _, v in ipairs(vim.fn.readfile('Makefile', '')) do
if vim.startwith(v, '.PHONY') then
table.insert(subcmds, v)
end
end
for _, subcmd in ipairs(subcmds) do
local comamnds = vim.fn.split(subcmd)
table.remove(commands, 1)
for _, cmd in ipairs(commands) do
conf = vim.tbl_extend('forces', conf, {
[cmd] = {
command = 'make',
args = {cmd}
isDetected = true,
detectedName = 'make:'
}
})
end
end
return conf
else
return {}
end
end
task.reg_provider(make_tasks)
```
With the above configuration, you will see the following tasks in the SpaceVim repo:
![task-make](https://img.spacevim.org/75105016-084cac80-564b-11ea-9fe6-75d86a0dbb9b.png)