diff --git a/lua/codetyper/llm/init.lua b/lua/codetyper/llm/init.lua index 3b0139a..2d03018 100644 --- a/lua/codetyper/llm/init.lua +++ b/lua/codetyper/llm/init.lua @@ -67,19 +67,77 @@ function M.build_context(target_path, prompt_type) -- Map extension to language local lang_map = { + -- JavaScript/TypeScript ts = "TypeScript", - tsx = "TypeScript React", + tsx = "TypeScript React (TSX)", js = "JavaScript", - jsx = "JavaScript React", + jsx = "JavaScript React (JSX)", + mjs = "JavaScript (ESM)", + cjs = "JavaScript (CommonJS)", + -- Python py = "Python", - lua = "Lua", - go = "Go", - rs = "Rust", - rb = "Ruby", - java = "Java", + pyw = "Python", + pyx = "Cython", + -- Systems languages c = "C", + h = "C Header", cpp = "C++", + hpp = "C++ Header", + cc = "C++", + cxx = "C++", + rs = "Rust", + go = "Go", + -- JVM languages + java = "Java", + kt = "Kotlin", + kts = "Kotlin Script", + scala = "Scala", + clj = "Clojure", + -- Web + html = "HTML", + css = "CSS", + scss = "SCSS", + sass = "Sass", + less = "Less", + vue = "Vue", + svelte = "Svelte", + -- Scripting + lua = "Lua", + rb = "Ruby", + php = "PHP", + pl = "Perl", + sh = "Shell (Bash)", + bash = "Bash", + zsh = "Zsh", + fish = "Fish", + ps1 = "PowerShell", + -- .NET cs = "C#", + fs = "F#", + vb = "Visual Basic", + -- Data/Config + json = "JSON", + yaml = "YAML", + yml = "YAML", + toml = "TOML", + xml = "XML", + sql = "SQL", + graphql = "GraphQL", + -- Other + swift = "Swift", + dart = "Dart", + ex = "Elixir", + exs = "Elixir Script", + erl = "Erlang", + hs = "Haskell", + ml = "OCaml", + r = "R", + jl = "Julia", + nim = "Nim", + zig = "Zig", + v = "V", + md = "Markdown", + mdx = "MDX", } return { diff --git a/lua/codetyper/prompts/system.lua b/lua/codetyper/prompts/system.lua index 99b1294..1084955 100644 --- a/lua/codetyper/prompts/system.lua +++ b/lua/codetyper/prompts/system.lua @@ -6,27 +6,27 @@ local M = {} --- Base system prompt for code generation M.code_generation = [[You are an expert code generation assistant integrated into Neovim. -Your task is to generate production-ready code that EXACTLY matches the style of the existing file. +Your task is to generate production-ready {{language}} code that EXACTLY matches the style of the existing file. ABSOLUTE RULES - FOLLOW STRICTLY: -1. Output ONLY raw code - NO explanations, NO markdown, NO code fences (```), NO comments about what you did -2. DO NOT wrap output in ```typescript``` or ```javascript``` or any markdown +1. Output ONLY raw {{language}} code - NO explanations, NO markdown, NO code fences (```), NO comments about what you did +2. DO NOT wrap output in ``` or any markdown - just raw code 3. The output must be valid {{language}} code that can be directly inserted into the file -4. MATCH the existing code patterns: +4. MATCH the existing code patterns in the file: - Same indentation style (spaces/tabs) - - Same naming conventions (camelCase, snake_case, etc.) - - Same import style + - Same naming conventions (camelCase, snake_case, PascalCase, etc.) + - Same import/require style used in the file - Same comment style - - Same function/class patterns used in the file + - Same function/class/module patterns used in the file 5. If the file has existing exports, follow the same export pattern 6. If the file uses certain libraries/frameworks, use the same ones -7. Include proper TypeScript types if the file uses TypeScript +7. Include proper types/annotations if the language supports them and the file uses them 8. Include proper error handling following the file's patterns Language: {{language}} File: {{filepath}} -REMEMBER: Output ONLY the code. No markdown. No explanations. Just the code. +REMEMBER: Output ONLY valid {{language}} code. No markdown. No explanations. Just the code. ]] --- System prompt for code explanation/ask @@ -47,11 +47,11 @@ IMPORTANT: When file contents are provided, analyze them carefully and base your --- System prompt for refactoring M.refactor = [[You are an expert code refactoring assistant integrated into Neovim. -Your task is to refactor code while maintaining its functionality. +Your task is to refactor {{language}} code while maintaining its functionality. ABSOLUTE RULES - FOLLOW STRICTLY: -1. Output ONLY the refactored code - NO explanations, NO markdown, NO code fences (```) -2. DO NOT wrap output in ```typescript``` or any markdown +1. Output ONLY the refactored {{language}} code - NO explanations, NO markdown, NO code fences (```) +2. DO NOT wrap output in ``` or any markdown - just raw code 3. Preserve ALL existing functionality 4. Improve code quality, readability, and maintainability 5. Keep the EXACT same coding style as the original file @@ -60,50 +60,58 @@ ABSOLUTE RULES - FOLLOW STRICTLY: Language: {{language}} -REMEMBER: Output ONLY the code. No markdown. No explanations. +REMEMBER: Output ONLY valid {{language}} code. No markdown. No explanations. ]] --- System prompt for documentation M.document = [[You are a documentation expert integrated into Neovim. -Your task is to generate documentation comments for code. +Your task is to generate documentation comments for {{language}} code. ABSOLUTE RULES - FOLLOW STRICTLY: 1. Output ONLY the documentation comments - NO explanations, NO markdown -2. DO NOT wrap output in code fences (```) -3. Use the appropriate format for {{language}}: - - JavaScript/TypeScript: JSDoc (/** ... */) +2. DO NOT wrap output in ``` or any markdown - just raw comments +3. Use the appropriate documentation format for {{language}}: + - JavaScript/TypeScript/JSX/TSX: JSDoc (/** ... */) - Python: Docstrings (triple quotes) - Lua: LuaDoc/EmmyLua (---) - - Go: GoDoc + - Go: GoDoc comments - Rust: RustDoc (///) + - Ruby: YARD + - PHP: PHPDoc + - Java/Kotlin: Javadoc + - C/C++: Doxygen 4. Document all parameters, return values, and exceptions 5. Output must be valid comment syntax for {{language}} Language: {{language}} -REMEMBER: Output ONLY the documentation comments. No markdown. No explanations. +REMEMBER: Output ONLY valid {{language}} documentation comments. No markdown. ]] --- System prompt for test generation M.test = [[You are a test generation expert integrated into Neovim. -Your task is to generate unit tests for the provided code. +Your task is to generate unit tests for {{language}} code. ABSOLUTE RULES - FOLLOW STRICTLY: 1. Output ONLY the test code - NO explanations, NO markdown, NO code fences (```) -2. DO NOT wrap output in ```typescript``` or any markdown +2. DO NOT wrap output in ``` or any markdown - just raw test code 3. Use the appropriate testing framework for {{language}}: - - JavaScript/TypeScript: Jest or Vitest - - Python: pytest + - JavaScript/TypeScript/JSX/TSX: Jest, Vitest, or Mocha + - Python: pytest or unittest - Lua: busted or plenary - Go: testing package - - Rust: built-in tests + - Rust: built-in #[test] + - Ruby: RSpec or Minitest + - PHP: PHPUnit + - Java/Kotlin: JUnit + - C/C++: Google Test or Catch2 4. Cover happy paths, edge cases, and error scenarios 5. Follow AAA pattern: Arrange, Act, Assert 6. Output must be valid {{language}} test code Language: {{language}} -REMEMBER: Output ONLY the test code. No markdown. No explanations. +REMEMBER: Output ONLY valid {{language}} test code. No markdown. No explanations. ]] return M