Skip to content

Commit

Permalink
Add some AI cuz... bandwagon?
Browse files Browse the repository at this point in the history
  • Loading branch information
zmre committed Dec 2, 2024
1 parent 488d5c5 commit 0b94a92
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 14 deletions.
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
#lldb # for debugging rust
#vscode-extensions.vadimcn.vscode-lldb # for debugging rust
metals # lsp for scala
# imagemagick # for image-nvim plugin
]
++ pkgs.lib.optionals pkgs.stdenv.isLinux [
ueberzug
Expand Down Expand Up @@ -273,6 +274,7 @@
cmp-emoji # complete :emojis:
cmp-nvim-lsp-signature-help # help complete function call by showing args
cmp-npm # complete node packages in package.json
codecompanion-nvim
nvim-autopairs # balances parens as you type
nvim-ts-autotag # balance or rename html
vim-emoji # TODO: redundant now?
Expand Down Expand Up @@ -312,6 +314,8 @@
comment-nvim # code commenter
crates-nvim # inline intelligence for Cargo.toml
todo-comments-nvim # highlight comments like NOTE
render-markdown-nvim # prettier markdown files
# image-nvim
];

recursiveMerge = attrList: let
Expand Down Expand Up @@ -392,6 +396,7 @@
withNodeJs = false;
withPython3 = false;
withRuby = false;
extraLuaPackages = ps: [ps.lua-curl];
extraMakeWrapperArgs = ''--prefix PATH : "${pkgs.lib.makeBinPath dependencies}"'';
# make sure impatient is loaded before everything else to speed things up
configure = {
Expand Down
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ require('pwnvim.plugins').ui()
require('pwnvim.plugins').diagnostics()
require('pwnvim.plugins').telescope()
require('pwnvim.plugins').completions()
require('pwnvim.plugins').llms()
require('pwnvim.plugins').notes()
require('pwnvim.plugins').misc()
8 changes: 8 additions & 0 deletions pwnvim/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ M.config = function()
{ "<leader>lc", group = "change" },
{ "<leader>n", group = "notes" },
{ "<leader>t", group = "tasks" },
{ "<leader>cc", group = "codecompanion ai" },
})

-- This file is for mappings that will work regardless of filetype. Always available.
Expand Down Expand Up @@ -399,6 +400,13 @@ M.config = function()
M.mapleadernv("gwn", require('telescope').extensions.git_worktree.create_git_worktree, "New worktree")
-- Bunch more will be mapped locally with gitsigns when it loads. See ./gitsigns.lua

-- Codecompanion bindings
M.mapleadernv("ccl", "CodeCompanion", "AI Inline")
M.mapi("<C-a>", "CodeCompanion", "AI Inline")
M.mapleadernv("ccc", "CodeCompanionChat Toggle", "AI Chat")
M.mapleadernv("cca", "CodeCompanionActions", "AI Actions")
M.mapleadernv("cce", function() require("codecompanion").prompt("explain") end, "AI Explain")
M.mapv("ga", "CodeCompanionChat Add", "AI add code block")

-- Set cwd to current file's dir
M.mapleadernv("lcd", "lcd %:h", "Change local dir to path of current file")
Expand Down
55 changes: 54 additions & 1 deletion pwnvim/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,53 @@ M.setup = function(ev)
-- vim.api.nvim_buf_add_user_command(0, 'PasteUrl', function(opts) require('pwnvim.markdown').pasteUrl() end, {})
vim.cmd("command! PasteUrl lua require('pwnvim.markdown').pasteUrl()")

vim.cmd('packadd render-markdown.nvim')
require('render-markdown').setup({
file_types = { 'markdown', "codecompanion" }
})
require('render-markdown').enable()

-- Image plugin still slow and buggy 2024-12-01
-- if os.getenv("TERM") == "wezterm" or os.getenv("TERM") == "kitty" then
-- vim.cmd('packadd image.nvim')
-- require("image").setup({
-- backend = "kitty",
-- processor = "magick_rock", -- or "magick_cli"
-- integrations = {
-- markdown = {
-- enabled = true,
-- clear_in_insert_mode = false,
-- download_remote_images = true,
-- only_render_image_at_cursor = false,
-- filetypes = { "markdown", "vimwiki" }, -- markdown extensions (ie. quarto) can go here
-- },
-- neorg = {
-- enabled = true,
-- filetypes = { "norg" },
-- },
-- typst = {
-- enabled = true,
-- filetypes = { "typst" },
-- },
-- html = {
-- enabled = false,
-- },
-- css = {
-- enabled = false,
-- },
-- },
-- max_width = nil,
-- max_height = nil,
-- max_width_window_percentage = nil,
-- max_height_window_percentage = 50,
-- window_overlap_clear_enabled = false, -- toggles images when windows are overlapped
-- window_overlap_clear_ft_ignore = { "cmp_menu", "cmp_docs", "" },
-- editor_only_render_when_focused = false, -- auto show/hide images when the editor gains/looses focus
-- tmux_show_only_in_active_window = false, -- auto show/hide images in the correct Tmux window (needs visual-activity off)
-- hijack_file_patterns = { "*.png", "*.jpg", "*.jpeg", "*.gif", "*.webp", "*.avif" }, -- render image files as images when opened
-- })
-- end

