feat: initial release of codetyper.nvim v0.2.0

AI-powered coding partner for Neovim with LLM integration.

Features:
- Split view for coder files (*.coder.*) and target files
- Tag-based prompts with /@ and @/ syntax
- Claude API and Ollama (local) LLM support
- Smart prompt detection (refactor, add, document, explain)
- Automatic code injection into target files
- Project tree logging (.coder/tree.log)
- Auto .gitignore management

Ask Panel (chat interface):
- Fixed at 1/4 screen width
- File attachment with @ key
- Ctrl+n for new chat
- Ctrl+Enter to submit
- Proper window close behavior
- Navigation with Ctrl+h/j/k/l

Commands: Coder, CoderOpen, CoderClose, CoderToggle,
CoderProcess, CoderAsk, CoderTree, CoderTreeView
This commit is contained in:
2026-01-11 15:24:06 -05:00
commit bba0647b47
29 changed files with 5503 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
---@mod codetyper.prompts.ask Ask/explanation prompts for Codetyper.nvim
---
--- These prompts are used for the Ask panel and code explanations.
local M = {}
--- Prompt for explaining code
M.explain_code = [[Please explain the following code:
{{code}}
Provide:
1. A high-level overview of what it does
2. Explanation of key parts
3. Any potential issues or improvements
]]
--- Prompt for explaining a specific function
M.explain_function = [[Explain this function in detail:
{{code}}
Include:
1. What the function does
2. Parameters and their purposes
3. Return value
4. Any side effects
5. Usage examples
]]
--- Prompt for explaining an error
M.explain_error = [[I'm getting this error:
{{error}}
In this code:
{{code}}
Please explain:
1. What the error means
2. Why it's happening
3. How to fix it
]]
--- Prompt for code review
M.code_review = [[Please review this code:
{{code}}
Provide feedback on:
1. Code quality and readability
2. Potential bugs or issues
3. Performance considerations
4. Security concerns (if applicable)
5. Suggested improvements
]]
--- Prompt for explaining a concept
M.explain_concept = [[Explain the following programming concept:
{{concept}}
Include:
1. Definition and purpose
2. When and why to use it
3. Simple code examples
4. Common pitfalls to avoid
]]
--- Prompt for comparing approaches
M.compare_approaches = [[Compare these different approaches:
{{approaches}}
Analyze:
1. Pros and cons of each
2. Performance implications
3. Maintainability
4. When to use each approach
]]
--- Prompt for debugging help
M.debug_help = [[Help me debug this issue:
Problem: {{problem}}
Code:
{{code}}
What I've tried:
{{attempts}}
Please help identify the issue and suggest a solution.
]]
--- Prompt for architecture advice
M.architecture_advice = [[I need advice on this architecture decision:
{{question}}
Context:
{{context}}
Please provide:
1. Recommended approach
2. Reasoning
3. Potential alternatives
4. Things to consider
]]
--- Generic ask prompt
M.generic = [[USER QUESTION: {{question}}
{{#if files}}
ATTACHED FILE CONTENTS:
{{files}}
{{/if}}
{{#if context}}
ADDITIONAL CONTEXT:
{{context}}
{{/if}}
Please provide a helpful, accurate response.
]]
return M

View File

@@ -0,0 +1,93 @@
---@mod codetyper.prompts.code Code generation prompts for Codetyper.nvim
---
--- These prompts are used for generating new code.
local M = {}
--- Prompt template for creating a new function
M.create_function = [[Create a function with the following requirements:
{{description}}
Requirements:
- Follow the coding style of the existing file
- Include proper error handling
- Use appropriate types (if applicable)
- Make it efficient and readable
]]
--- Prompt template for creating a new class/module
M.create_class = [[Create a class/module with the following requirements:
{{description}}
Requirements:
- Follow OOP best practices
- Include constructor/initialization
- Implement proper encapsulation
- Add necessary methods as described
]]
--- Prompt template for implementing an interface/trait
M.implement_interface = [[Implement the following interface/trait:
{{description}}
Requirements:
- Implement all required methods
- Follow the interface contract exactly
- Handle edge cases appropriately
]]
--- Prompt template for creating a React component
M.create_react_component = [[Create a React component with the following requirements:
{{description}}
Requirements:
- Use functional components with hooks
- Include proper TypeScript types (if .tsx)
- Follow React best practices
- Make it reusable and composable
]]
--- Prompt template for creating an API endpoint
M.create_api_endpoint = [[Create an API endpoint with the following requirements:
{{description}}
Requirements:
- Include input validation
- Proper error handling and status codes
- Follow RESTful conventions
- Include appropriate middleware
]]
--- Prompt template for creating a utility function
M.create_utility = [[Create a utility function:
{{description}}
Requirements:
- Pure function (no side effects) if possible
- Handle edge cases
- Efficient implementation
- Well-typed (if applicable)
]]
--- Prompt template for generic code generation
M.generic = [[Generate code based on the following description:
{{description}}
Context:
- Language: {{language}}
- File: {{filepath}}
Requirements:
- Match existing code style
- Follow best practices
- Handle errors appropriately
]]
return M

View File

@@ -0,0 +1,136 @@
---@mod codetyper.prompts.document Documentation prompts for Codetyper.nvim
---
--- These prompts are used for generating documentation.
local M = {}
--- Prompt for adding JSDoc comments
M.jsdoc = [[Add JSDoc documentation to this code:
{{code}}
Requirements:
- Document all functions and methods
- Include @param for all parameters
- Include @returns for return values
- Add @throws if exceptions are thrown
- Include @example where helpful
- Use @typedef for complex types
]]
--- Prompt for adding Python docstrings
M.python_docstring = [[Add docstrings to this Python code:
{{code}}
Requirements:
- Use Google-style docstrings
- Document all functions and classes
- Include Args, Returns, Raises sections
- Add Examples where helpful
- Include type hints in docstrings
]]
--- Prompt for adding LuaDoc comments
M.luadoc = [[Add LuaDoc/EmmyLua annotations to this Lua code:
{{code}}
Requirements:
- Use ---@param for parameters
- Use ---@return for return values
- Use ---@class for table structures
- Use ---@field for class fields
- Add descriptions for all items
]]
--- Prompt for adding Go documentation
M.godoc = [[Add GoDoc comments to this Go code:
{{code}}
Requirements:
- Start comments with the name being documented
- Document all exported functions, types, and variables
- Keep comments concise but complete
- Follow Go documentation conventions
]]
--- Prompt for adding README documentation
M.readme = [[Generate README documentation for this code:
{{code}}
Include:
- Project description
- Installation instructions
- Usage examples
- API documentation
- Contributing guidelines
]]
--- Prompt for adding inline comments
M.inline_comments = [[Add helpful inline comments to this code:
{{code}}
Guidelines:
- Explain complex logic
- Document non-obvious decisions
- Don't state the obvious
- Keep comments concise
- Use TODO/FIXME where appropriate
]]
--- Prompt for adding API documentation
M.api_docs = [[Generate API documentation for this code:
{{code}}
Include for each endpoint/function:
- Description
- Parameters with types
- Return value with type
- Example request/response
- Error cases
]]
--- Prompt for adding type definitions
M.type_definitions = [[Generate type definitions for this code:
{{code}}
Requirements:
- Define interfaces/types for all data structures
- Include optional properties where appropriate
- Add JSDoc/docstring descriptions
- Export all types that should be public
]]
--- Prompt for changelog entry
M.changelog = [[Generate a changelog entry for these changes:
{{changes}}
Format:
- Use conventional changelog format
- Categorize as Added/Changed/Fixed/Removed
- Be concise but descriptive
- Include breaking changes prominently
]]
--- Generic documentation prompt
M.generic = [[Add documentation to this code:
{{code}}
Language: {{language}}
Requirements:
- Use appropriate documentation format for the language
- Document all public APIs
- Include parameter and return descriptions
- Add examples where helpful
]]
return M

View File

@@ -0,0 +1,56 @@
---@mod codetyper.prompts Prompt templates for Codetyper.nvim
---
--- This module provides all prompt templates used by the plugin.
--- Prompts are organized by functionality and can be customized.
local M = {}
-- Load all prompt modules
M.system = require("codetyper.prompts.system")
M.code = require("codetyper.prompts.code")
M.ask = require("codetyper.prompts.ask")
M.refactor = require("codetyper.prompts.refactor")
M.document = require("codetyper.prompts.document")
--- Get a prompt by category and name
---@param category string Category name (system, code, ask, refactor, document)
---@param name string Prompt name
---@param vars? table Variables to substitute in the prompt
---@return string Formatted prompt
function M.get(category, name, vars)
local prompts = M[category]
if not prompts then
error("Unknown prompt category: " .. category)
end
local prompt = prompts[name]
if not prompt then
error("Unknown prompt: " .. category .. "." .. name)
end
-- Substitute variables if provided
if vars then
for key, value in pairs(vars) do
prompt = prompt:gsub("{{" .. key .. "}}", tostring(value))
end
end
return prompt
end
--- List all available prompts
---@return table Available prompts by category
function M.list()
local result = {}
for category, prompts in pairs(M) do
if type(prompts) == "table" and category ~= "list" and category ~= "get" then
result[category] = {}
for name, _ in pairs(prompts) do
table.insert(result[category], name)
end
end
end
return result
end
return M

View File

@@ -0,0 +1,128 @@
---@mod codetyper.prompts.refactor Refactoring prompts for Codetyper.nvim
---
--- These prompts are used for code refactoring operations.
local M = {}
--- Prompt for general refactoring
M.general = [[Refactor this code to improve its quality:
{{code}}
Focus on:
- Readability
- Maintainability
- Following best practices
- Keeping the same functionality
]]
--- Prompt for extracting a function
M.extract_function = [[Extract a function from this code:
{{code}}
The function should:
{{description}}
Requirements:
- Give it a meaningful name
- Include proper parameters
- Return appropriate values
]]
--- Prompt for simplifying code
M.simplify = [[Simplify this code while maintaining functionality:
{{code}}
Goals:
- Reduce complexity
- Remove redundancy
- Improve readability
- Keep all existing behavior
]]
--- Prompt for converting to async/await
M.async_await = [[Convert this code to use async/await:
{{code}}
Requirements:
- Convert all promises to async/await
- Maintain error handling
- Keep the same functionality
]]
--- Prompt for adding error handling
M.add_error_handling = [[Add proper error handling to this code:
{{code}}
Requirements:
- Handle all potential errors
- Use appropriate error types
- Add meaningful error messages
- Don't change core functionality
]]
--- Prompt for improving performance
M.optimize_performance = [[Optimize this code for better performance:
{{code}}
Focus on:
- Algorithm efficiency
- Memory usage
- Reducing unnecessary operations
- Maintaining readability
]]
--- Prompt for converting to TypeScript
M.convert_to_typescript = [[Convert this JavaScript code to TypeScript:
{{code}}
Requirements:
- Add proper type annotations
- Use interfaces where appropriate
- Handle null/undefined properly
- Maintain all functionality
]]
--- Prompt for applying design pattern
M.apply_pattern = [[Refactor this code to use the {{pattern}} pattern:
{{code}}
Requirements:
- Properly implement the pattern
- Maintain existing functionality
- Improve code organization
]]
--- Prompt for splitting a large function
M.split_function = [[Split this large function into smaller, focused functions:
{{code}}
Goals:
- Single responsibility per function
- Clear function names
- Proper parameter passing
- Maintain all functionality
]]
--- Prompt for removing code smells
M.remove_code_smells = [[Refactor this code to remove code smells:
{{code}}
Look for and fix:
- Long methods
- Duplicated code
- Magic numbers
- Deep nesting
- Other anti-patterns
]]
return M

View File

@@ -0,0 +1,96 @@
---@mod codetyper.prompts.system System prompts for Codetyper.nvim
---
--- These are the base system prompts that define the AI's behavior.
local M = {}
--- Base system prompt for code generation
M.code_generation = [[You are an expert code generation assistant integrated into Neovim via Codetyper.nvim.
Your task is to generate high-quality, production-ready code based on the user's prompt.
CRITICAL RULES:
1. Output ONLY the code - no explanations, no markdown code blocks, no comments about what you did
2. Match the coding style, conventions, and patterns of the existing file
3. Use proper indentation and formatting for the language
4. Follow best practices for the specific language/framework
5. Preserve existing functionality unless explicitly asked to change it
6. Use meaningful variable and function names
7. Handle edge cases and errors appropriately
Language: {{language}}
File: {{filepath}}
]]
--- System prompt for code explanation/ask
M.ask = [[You are a helpful coding assistant integrated into Neovim via Codetyper.nvim.
You help developers understand code, explain concepts, and answer programming questions.
GUIDELINES:
1. Be concise but thorough in your explanations
2. Use code examples when helpful
3. Reference the provided code context in your explanations
4. Format responses in markdown for readability
5. If you don't know something, say so honestly
6. Break down complex concepts into understandable parts
7. Provide practical, actionable advice
IMPORTANT: When file contents are provided, analyze them carefully and base your response on the actual code.
]]
--- System prompt for refactoring
M.refactor = [[You are an expert code refactoring assistant integrated into Neovim via Codetyper.nvim.
Your task is to refactor code while maintaining its functionality.
CRITICAL RULES:
1. Output ONLY the refactored code - no explanations
2. Preserve ALL existing functionality
3. Improve code quality, readability, and maintainability
4. Follow SOLID principles and best practices
5. Keep the same coding style as the original
6. Do not add new features unless explicitly requested
7. Optimize performance where possible without sacrificing readability
Language: {{language}}
]]
--- System prompt for documentation
M.document = [[You are a documentation expert integrated into Neovim via Codetyper.nvim.
Your task is to generate clear, comprehensive documentation for code.
CRITICAL RULES:
1. Output ONLY the documentation/comments - ready to be inserted into code
2. Use the appropriate documentation format for the language:
- JavaScript/TypeScript: JSDoc
- Python: Docstrings (Google or NumPy style)
- Lua: LuaDoc/EmmyLua
- Go: GoDoc
- Rust: RustDoc
- Java: Javadoc
3. Document all parameters, return values, and exceptions
4. Include usage examples where helpful
5. Be concise but complete
Language: {{language}}
]]
--- System prompt for test generation
M.test = [[You are a test generation expert integrated into Neovim via Codetyper.nvim.
Your task is to generate comprehensive unit tests for the provided code.
CRITICAL RULES:
1. Output ONLY the test code - no explanations
2. Use the appropriate testing framework for the language:
- JavaScript/TypeScript: Jest or Vitest
- Python: pytest
- Lua: busted or plenary
- Go: testing package
- Rust: built-in tests
3. Cover happy paths, edge cases, and error scenarios
4. Use descriptive test names
5. Follow AAA pattern: Arrange, Act, Assert
6. Mock external dependencies appropriately
Language: {{language}}
]]
return M