this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

nvim: vibecoded a claude integration

+332 -14
+3
nvim/init.lua
··· 9 9 10 10 -- Uses which-key plugin 11 11 require("config.keys") 12 + 13 + -- Claude integration 14 + require("config.claude").setup()
+13 -13
nvim/lazy-lock.json
··· 1 1 { 2 - "aerial.nvim": { "branch": "master", "commit": "5c0df1679bf7c814c924dc6646cc5291daca8363" }, 3 - "auto-dark-mode.nvim": { "branch": "master", "commit": "97a86c9402c784a254e5465ca2c51481eea310e3" }, 2 + "aerial.nvim": { "branch": "master", "commit": "62a5a3149b66444a245c052e431c30568ae173e3" }, 3 + "auto-dark-mode.nvim": { "branch": "master", "commit": "e300259ec777a40b4b9e3c8e6ade203e78d15881" }, 4 4 "bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" }, 5 - "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, 6 - "copilot.vim": { "branch": "release", "commit": "3955014c503b0cd7b30bc56c86c56c0736ca0951" }, 5 + "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, 6 + "copilot.vim": { "branch": "release", "commit": "f3d66c148aa60ad04c0a21d3e0a776459de09eb2" }, 7 7 "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, 8 8 "dressing.nvim": { "branch": "master", "commit": "2d7c2db2507fa3c4956142ee607431ddb2828639" }, 9 - "dropbar.nvim": { "branch": "master", "commit": "64f5540824ab350f02dabc1276f4a1f4f141276b" }, 9 + "dropbar.nvim": { "branch": "master", "commit": "596f95e98a21e8fccf3db91fec481129eb82ff61" }, 10 10 "gitlab.nvim": { "branch": "main", "commit": "e29909cd1064a7b53c3150bff49449a548dadf8d" }, 11 11 "gitlinker.nvim": { "branch": "master", "commit": "cc59f732f3d043b626c8702cb725c82e54d35c25" }, 12 - "gitsigns.nvim": { "branch": "main", "commit": "6e3ee68bc9f65b21a21582a3d80e270c7e4f2992" }, 12 + "gitsigns.nvim": { "branch": "main", "commit": "6e3c66548035e50db7bd8e360a29aec6620c3641" }, 13 13 "goyo.vim": { "branch": "master", "commit": "fa0263d456dd43f5926484d1c4c7022dfcb21ba9" }, 14 14 "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, 15 15 "lazydev.nvim": { "branch": "main", "commit": "2367a6c0a01eb9edb0464731cc0fb61ed9ab9d2c" }, 16 - "mason-lspconfig.nvim": { "branch": "main", "commit": "73e0143385d8a2185944b42ed44d728b94ee19a3" }, 17 - "mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" }, 16 + "mason-lspconfig.nvim": { "branch": "main", "commit": "1ec4da522fa49dcecee8d190efda273464dd2192" }, 17 + "mason.nvim": { "branch": "main", "commit": "7dc4facca9702f95353d5a1f87daf23d78e31c2a" }, 18 18 "neo-tree.nvim": { "branch": "v3.x", "commit": "cea666ef965884414b1b71f6b39a537f9238bdb2" }, 19 19 "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, 20 20 "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, 21 21 "nvim-comment": { "branch": "main", "commit": "e9ac16ab056695cad6461173693069ec070d2b23" }, 22 22 "nvim-config-local": { "branch": "main", "commit": "990f3e35e0fba8fb83012d7e85f9a6a77de7f87f" }, 23 23 "nvim-lsp-file-operations": { "branch": "master", "commit": "9744b738183a5adca0f916527922078a965515ed" }, 24 - "nvim-lspconfig": { "branch": "master", "commit": "d8f03bfd5b54b10352276a0ed1f2ffe9c2e0676f" }, 24 + "nvim-lspconfig": { "branch": "master", "commit": "e844850b3143a1627437f811549fc7d70cfedf05" }, 25 25 "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, 26 - "nvim-web-devicons": { "branch": "master", "commit": "19d6211c78169e78bab372b585b6fb17ad974e82" }, 27 - "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, 28 - "rose-pine": { "branch": "main", "commit": "f93360149e9ed4df8677fbb07c7231ea0fd03b97" }, 29 - "schemastore.nvim": { "branch": "main", "commit": "1ec3867f463dfe4ca37001348953d810c716d4d9" }, 26 + "nvim-web-devicons": { "branch": "master", "commit": "81b37d7937953b50e5fd8d9d7dfe2c6d0088fde1" }, 27 + "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, 28 + "rose-pine": { "branch": "main", "commit": "72a04c4065345b51b56aed4859ea1d884f734097" }, 29 + "schemastore.nvim": { "branch": "main", "commit": "433a310de5cbab41f1eb3424332a583e21e39f5c" }, 30 30 "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, 31 31 "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, 32 32 "toggleterm.nvim": { "branch": "main", "commit": "9a88eae817ef395952e08650b3283726786fb5fb" },
+148
nvim/lua/config/claude.lua
··· 1 + local helpers = require('utils.claude_helpers') 2 + local diagnostic_helpers = require('utils.diagnostic_helpers') 3 + 4 + local M = {} 5 + 6 + -- Display Claude response in new buffer 7 + local function show_claude_response(response) 8 + -- Create new buffer and switch to it 9 + vim.cmd('vnew') 10 + local buf = vim.api.nvim_get_current_buf() 11 + 12 + -- Set buffer content 13 + vim.api.nvim_buf_set_lines(buf, 0, -1, false, vim.split(response, '\n')) 14 + 15 + -- Set buffer options 16 + vim.bo[buf].modifiable = false 17 + vim.bo[buf].filetype = 'markdown' 18 + vim.bo[buf].buftype = '' -- Make it a normal buffer 19 + vim.bo[buf].bufhidden = 'hide' -- Hide instead of wipe 20 + 21 + -- Set buffer name 22 + vim.api.nvim_buf_set_name(buf, 'Claude Response') 23 + end 24 + 25 + -- Main Claude command handler 26 + local function claude_command(opts) 27 + if not helpers.claude_available() then 28 + vim.notify("Claude binary not found. Please install claude-code CLI.", vim.log.levels.ERROR) 29 + return 30 + end 31 + 32 + local user_input = table.concat(opts.fargs, ' ') 33 + if user_input == '' then 34 + vim.notify("Please provide a request for Claude", vim.log.levels.WARN) 35 + return 36 + end 37 + 38 + local file_context = helpers.get_file_context() 39 + local selection = helpers.get_selection_info(opts.range > 0, opts.line1, opts.line2) 40 + local prompt = helpers.build_prompt(user_input, file_context, selection, false, nil) 41 + 42 + vim.notify("Asking Claude...", vim.log.levels.INFO) 43 + 44 + helpers.execute_claude(prompt, function(response) 45 + vim.schedule(function() 46 + show_claude_response(response) 47 + end) 48 + end) 49 + end 50 + 51 + -- Claude edit command handler 52 + local function claude_edit_command(opts) 53 + if not helpers.claude_available() then 54 + vim.notify("Claude binary not found. Please install claude-code CLI.", vim.log.levels.ERROR) 55 + return 56 + end 57 + 58 + local user_input = table.concat(opts.fargs, ' ') 59 + if user_input == '' then 60 + vim.notify("Please provide a request for Claude", vim.log.levels.WARN) 61 + return 62 + end 63 + 64 + local file_context = helpers.get_file_context() 65 + local selection = helpers.get_selection_info(opts.range > 0, opts.line1, opts.line2) 66 + 67 + if not selection then 68 + vim.notify("ClaudeEdit requires a selection. Select text first or use a range.", vim.log.levels.WARN) 69 + return 70 + end 71 + 72 + local prompt = helpers.build_prompt(user_input, file_context, selection, true, nil) 73 + 74 + vim.notify("Claude is editing your selection...", vim.log.levels.INFO) 75 + 76 + helpers.execute_claude(prompt, function(response) 77 + vim.schedule(function() 78 + helpers.replace_selection(selection, response) 79 + vim.notify("Selection replaced by Claude", vim.log.levels.INFO) 80 + end) 81 + end) 82 + end 83 + 84 + -- Claude fix diagnostics command handler 85 + local function claude_fix_command(opts) 86 + if not helpers.claude_available() then 87 + vim.notify("Claude binary not found. Please install claude-code CLI.", vim.log.levels.ERROR) 88 + return 89 + end 90 + 91 + local file_context = helpers.get_file_context() 92 + local selection = helpers.get_selection_info(opts.range > 0, opts.line1, opts.line2) 93 + 94 + if not selection then 95 + vim.notify("ClaudeFix requires a selection. Select text first or use a range.", vim.log.levels.WARN) 96 + return 97 + end 98 + 99 + -- Get diagnostics for the selected range 100 + local diagnostics = diagnostic_helpers.get_range_diagnostics(0, selection.start_line, selection.end_line) 101 + 102 + if not diagnostic_helpers.has_diagnostics(0, selection.start_line, selection.end_line) then 103 + vim.notify("No diagnostic issues found in selected range.", vim.log.levels.INFO) 104 + return 105 + end 106 + 107 + local diagnostic_info = diagnostic_helpers.format_diagnostics_for_prompt(diagnostics) 108 + local user_input = table.concat(opts.fargs, ' ') 109 + if user_input == '' then 110 + user_input = "Fix the diagnostic issues listed above" 111 + end 112 + 113 + local prompt = helpers.build_prompt(user_input, file_context, selection, false, diagnostic_info) 114 + 115 + vim.notify("Claude is analyzing and fixing diagnostic issues...", vim.log.levels.INFO) 116 + 117 + helpers.execute_claude_with_tools(prompt, function(response) 118 + vim.schedule(function() 119 + vim.notify("Claude diagnostic fix completed. Check the file for changes.", vim.log.levels.INFO) 120 + end) 121 + end) 122 + end 123 + 124 + -- Setup function to register commands 125 + function M.setup() 126 + -- Register :Claude command 127 + vim.api.nvim_create_user_command('Claude', claude_command, { 128 + nargs = '*', 129 + range = true, 130 + desc = 'Ask Claude for help with code context' 131 + }) 132 + 133 + -- Register :ClaudeEdit command 134 + vim.api.nvim_create_user_command('ClaudeEdit', claude_edit_command, { 135 + nargs = '*', 136 + range = true, 137 + desc = 'Ask Claude to edit selected code' 138 + }) 139 + 140 + -- Register :ClaudeFix command 141 + vim.api.nvim_create_user_command('ClaudeFix', claude_fix_command, { 142 + nargs = '*', 143 + range = true, 144 + desc = 'Ask Claude to fix diagnostic issues in selected code' 145 + }) 146 + end 147 + 148 + return M
+6 -1
nvim/lua/config/keys.lua
··· 151 151 silent = true, 152 152 }, 153 153 154 - { "<leader>PP", "<cmd>Lazy<cr>", desc = "Manage plugins", group = "plugin" }, 154 + { "<leader>PP", "<cmd>Lazy<cr>", desc = "Manage plugins", group = "plugin" }, 155 + 156 + -- Claude integration 157 + { "<leader>cc", ":Claude ", desc = "Ask Claude", group = "claude" }, 158 + { "<leader>ce", ":ClaudeEdit ", desc = "Claude edit selection", mode = { "n", "v" }, group = "claude" }, 159 + { "<leader>cf", ":ClaudeFix", desc = "Claude fix diagnostics", mode = { "n", "v" }, group = "claude" }, 155 160 })
+110
nvim/lua/utils/claude_helpers.lua
··· 1 + local M = {} 2 + 3 + -- Get current file context 4 + function M.get_file_context() 5 + return { 6 + filepath = vim.fn.expand('%:p'), 7 + filename = vim.fn.expand('%:t'), 8 + filetype = vim.bo.filetype, 9 + line_count = vim.api.nvim_buf_line_count(0) 10 + } 11 + end 12 + 13 + -- Detect and extract visual selection 14 + function M.get_selection_info(range_given, line1, line2) 15 + local selection = nil 16 + if range_given then 17 + -- Command called with range 18 + selection = { 19 + start_line = line1, 20 + end_line = line2, 21 + text = table.concat(vim.api.nvim_buf_get_lines(0, line1 - 1, line2, false), '\n') 22 + } 23 + elseif vim.fn.mode() == 'v' or vim.fn.mode() == 'V' then 24 + -- Visual mode selection 25 + local start_pos = vim.fn.getpos("'<") 26 + local end_pos = vim.fn.getpos("'>") 27 + selection = { 28 + start_line = start_pos[2], 29 + end_line = end_pos[2], 30 + text = table.concat(vim.api.nvim_buf_get_lines(0, start_pos[2] - 1, end_pos[2], false), '\n') 31 + } 32 + end 33 + return selection 34 + end 35 + 36 + -- Build prompt with context 37 + function M.build_prompt(user_input, file_context, selection, is_edit_mode, diagnostic_info) 38 + local prompt_parts = {} 39 + 40 + -- Diagnostic fix mode instruction 41 + if diagnostic_info then 42 + table.insert(prompt_parts, 43 + "DIAGNOSTIC FIX MODE: Use your Edit tool to fix the following diagnostic issues in the code. Make precise fixes to resolve the specific problems listed.") 44 + table.insert(prompt_parts, diagnostic_info) 45 + elseif is_edit_mode then 46 + -- Edit mode instruction 47 + table.insert(prompt_parts, 48 + "EDIT MODE: Return ONLY the modified code with no explanations, markdown formatting, or additional text. Any explanations should be included as code comments within the code itself. Do not surround the code with backticks.") 49 + end 50 + 51 + -- File context 52 + table.insert(prompt_parts, string.format("File: %s (%s)", file_context.filename, file_context.filetype)) 53 + 54 + -- Selection context if present 55 + if selection then 56 + table.insert(prompt_parts, string.format("Selected lines %d-%d:", selection.start_line, selection.end_line)) 57 + table.insert(prompt_parts, "```" .. file_context.filetype) 58 + table.insert(prompt_parts, selection.text) 59 + table.insert(prompt_parts, "```") 60 + end 61 + 62 + -- User request 63 + table.insert(prompt_parts, "Request: " .. user_input) 64 + 65 + return table.concat(prompt_parts, '\n\n') 66 + end 67 + 68 + -- Execute claude command 69 + function M.execute_claude(prompt, callback) 70 + -- Alternative 1: Use vim.system (Neovim 0.10+) - cleaner, no shell escaping needed 71 + vim.system({ 'claude', '-p', prompt }, { 72 + text = true 73 + }, function(result) 74 + vim.schedule(function() 75 + if result.code == 0 then 76 + if callback then callback(result.stdout) end 77 + else 78 + vim.notify("Claude error: " .. (result.stderr or "Unknown error"), vim.log.levels.ERROR) 79 + end 80 + end) 81 + end) 82 + end 83 + 84 + -- Execute claude command with tool permissions for diagnostic fixing 85 + function M.execute_claude_with_tools(prompt, callback) 86 + vim.system({ 'claude', '--allowedTools=Edit,Read', '-p', prompt }, { 87 + text = true 88 + }, function(result) 89 + vim.schedule(function() 90 + if result.code == 0 then 91 + if callback then callback(result.stdout) end 92 + else 93 + vim.notify("Claude error: " .. (result.stderr or "Unknown error"), vim.log.levels.ERROR) 94 + end 95 + end) 96 + end) 97 + end 98 + 99 + -- Replace selection with new content 100 + function M.replace_selection(selection, new_content) 101 + local lines = vim.split(new_content, '\n') 102 + vim.api.nvim_buf_set_lines(0, selection.start_line - 1, selection.end_line, false, lines) 103 + end 104 + 105 + -- Check if claude binary exists 106 + function M.claude_available() 107 + return vim.fn.executable('claude') == 1 108 + end 109 + 110 + return M
+52
nvim/lua/utils/diagnostic_helpers.lua
··· 1 + local M = {} 2 + 3 + -- Get diagnostics for a specific line range 4 + function M.get_range_diagnostics(bufnr, start_line, end_line) 5 + local all_diagnostics = vim.diagnostic.get(bufnr or 0) 6 + local range_diagnostics = {} 7 + 8 + for _, diagnostic in ipairs(all_diagnostics) do 9 + -- Convert from 0-indexed to 1-indexed for user-facing line numbers 10 + local diag_line = diagnostic.lnum + 1 11 + if diag_line >= start_line and diag_line <= end_line then 12 + table.insert(range_diagnostics, diagnostic) 13 + end 14 + end 15 + 16 + return range_diagnostics 17 + end 18 + 19 + -- Format diagnostics for Claude prompt 20 + function M.format_diagnostics_for_prompt(diagnostics) 21 + if #diagnostics == 0 then 22 + return "No diagnostics found in the selected range." 23 + end 24 + 25 + local severity_names = { 26 + [vim.diagnostic.severity.ERROR] = "ERROR", 27 + [vim.diagnostic.severity.WARN] = "WARNING", 28 + [vim.diagnostic.severity.INFO] = "INFO", 29 + [vim.diagnostic.severity.HINT] = "HINT" 30 + } 31 + 32 + local formatted_lines = {} 33 + table.insert(formatted_lines, "Diagnostic Issues:") 34 + 35 + for _, diagnostic in ipairs(diagnostics) do 36 + local line_num = diagnostic.lnum + 1 -- Convert to 1-indexed 37 + local severity = severity_names[diagnostic.severity] or "UNKNOWN" 38 + local message = diagnostic.message:gsub("\n", " ") -- Remove newlines from message 39 + 40 + table.insert(formatted_lines, string.format("Line %d: [%s] %s", line_num, severity, message)) 41 + end 42 + 43 + return table.concat(formatted_lines, "\n") 44 + end 45 + 46 + -- Quick check if any diagnostics exist in range 47 + function M.has_diagnostics(bufnr, start_line, end_line) 48 + local diagnostics = M.get_range_diagnostics(bufnr, start_line, end_line) 49 + return #diagnostics > 0 50 + end 51 + 52 + return M