Files
nvim/after/ftplugin/jai.lua
2026-04-23 09:21:36 -04:00

46 lines
1.3 KiB
Lua

vim.keymap.set("n", "gd", function()
-- grab the word under the cursor
local word = vim.fn.expand("<cword>")
print(word)
-- search for "def <word>" or "class <word>" in the current project
local command = string.format("rg --no-heading -n -g '*.jai' '^%s[[:space:]]*:' ~/.local/jai ./", word)
local results = vim.fn.systemlist(command)
if #results == 0 then
print("no definition found for " .. word)
return
end
-- populate the quickfix list and open it
local qf = {}
for _, line in ipairs(results) do
local file, lnum, text = line:match("^(.+):(%d+):(.*)$")
if file then
table.insert(qf, {
filename = file,
lnum = tonumber(lnum),
text = text,
})
end
end
if #qf == 1 then
vim.cmd.edit(string.format("+%d %s", qf[1].lnum, qf[1].filename))
return
end
vim.fn.setqflist(qf)
vim.cmd.copen()
end, { buffer = true, desc = "Go to definition (jai)" })
vim.keymap.set("n", "<leader>fj", function()
local jai_path = vim.fn.expand("$HOME/.local/jai")
require("telescope.builtin").find_files({
cwd = jai_path,
})
end, { buffer = true, desc = "Telescope find files" })
vim.keymap.set("n", "<leader>fJ", function()
require("telescope.builtin").live_grep({
cwd = "/Users/grant/.local/jai",
})
end, { buffer = true, desc = "Telescope find files" })