-- Hologram displays image thumbnails in-terminal while editing markdown in vim
-- This is wonderful when it's working, but I sometimes get too many open files errors that seem to come from this plugin. Plus
-- some weirdness where my entire terminal (kitty) completely hangs for a time. Especially when typing in an alt description.
Expand Down Expand Up @@ -77,7 +124,13 @@ M.setup = function(ev)

vim.cmd('packadd todo-comments.nvim')
require("pwnvim.plugins.todo-comments") -- show todo's in markdown, too
require("todo-comments.config").options.highlight.comments_only = false
if require("todo-comments.config").options["highlight"] ~= nil then
require("todo-comments.config").options.highlight.comments_only = false
else
require("todo-comments.config").options["highlight"] = {
comments_only = false
}
end

local autocmd = vim.api.nvim_create_autocmd
local mdsave = vim.api.nvim_create_augroup("mdsave", { clear = true })
Expand Down
64 changes: 63 additions & 1 deletion pwnvim/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ M.ui = function()
autopush = false
})



if not SimpleUI then
require("colorizer").setup({})
require("dressing").setup({
Expand Down Expand Up @@ -146,6 +148,7 @@ M.ui = function()
})
end -- UI setup


----------------------- DIAGNOSTICS --------------------------------
M.diagnostics = function()
-- IMPORTANT: make sure to setup neodev BEFORE lspconfig
Expand Down Expand Up @@ -664,6 +667,63 @@ M.diagnostics = function()
})
end -- Diagnostics setup

M.llms = function()
local isOllamaRunning = require("plenary.curl").get("http://localhost:11434", {
timeout = 50,
on_error = function(e) return { status = e.exit } end,
}).status == 200

if isOllamaRunning then
vim.g.codecompanion_adapter = "ollama"
else
vim.g.codecompanion_adapter = "copilot"
end

require("codecompanion").setup({
display = {
chat = {
render_headers = false,
show_settings = true
}
},
adapters = {
ollama = function()
return require("codecompanion.adapters").extend("ollama", {
env = {
url = "http://127.0.0.1:11434",
},
schema = {
model = {
default = "qwen2.5-coder:32b",
},
},
headers = {
["Content-Type"] = "application/json",
},
parameters = {
sync = true,
},
})
end,
opts = {
allow_insecure = true, -- Allow insecure connections?
},
},
strategies = {
chat = {
adapter = (isOllamaRunning and "ollama" or "copilot"),
},
inline = {
adapter = (isOllamaRunning and "ollama" or "copilot"),
},
agent = {
adapter = (isOllamaRunning and "ollama" or "copilot"),
},
},
})
vim.cmd([[cab cc CodeCompanion]])
end

----------------------- TELESCOPE --------------------------------
M.telescope = function()
local actions = require("telescope.actions")
Expand Down Expand Up @@ -781,6 +841,7 @@ M.telescope = function()
end
end -- telescope


----------------------- COMPLETIONS --------------------------------
-- cmp, luasnip
M.completions = function()
Expand Down Expand Up @@ -860,7 +921,8 @@ M.completions = function()
nvim_lsp_signature_help = "[LSPS]",
-- luasnip = "[Snippet]",
buffer = "[Buffer]",
path = "[Path]"
path = "[Path]",
Copilot = "[Copilot]",
})[entry.source.name]
return vim_item
end
Expand Down
6 changes: 3 additions & 3 deletions pwnvim/signs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ M.hint = SimpleUI and "" or ""
M.info = SimpleUI and "" or ""
M.signs = {
{ name = "DiagnosticSignError", text = M.error },
{ name = "DiagnosticSignWarn", text = M.warn },
{ name = "DiagnosticSignHint", text = M.hint },
{ name = "DiagnosticSignInfo", text = M.info }
{ name = "DiagnosticSignWarn", text = M.warn },
{ name = "DiagnosticSignHint", text = M.hint },
{ name = "DiagnosticSignInfo", text = M.info }
}
if SimpleUI then
M.kind_icons = {
Expand Down

0 comments on commit 0b94a92

Please sign in to comment.