Files
outline.nvim/lua/outline/providers/init.lua
hedy b90174c6c2 refactor: Provider symbol actions
It makes sense to store the provider each sidebar is using with own
self.provider fields, no way that did not occur to me before this.

The old `_G._outline_current_provider` ironically, can now be replaced
by `require('outline').current.provider`.
2023-11-26 15:14:42 +08:00

38 lines
893 B
Lua

local cfg = require('outline.config')
local M = {}
local import_prefix = 'outline/providers/'
---@return outline.Provider?
function M.find_provider()
if not M.providers then
M.providers = vim.tbl_map(function(p)
return import_prefix .. p
end, cfg.get_providers())
end
for _, path in ipairs(M.providers) do
local provider = require(path)
if provider.supports_buffer(0) then
return provider
end
end
end
---@return boolean found_provider
function M.has_provider()
return M.find_provider() ~= nil
end
---Call `sidebar.provider[method]` with args. NOP if no provider or no defined `method`
---@param sidebar outline.Sidebar
---@param method string
---@param args any[]
function M.action(sidebar, method, args)
if not sidebar.provider or not sidebar.provider[method] then
return
end
return sidebar.provider[method](unpack(args))
end
return M