Neovim quick file switcher
at main 1.4 kB view raw
1local ui = require("javelin.ui") 2local data = require("javelin.data") 3 4local Javelin = {} 5 6---@class JavelinConfig 7local defaults = { 8 use_git_root = true, 9 -- Passthrough options to Snacks.win 10 menu = { 11 width = 0.6, 12 height = 8, 13 title_pos = "center", 14 border = "rounded", 15 keys = { 16 ["<CR>"] = "goto", 17 q = "close", 18 ["<Esc>"] = "close", 19 }, 20 }, 21} 22 23function Javelin.open() 24 return ui.open() 25end 26 27---@param index number 28function Javelin.select(index) 29 return ui.select(index) 30end 31 32function Javelin.add() 33 return data.add_current() 34end 35 36local function create_user_command() 37 local commands = { 38 open = Javelin.open, 39 add = Javelin.add, 40 } 41 42 vim.api.nvim_create_user_command("Javelin", function(args) 43 local cmd = vim.trim(args.args or "") 44 if cmd == "" then 45 commands.open() 46 elseif commands[cmd] then 47 commands[cmd]() 48 end 49 end, { 50 desc = "Javelin", 51 nargs = "?", 52 complete = function(_, line) 53 if line:match("^%s*Javelin %w+ ") then 54 return {} 55 end 56 local prefix = line:match("^%s*Javelin (%w*)") or "" 57 return vim.tbl_filter(function(key) 58 return key:find(prefix) == 1 59 end, vim.tbl_keys(commands)) 60 end, 61 }) 62end 63 64---@param opt? JavelinConfig 65function Javelin.setup(opt) 66 ---@type JavelinConfig 67 local options = vim.tbl_deep_extend("force", {}, defaults, opt or {}) 68 69 create_user_command() 70 71 ui.setup(options) 72 data.setup(options) 73end 74 75return Javelin