Skip to content

Commit

Permalink
feat: setup avante
Browse files Browse the repository at this point in the history
  • Loading branch information
reVrost committed Dec 22, 2024
1 parent 8b37b52 commit 42a7188
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 122 deletions.
6 changes: 6 additions & 0 deletions nvim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"LuaSnip": { "branch": "master", "commit": "33b06d72d220aa56a7ce80a0dd6f06c70cd82b9d" },
"NvChad": { "branch": "v2.5", "commit": "bbc3d43db088c141b142a40cd5f717635833a54e" },
"avante.nvim": { "branch": "main", "commit": "01e05a538b4b7f20fb922016d72be8c42d400b0e" },
"base46": { "branch": "v2.5", "commit": "40943fc668bf8f1caa4cc45f71c784cf0d3cc34f" },
"cellular-automaton.nvim": { "branch": "main", "commit": "11aea08aa084f9d523b0142c2cd9441b8ede09ed" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
Expand All @@ -9,14 +10,17 @@
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" },
"conform.nvim": { "branch": "master", "commit": "339b3e4519ec49312d34fcfa275aa15bfaa67025" },
"copilot.lua": { "branch": "master", "commit": "d3783b9283a7c35940ed8d71549030d5f5f9f980" },
"copilot.vim": { "branch": "release", "commit": "87038123804796ca7af20d1b71c3428d858a9124" },
"dashboard-nvim": { "branch": "master", "commit": "ae309606940d26d8c9df8b048a6e136b6bbec478" },
"diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" },
"dressing.nvim": { "branch": "master", "commit": "3a45525bb182730fe462325c99395529308f431e" },
"dropbar.nvim": { "branch": "master", "commit": "b3b085e936ba1578ee2ae02de44274f96fbb5e07" },
"flit.nvim": { "branch": "main", "commit": "1ef72de6a02458d31b10039372c8a15ab8989e0d" },
"friendly-snippets": { "branch": "main", "commit": "efff286dd74c22f731cdec26a70b46e5b203c619" },
"gitsigns.nvim": { "branch": "main", "commit": "5f808b5e4fef30bd8aca1b803b4e555da07fc412" },
"grapple.nvim": { "branch": "main", "commit": "b41ddfc1c39f87f3d1799b99c2f0f1daa524c5f7" },
"img-clip.nvim": { "branch": "main", "commit": "5ff183655ad98b5fc50c55c66540375bbd62438c" },
"incline.nvim": { "branch": "main", "commit": "16fc9c073e3ea4175b66ad94375df6d73fc114c0" },
"indent-blankline.nvim": { "branch": "master", "commit": "259357fa4097e232730341fa60988087d189193a" },
"lazy.nvim": { "branch": "main", "commit": "7e6c863bc7563efbdd757a310d17ebc95166cef3" },
Expand All @@ -29,6 +33,7 @@
"mini.files": { "branch": "main", "commit": "72cc9045c1011f2c158117bd5a0d339792b7f34a" },
"mini.indentscope": { "branch": "main", "commit": "da9af64649e114aa79480c238fd23f6524bc0903" },
"minty": { "branch": "main", "commit": "6dce9f097667862537823d515a0250ce58faab05" },
"nui.nvim": { "branch": "main", "commit": "53e907ffe5eedebdca1cd503b00aa8692068ca46" },
"nvim-autopairs": { "branch": "master", "commit": "b464658e9b880f463b9f7e6ccddd93fb0013f559" },
"nvim-cmp": { "branch": "main", "commit": "b555203ce4bd7ff6192e759af3362f9d217e8c89" },
"nvim-lspconfig": { "branch": "master", "commit": "f1405c1ea5d7a1051a8ced3110d7cf3b8524041b" },
Expand All @@ -38,6 +43,7 @@
"nvim-web-devicons": { "branch": "master", "commit": "6317aca1fd86cc8e8c5ad30029ae7640d566cec6" },
"plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" },
"quicker.nvim": { "branch": "master", "commit": "049d66534d3de5920663ee1b8dd0096d70f55a67" },
"render-markdown.nvim": { "branch": "main", "commit": "0022a579ac7355966be5ade77699b88c76b6a549" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "dae2eac9d91464448b584c7949a31df8faefec56" },
"telescope-live-grep-args.nvim": { "branch": "master", "commit": "649b662a8f476fd2c0289570764459e95ebaa3f3" },
"telescope.nvim": { "branch": "master", "commit": "2eca9ba22002184ac05eddbe47a7fe2d5a384dfc" },
Expand Down
264 changes: 142 additions & 122 deletions nvim/lua/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ opt.encoding = "utf-8"
opt.splitkeep = "screen"

