mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 07:20:04 +08:00
feat(tasks): add telescope task
This commit is contained in:
parent
eb046b23ef
commit
3db40b345a
@ -380,6 +380,7 @@ function! SpaceVim#layers#core#config() abort
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['p', 't', 'c'], 'call SpaceVim#plugins#runner#clear_tasks()', 'clear-tasks', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['p', 't', 'r'],
|
||||
\ 'call SpaceVim#plugins#runner#run_task(SpaceVim#plugins#tasks#get())', 'pick-task-to-run', 1)
|
||||
" SPC p t f is defined in fuzzy finder layer
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['p', 'k'], 'call SpaceVim#plugins#projectmanager#kill_project()', 'kill-all-project-buffers', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['p', 'p'], 'call SpaceVim#plugins#projectmanager#list()', 'list-all-projects', 1)
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['p', '/'], 'Grepper', 'fuzzy search for text in current project', 1)
|
||||
|
@ -165,6 +165,8 @@ function! SpaceVim#layers#telescope#config() abort
|
||||
\ ],
|
||||
\ 1)
|
||||
|
||||
call SpaceVim#mapping#space#def('nnoremap', ['p', 't', 'f'],
|
||||
\ 'Telescope task', 'fuzzy-find-tasks', 1)
|
||||
let g:_spacevim_mappings.f = {'name' : '+Fuzzy Finder'}
|
||||
call s:defind_fuzzy_finder()
|
||||
|
||||
|
@ -366,6 +366,15 @@ function! s:update_tasks_win_context() abort
|
||||
call s:BUF.buf_set_lines(s:task_viewer_bufnr, 0, -1, 0, sort(lines))
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#tasks#get_tasks() abort
|
||||
call s:load()
|
||||
for Provider in s:providers
|
||||
call extend(s:task_config, call(Provider, []))
|
||||
endfor
|
||||
call s:init_variables()
|
||||
return s:task_config
|
||||
endfunction
|
||||
|
||||
function! SpaceVim#plugins#tasks#edit(...) abort
|
||||
if get(a:000, 0, 0)
|
||||
exe 'e ~/.SpaceVim.d/tasks.toml'
|
||||
|
@ -3,6 +3,7 @@ lua require('telescope').load_extension('messages')
|
||||
lua require('telescope').load_extension('project')
|
||||
lua require('telescope').load_extension('scriptnames')
|
||||
lua require('telescope').load_extension('neoyank')
|
||||
lua require('telescope').load_extension('task')
|
||||
lua require('telescope').load_extension('zettelkasten_template')
|
||||
if filereadable(g:_spacevim_root_dir . 'bundle/telescope-fzf-native.nvim/build/libfzf.so')
|
||||
\ || filereadable(g:_spacevim_root_dir . 'bundle/telescope-fzf-native.nvim/build/libfzf.dll')
|
||||
|
@ -2152,14 +2152,21 @@ which is similar to VSCode's tasks-manager. There are two kinds of task configur
|
||||
The tasks defined in the global tasks configuration can be overrided by project local
|
||||
tasks configuration.
|
||||
|
||||
| Key Bindings | Descriptions |
|
||||
| ------------ | ----------------------------- |
|
||||
| `SPC p t e` | edit tasks configuration file |
|
||||
| `SPC p t r` | select task to run |
|
||||
| `SPC p t l` | list all available tasks |
|
||||
| Key Bindings | Descriptions |
|
||||
| ------------ | ----------------------------------------- |
|
||||
| `SPC p t e` | edit tasks configuration file |
|
||||
| `SPC p t r` | select task to run |
|
||||
| `SPC p t l` | list all available tasks |
|
||||
| `SPC p t f` | fuzzy find tasks(require telescope layer) |
|
||||
|
||||
The `SPC p t l` will open the tasks manager windows, in the tasks manager windows, you can use `Enter` to run task under the cursor.
|
||||
|
||||
![task_manager](https://user-images.githubusercontent.com/13142418/94822603-69d0c700-0435-11eb-95a7-b0b4fef91be5.png)
|
||||
|
||||
If the `telescope` layer is loaded, you can also use `SPC p t f` to fuzzy find specific task, and run the select task.
|
||||
|
||||
![fuzzy-task](https://user-images.githubusercontent.com/13142418/199057483-d5cce17c-2f06-436d-bf7d-24a78d0eeb11.png)
|
||||
|
||||
#### Custom tasks
|
||||
|
||||
This is a basic task configuration for running `echo hello world`,
|
||||
|
89
lua/telescope/_extensions/task.lua
Normal file
89
lua/telescope/_extensions/task.lua
Normal file
@ -0,0 +1,89 @@
|
||||
local action_state = require('telescope.actions.state')
|
||||
local actions = require('telescope.actions')
|
||||
local conf = require('telescope.config').values
|
||||
local entry_display = require('telescope.pickers.entry_display')
|
||||
local finders = require('telescope.finders')
|
||||
local pickers = require('telescope.pickers')
|
||||
|
||||
local function prepare_project_task_output(register)
|
||||
local rst = {}
|
||||
local taskconfig = vim.api.nvim_eval('SpaceVim#plugins#tasks#get_tasks()')
|
||||
for k, v in pairs(taskconfig) do
|
||||
table.insert(rst, {
|
||||
name = k,
|
||||
task = v,
|
||||
})
|
||||
end
|
||||
return rst
|
||||
end
|
||||
|
||||
local function show_taskconfig(opts)
|
||||
local opts = opts or {}
|
||||
local register = opts.register or '"'
|
||||
local displayer = entry_display.create({
|
||||
separator = ' ',
|
||||
items = {
|
||||
{ width = 25 },
|
||||
{ width = 15 },
|
||||
{ remaining = true },
|
||||
},
|
||||
})
|
||||
local function make_display(entry)
|
||||
local n = entry.value.name
|
||||
local desc = entry.value.task.description
|
||||
if desc == nil then
|
||||
desc = entry.value.task.command
|
||||
if entry.value.task.args ~= nil then
|
||||
desc = desc .. ' ' .. table.concat(entry.value.task.args, ' ')
|
||||
end
|
||||
end
|
||||
local task_type = 'local'
|
||||
if entry.value.task.isGlobal == 1 then
|
||||
task_type = 'global'
|
||||
elseif entry.value.task.isDetected == 1 then
|
||||
task_type = 'detected'
|
||||
end
|
||||
return displayer({
|
||||
{ '[' .. entry.value.name .. ']', 'TelescopeResultsVariable' },
|
||||
{ '[' .. task_type .. ']', 'TelescopeResultsNumber' },
|
||||
{ desc, 'TelescopeResultsComment' },
|
||||
})
|
||||
end
|
||||
pickers
|
||||
.new(opts, {
|
||||
prompt_title = 'Project Tasks',
|
||||
finder = finders.new_table({
|
||||
results = prepare_project_task_output(register),
|
||||
entry_maker = function(entry)
|
||||
return {
|
||||
value = entry,
|
||||
display = make_display,
|
||||
ordinal = entry.name,
|
||||
}
|
||||
end,
|
||||
}),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
attach_mappings = function(prompt_bufnr)
|
||||
actions.select_default:replace(function()
|
||||
local entry = action_state.get_selected_entry()
|
||||
actions.close(prompt_bufnr)
|
||||
-- vim.fn.setreg('"', entry.value[1])
|
||||
local task = entry.value.task
|
||||
vim.fn['SpaceVim#plugins#runner#run_task'](task)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
})
|
||||
:find()
|
||||
end
|
||||
|
||||
local function run()
|
||||
show_taskconfig()
|
||||
end
|
||||
|
||||
return require('telescope').register_extension({
|
||||
exports = {
|
||||
-- Default when to argument is given, i.e. :Telescope neoyank
|
||||
task = run,
|
||||
},
|
||||
})
|
Loading…
Reference in New Issue
Block a user