http-codes.nvim/lua/http-codes.lua
Barrett Ruth 4dce284c10 refactor: use vim.g config and lazy loading
Replace setup() with vim.g.http_codes configuration. Add plugin/ file
with load guard for proper lazy loading via lazy.nvim or other managers.
2026-02-03 20:12:54 -05:00

67 lines
1.3 KiB
Lua

local M = {}
local initialized = false
local defaults = {
use = nil,
open_url = nil,
}
local config = vim.deepcopy(defaults)
local function init()
if initialized then
return true
end
local user_config = vim.g.http_codes or {}
config = vim.tbl_deep_extend('force', defaults, user_config)
if not config.open_url then
config.open_url = require('http-codes.os').get_open_url()
end
if not config.use then
if pcall(require, 'fzf-lua') then
config.use = 'fzf-lua'
elseif pcall(require, 'telescope') then
config.use = 'telescope'
end
end
if not config.use then
vim.notify_once('http-codes.nvim: install fzf-lua or telescope.nvim', vim.log.levels.ERROR)
return false
end
if not vim.tbl_contains({ 'fzf-lua', 'telescope' }, config.use) then
vim.notify_once(
"http-codes.nvim: 'use' must be 'fzf-lua' or 'telescope'",
vim.log.levels.ERROR
)
return false
end
if config.use == 'telescope' then
require('http-codes.telescope').setup()
end
initialized = true
return true
end
function M.pick()
if not init() then
return
end
if config.use == 'telescope' then
require('telescope').extensions.http.list(config.open_url)
elseif config.use == 'fzf-lua' then
require('http-codes.fzf-lua').pick(config.open_url)
end
end
M.http_codes = M.pick
return M