set up jai config
This commit is contained in:
44
after/ftplugin/jai.lua
Normal file
44
after/ftplugin/jai.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
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()
|
||||
require("telescope.builtin").find_files({
|
||||
cwd = "/Users/grant/.local/jai",
|
||||
})
|
||||
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" })
|
||||
Reference in New Issue
Block a user