1
0

fixes and improvements from work setup

This commit is contained in:
2026-04-09 09:38:33 +02:00
parent 2afffb0488
commit 214efb0e8a
5 changed files with 158 additions and 36 deletions

View File

@@ -8,47 +8,52 @@ vim.pack.add({
})
local codecompanion = require("codecompanion")
-- Dynamically choose the adapter based on the environment variable
local active_adapter = os.getenv("GEMINI_API_KEY") and "gemini" or "kiro"
local has_gemini = os.getenv("GEMINI_API_KEY")
codecompanion.setup({
strategies = {
chat = { adapter = active_adapter },
inline = { adapter = active_adapter },
agent = { adapter = active_adapter },
interactions = {
chat = {
adapter = has_gemini and "gemini" or "kiro",
tools = {
["web_search"] = {
opts = { require_approval_before = false },
},
["fetch_webpage"] = {
opts = { require_approval_before = false },
},
},
},
inline = { adapter = has_gemini and "gemini" or nil },
},
adapters = {
gemini = function()
return require("codecompanion.adapters").extend("gemini", {
env = {
-- We read the API key from the environment variable.
-- You can also use "cmd:pass show gemini/api_key" or "cmd:cat ~/.gemini_api_key"
api_key = os.getenv("GEMINI_API_KEY") or "cmd:cat ~/.gemini_api_key",
},
schema = {
model = {
default = "gemini-3.1-pro-preview",
http = {
gemini = function()
return require("codecompanion.adapters").extend("gemini", {
env = {
api_key = os.getenv("GEMINI_API_KEY") or "cmd:cat ~/.gemini_api_key",
},
},
})
end,
-- If 'kiro' is a custom CLI or local LLM, you must define it here.
-- This is a generic custom adapter stub for CodeCompanion:
kiro = function()
return require("codecompanion.adapters").extend("openai_compatible", {
name = "kiro",
env = {
url = "http://localhost:11434", -- Example endpoint
-- api_key = "...",
},
})
end,
schema = {
model = {
default = "gemini-3.1-pro-preview",
},
},
})
end,
},
acp = {
kiro = function()
return require("codecompanion.adapters").extend("kiro", {
defaults = {
model = "kiro_default",
},
})
end,
},
},
})
-- Optional: Keymaps for CodeCompanion
vim.keymap.set({ "n", "v" }, "<leader>a", "<cmd>CodeCompanionChat Toggle<cr>", { noremap = true, silent = true })
vim.keymap.set({ "n", "v" }, "<leader>a", "<cmd>CodeCompanionChat Toggle<cr>", { noremap = true, silent = true })
-- Inline prompt for buffer modifications (Generates diffs)
vim.keymap.set({ "n", "v" }, "<leader>ci", "<cmd>CodeCompanion <cr>", { noremap = true, silent = true })
-- Add visual selection to chat
@@ -65,6 +70,7 @@ blink.setup({
completion = {
menu = { border = "rounded" },
documentation = { auto_show = true, window = { border = "rounded" } },
ghost_text = { enabled = true }, -- Enables ghost text in insert mode
},
cmdline = {
@@ -92,6 +98,8 @@ blink.setup({
name = "CodeCompanion",
module = "codecompanion.providers.completion.blink",
enabled = true,
score_offset = 100, -- Boosts priority so AI suggestions appear first in ghost text
async = true, -- Ensures AI fetching doesn't block the UI
},
},
},

View File

@@ -45,12 +45,42 @@ local function get_project_root()
return tf_root or nvim_root or git_root or lang_root or vim.fn.getcwd()
end
local function get_submodule_excludes()
local git_root = vim.fs.root(0, ".git")
if not git_root then
return {}
end
local handle =
io.popen("git -C " .. vim.fn.shellescape(git_root) .. " submodule --quiet foreach 'echo $sm_path' 2>/dev/null")
if not handle then
return {}
end
local excludes = {}
for line in handle:lines() do
table.insert(excludes, line)
end
handle:close()
return excludes
end
vim.keymap.set("n", "<leader>pf", function()
require("fzf-lua").files({ cwd = get_project_root() })
local fzf = require("fzf-lua")
local defaults = fzf.defaults.files
local fd_opts = defaults.fd_opts
for _, sub in ipairs(get_submodule_excludes()) do
fd_opts = fd_opts .. " --exclude " .. sub
end
fzf.files({ cwd = get_project_root(), fd_opts = fd_opts })
end, { desc = "Fuzzy find project files" })
vim.keymap.set("n", "<leader>ps", function()
require("fzf-lua").live_grep({ cwd = get_project_root() })
local fzf = require("fzf-lua")
local defaults = fzf.defaults.grep
local rg_opts = defaults.rg_opts
for _, sub in ipairs(get_submodule_excludes()) do
rg_opts = rg_opts .. " -g '!" .. sub .. "'"
end
fzf.live_grep({ cwd = get_project_root(), rg_opts = rg_opts })
end, { desc = "Live grep project text" })
vim.keymap.set("n", "<leader><space>", function()
@@ -58,7 +88,12 @@ vim.keymap.set("n", "<leader><space>", function()
end, { desc = "Fuzzy find open files" })
vim.keymap.set("n", "<leader>gf", function()
require("fzf-lua").git_files()
local excludes = get_submodule_excludes()
local pathspecs = {}
for _, sub in ipairs(excludes) do
table.insert(pathspecs, ":(exclude)" .. sub)
end
require("fzf-lua").git_files({ cmd = "git ls-files --exclude-standard -- . " .. table.concat(pathspecs, " ") })
end, { desc = "Fuzzy find tracked Git files" })
vim.api.nvim_create_autocmd("BufEnter", {

View File

@@ -19,6 +19,12 @@ require("nvim-treesitter").install({
"yaml",
})
vim.api.nvim_create_autocmd("FileType", {
callback = function()
pcall(vim.treesitter.start)
end,
})
-- Default to treesitter folding
vim.opt.foldexpr = "v:lua.vim.treesitter.foldexpr()"
vim.opt.foldmethod = "expr"