-- vim snippets
g.vscode_snippets_path = fn.stdpath("config") .. "/lua/custom/snippets"
g.lua_snippets_path = fn.stdpath("config") .. "/lua/custom/snippets"
g.vscode_snippets_path = fn.stdpath "config" .. "/lua/custom/snippets"
g.lua_snippets_path = fn.stdpath "config" .. "/lua/custom/snippets"
g.go_term_mode = "vsplit"
g.go_term_enabled = 1

Expand All @@ -20,160 +20,180 @@ g.neovide_scale_factor = 0.8
-- See `:help vim.highlight.on_yank()`
local highlight_group = vim.api.nvim_create_augroup("YankHighlight", { clear = true })
vim.api.nvim_create_autocmd("TextYankPost", {
group = highlight_group,
callback = function()
vim.highlight.on_yank()
end,
group = highlight_group,
callback = function()
vim.highlight.on_yank()
end,
})

-- auto trim trailing whitespace
local trim_whitespace_group = vim.api.nvim_create_augroup("trim_whitespace", { clear = true })
vim.api.nvim_create_autocmd("BufWritePost", {
group = trim_whitespace_group,
callback = function()
-- basically the same as mini.trailspace
local curpos = vim.api.nvim_win_get_cursor(0)
---Search and replace trailing whitespace
vim.cmd [[keeppatterns %s/\s\+$//e]]
vim.api.nvim_win_set_cursor(0, curpos)
end,
})

-- vim.api.nvim_set_hl(0, "LeapMatch", {
-- ---For light themes, set to 'black' or similar.
-- fg = vim.go.background == "dark" and "white" or "black",
-- bold = true,
-- nocombine = true,
-- })

-- temp
-- vim.lsp.set_log_level "debug" -- Sets the LSP log level to 'debug' for detailed logs

-- WSL clipboard
if vim.fn.has("wsl") == 1 then
g.clipboard = {
name = "WslClipboard",
copy = {
["+"] = "clip.exe",
["*"] = "clip.exe",
},
paste = {
["+"] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r",""))',
["*"] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r",""))',
},
cache_enabled = 0,
}
if vim.fn.has "wsl" == 1 then
g.clipboard = {
name = "WslClipboard",
copy = {
["+"] = "clip.exe",
["*"] = "clip.exe",
},
paste = {
["+"] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r",""))',
["*"] = 'powershell.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r",""))',
},
cache_enabled = 0,
}
end

-- Global funcs, utilities
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end

vim.api.nvim_create_user_command("RunGoTest", function()
local ts_locals = require("nvim-treesitter.locals")
local ts_utils = require("nvim-treesitter.ts_utils")
local cursor_node = ts_utils.get_node_at_cursor()
local scope = ts_locals.get_scope_tree(cursor_node, 0)
local get_node_text = vim.treesitter.get_node_text
local function_node, package_node
local function_node_types = {
function_declaration = true,
}
for _, v in ipairs(scope) do
if function_node_types[v:type()] then
function_node = v
end
if v:type() == "source_file" then
package_node = v
end
end
if not function_node then
print("Not in a function")
return
end
local package, function_name
local packageQuery = vim.treesitter.query.parse("go", "(source_file (package_clause (package_identifier) @id))")
local functionQuery = vim.treesitter.query.parse("go", "(function_declaration name: (_) @id)")
for _, node in functionQuery:iter_captures(function_node, 0) do
function_name = get_node_text(node, 0)
end
for _, node in packageQuery:iter_captures(package_node, 0) do
package = get_node_text(node, 0)
end
local go_mod_path = vim.fn.findfile("go.mod", ".;")
if go_mod_path == "" then
print("go.mod not found in the directory tree")
return
end
local go_mod_directory = vim.fn.fnamemodify(go_mod_path, ":h")
local cmd = "gotest -v -count=1 ./.../" .. package .. " -run " .. function_name
print(go_mod_directory)
local term_buf = nil
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.bo[buf].buftype == "terminal" then
local job_id = vim.b[buf].terminal_job_id
if vim.fn.jobwait({ job_id }, 0)[1] == -1 then -- Check if the job is still active
term_buf = buf
break
end
end
end
if term_buf then
vim.cmd("buffer " .. term_buf)
vim.cmd("startinsert")
vim.fn.chansend(vim.b[term_buf].terminal_job_id, cmd .. "\n")
else
vim.cmd("vsplit term://" .. cmd)
end
local ts_locals = require "nvim-treesitter.locals"
local ts_utils = require "nvim-treesitter.ts_utils"
local cursor_node = ts_utils.get_node_at_cursor()
local scope = ts_locals.get_scope_tree(cursor_node, 0)
local get_node_text = vim.treesitter.get_node_text
local function_node, package_node
local function_node_types = {
function_declaration = true,
}
for _, v in ipairs(scope) do
if function_node_types[v:type()] then
function_node = v
end
if v:type() == "source_file" then
package_node = v
end
end
if not function_node then
print "Not in a function"
return
end
local package, function_name
local packageQuery = vim.treesitter.query.parse("go", "(source_file (package_clause (package_identifier) @id))")
local functionQuery = vim.treesitter.query.parse("go", "(function_declaration name: (_) @id)")
for _, node in functionQuery:iter_captures(function_node, 0) do
function_name = get_node_text(node, 0)
end
for _, node in packageQuery:iter_captures(package_node, 0) do
package = get_node_text(node, 0)
end
local go_mod_path = vim.fn.findfile("go.mod", ".;")
if go_mod_path == "" then
print "go.mod not found in the directory tree"
return
end
local go_mod_directory = vim.fn.fnamemodify(go_mod_path, ":h")
local cmd = "gotest -v -count=1 ./.../" .. package .. " -run " .. function_name
print(go_mod_directory)
local term_buf = nil
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.bo[buf].buftype == "terminal" then
local job_id = vim.b[buf].terminal_job_id
if vim.fn.jobwait({ job_id }, 0)[1] == -1 then -- Check if the job is still active
term_buf = buf
break
end
end
end
if term_buf then
vim.cmd("buffer " .. term_buf)
vim.cmd "startinsert"
vim.fn.chansend(vim.b[term_buf].terminal_job_id, cmd .. "\n")
else
vim.cmd("vsplit term://" .. cmd)
end
end, { nargs = "*" })

_G.run_command = function()
local filetype = vim.bo.filetype
if filetype == "c" then
vim.cmd("!sh run.sh")
end
if filetype == "go" then
run_make_dev()
end
local filetype = vim.bo.filetype
if filetype == "c" then
vim.cmd "!sh run.sh"
end
if filetype == "go" then
run_make_dev()
end
end

-- specific to whatever you're working on atm
_G.run_make_dev = function()
-- Find the directory containing the Makefile
local makefile_path = vim.fn.findfile("Makefile", ".")
print("Rebuilding...")

-- Check if Makefile is found
if makefile_path ~= "" then
-- Change to the directory containing the Makefile
local makefile_dir = vim.fn.fnamemodify(makefile_path, ":h")
vim.cmd("cd " .. makefile_dir)

-- Kill previous process if running
vim.fn.system("pkill -f marketpal_server")

-- Run make dev
vim.fn.jobstart("make dev", { detach = true })
print("Dev is running.")
else
print("Makefile not found.")
end
-- Find the directory containing the Makefile
local makefile_path = vim.fn.findfile("Makefile", ".")
print "Rebuilding..."

-- Check if Makefile is found
if makefile_path ~= "" then
-- Change to the directory containing the Makefile
local makefile_dir = vim.fn.fnamemodify(makefile_path, ":h")
vim.cmd("cd " .. makefile_dir)

-- Kill previous process if running
vim.fn.system "pkill -f marketpal_server"

-- Run make dev
vim.fn.jobstart("make dev", { detach = true })
print "Dev is running."
else
print "Makefile not found."
end
end

vim.api.nvim_create_user_command("DiffviewToggle", function(e)
local view = require("diffview.lib").get_current_view()
local view = require("diffview.lib").get_current_view()

if view then
vim.cmd("DiffviewClose")
else
vim.cmd("DiffviewOpen " .. e.args)
end
if view then
vim.cmd "DiffviewClose"
else
vim.cmd("DiffviewOpen " .. e.args)
end
end, { nargs = "*" })

_G.snip_complete = function()
if fn.pumvisible() == 1 then
return t("<C-n>")
elseif require("luasnip").expand_or_jumpable() then
return t("<Plug>luasnip-expand-or-jump")
end
return ""
if fn.pumvisible() == 1 then
return t "<C-n>"
elseif require("luasnip").expand_or_jumpable() then
return t "<Plug>luasnip-expand-or-jump"
end
return ""
end

_G.r_snip_complete = function()
if fn.pumvisible() == 1 then
return t("<C-p>")
elseif require("luasnip").jumpable(-1) then
return t("<Plug>luasnip-jump-prev")
end
return ""
if fn.pumvisible() == 1 then
return t "<C-p>"
elseif require("luasnip").jumpable(-1) then
return t "<Plug>luasnip-jump-prev"
end
return ""
end

function _G.smart_tab()
return require("luasnip").expand_or_jumpable() and t("<Plug>luasnip-expand-or-jump") or t("<Tab>")
return require("luasnip").expand_or_jumpable() and t "<Plug>luasnip-expand-or-jump" or t "<Tab>"
end

vim.keymap.set({ "n", "x", "o" }, "s", function()
local current_window = vim.fn.win_getid()
require("leap").leap({ target_windows = { current_window } })
local current_window = vim.fn.win_getid()
require("leap").leap { target_windows = { current_window } }
end)
Loading

0 comments on commit 42a7188

Please sign in to comment.