exe_source.lua (967B)
1 local source = {} 2 3 local executable_files = function(callback) 4 local job = require('plenary.job') 5 job:new({ 6 command = 'zsh', 7 args = {'-o', 'shwordsplit', '-c', 'IFS=: && stest -flx $PATH'}, 8 on_exit = function(j, code) 9 if code > 0 then callback({}) end 10 local items = {} 11 for _, item in ipairs(j:result()) do table.insert(items, {label = item}) end 12 callback(items) 13 end, 14 }):sync() 15 end 16 17 ---Source constructor. 18 source.new = function() 19 local self = setmetatable({}, {__index = source}) 20 executable_files(function(items) self.files = items end) 21 return self 22 end 23 24 ---Invoke completion (required). 25 --- If you want to abort completion, just call the callback without arguments. 26 ---@param params cmp.SourceCompletionApiParams 27 ---@param callback fun(response: lsp.CompletionResponse|nil) 28 function source:complete(params, callback) 29 if #self.files > 0 then 30 callback(self.files) 31 else 32 callback() 33 end 34 end 35 36 return source