this repo has no description
0
fork

Configure Feed

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

nvim: cleanup

-162
-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