diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f40a72..38b9fb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.0.3] - 2025-03-25 + +### Fixed + +- Fixed `window/init.lua` containing invalid `//` comment syntax causing StyLua parse failure +- Fixed `check_for_closed_prompt.lua` declaring a global instead of local function +- Fixed `check_for_closed_prompt.lua` accessing undefined `config` variable — now properly requires `get_config` +- Fixed `check_for_closed_prompt_with_preference.lua` and `check_all_prompts_with_preference.lua` accessing undefined `auto_process` — now uses `preferences.is_auto_process_enabled()` +- Fixed `auto_index_file.lua` calling undefined `extract_functions`, `extract_classes`, `extract_imports` — added local implementations +- Removed unused `comment_block_start` and `comment_block_end` variables in `auto_index_file.lua` + ## [1.0.2] - 2025-03-24 ### Changed @@ -283,7 +294,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Fixed** — Bug fixes - **Security** — Vulnerability fixes -[Unreleased]: https://github.com/cargdev/codetyper.nvim/compare/v1.0.2...HEAD +[Unreleased]: https://github.com/cargdev/codetyper.nvim/compare/v1.0.3...HEAD +[1.0.3]: https://github.com/cargdev/codetyper.nvim/compare/v1.0.2...v1.0.3 [1.0.2]: https://github.com/cargdev/codetyper.nvim/compare/v1.0.1...v1.0.2 [1.0.1]: https://github.com/cargdev/codetyper.nvim/compare/v1.0.0...v1.0.1 [1.0.0]: https://github.com/cargdev/codetyper.nvim/compare/v0.6.0...v1.0.0 diff --git a/lua/codetyper/adapters/nvim/autocmds/auto_index_file.lua b/lua/codetyper/adapters/nvim/autocmds/auto_index_file.lua index edb9a26..3e6c9e5 100644 --- a/lua/codetyper/adapters/nvim/autocmds/auto_index_file.lua +++ b/lua/codetyper/adapters/nvim/autocmds/auto_index_file.lua @@ -3,6 +3,50 @@ local autocmds_state = require("codetyper.adapters.nvim.autocmds.state") local is_supported_extension = require("codetyper.adapters.nvim.autocmds.is_supported_extension") local should_ignore_for_coder = require("codetyper.adapters.nvim.autocmds.should_ignore_for_coder") +local function extract_functions(content, _ext) + local results = {} + for line in content:gmatch("[^\n]+") do + local name = line:match("^%s*function%s+([%w_:%.]+)%s*%(") + or line:match("^%s*local%s+function%s+([%w_]+)%s*%(") + or line:match("^%s*def%s+([%w_]+)%s*%(") + or line:match("^%s*func%s+([%w_]+)%s*%(") + or line:match("^%s*async%s+function%s+([%w_]+)%s*%(") + or line:match("^%s*public%s+.*%s+([%w_]+)%s*%(") + or line:match("^%s*private%s+.*%s+([%w_]+)%s*%(") + if name then + table.insert(results, { name = name }) + end + end + return results +end + +local function extract_classes(content, _ext) + local results = {} + for line in content:gmatch("[^\n]+") do + local name = line:match("^%s*class%s+([%w_]+)") + or line:match("^%s*public%s+class%s+([%w_]+)") + or line:match("^%s*interface%s+([%w_]+)") + or line:match("^%s*struct%s+([%w_]+)") + if name then + table.insert(results, { name = name }) + end + end + return results +end + +local function extract_imports(content, _ext) + local results = {} + for line in content:gmatch("[^\n]+") do + local imp = line:match("import%s+.*%s+from%s+[\"']([^\"']+)[\"']") + or line:match("require%([\"']([^\"']+)[\"']%)") + or line:match("from%s+([%w_.]+)%s+import") + if imp then + table.insert(results, imp) + end + end + return results +end + --- Auto-index a file by creating/opening its coder companion ---@param bufnr number Buffer number local function auto_index_file(bufnr) @@ -54,8 +98,6 @@ local function auto_index_file(bufnr) local file_ext = vim.fn.fnamemodify(filepath, ":e") local comment_prefix = "--" - local comment_block_start = "--[[" - local comment_block_end = "]]" if file_ext == "ts" or file_ext == "tsx" @@ -69,12 +111,8 @@ local function auto_index_file(bufnr) or file_ext == "rs" then comment_prefix = "//" - comment_block_start = "/*" - comment_block_end = "*/" elseif file_ext == "py" or file_ext == "rb" or file_ext == "yaml" or file_ext == "yml" then comment_prefix = "#" - comment_block_start = '"""' - comment_block_end = '"""' end local content = "" diff --git a/lua/codetyper/adapters/nvim/autocmds/check_all_prompts_with_preference.lua b/lua/codetyper/adapters/nvim/autocmds/check_all_prompts_with_preference.lua index 4db4691..c13ceba 100644 --- a/lua/codetyper/adapters/nvim/autocmds/check_all_prompts_with_preference.lua +++ b/lua/codetyper/adapters/nvim/autocmds/check_all_prompts_with_preference.lua @@ -1,11 +1,11 @@ local processed_prompts = require("codetyper.constants.constants").processed_prompts local get_prompt_key = require("codetyper.adapters.nvim.autocmds.get_prompt_key") local check_all_prompts = require("codetyper.adapters.nvim.autocmds.check_all_prompts") +local preferences = require("codetyper.config.preferences") --- Check all prompts with preference check --- Only processes if there are unprocessed prompts and auto_process is enabled local function check_all_prompts_with_preference() - local preferences = require("codetyper.config.preferences") local find_prompts_in_buffer = require("codetyper.parser.find_prompts_in_buffer") local bufnr = vim.api.nvim_get_current_buf() @@ -27,7 +27,7 @@ local function check_all_prompts_with_preference() return end - if auto_process then + if preferences.is_auto_process_enabled() then check_all_prompts() end end diff --git a/lua/codetyper/adapters/nvim/autocmds/check_for_closed_prompt.lua b/lua/codetyper/adapters/nvim/autocmds/check_for_closed_prompt.lua index 417fd19..f3bc46a 100644 --- a/lua/codetyper/adapters/nvim/autocmds/check_for_closed_prompt.lua +++ b/lua/codetyper/adapters/nvim/autocmds/check_for_closed_prompt.lua @@ -4,9 +4,10 @@ local is_processing = require("codetyper.constants.constants").is_processing local get_prompt_key = require("codetyper.adapters.nvim.autocmds.get_prompt_key") local read_attached_files = require("codetyper.adapters.nvim.autocmds.read_attached_files") local create_injection_marks = require("codetyper.adapters.nvim.autocmds.create_injection_marks") +local get_config = require("codetyper.utils.get_config").get_config --- Check if the buffer has a newly closed prompt and auto-process -function check_for_closed_prompt() +local function check_for_closed_prompt() if is_processing then return end @@ -36,7 +37,8 @@ function check_for_closed_prompt() local current_line = lines[1] - if has_closing_tag(current_line, config.patterns.close_tag) then + local cfg = get_config() + if has_closing_tag(current_line, cfg.patterns.close_tag) then local prompt = get_last_prompt(bufnr) if prompt and prompt.content and prompt.content ~= "" then local prompt_key = get_prompt_key(bufnr, prompt) diff --git a/lua/codetyper/adapters/nvim/autocmds/check_for_closed_prompt_with_preference.lua b/lua/codetyper/adapters/nvim/autocmds/check_for_closed_prompt_with_preference.lua index 75c1653..e7a24c0 100644 --- a/lua/codetyper/adapters/nvim/autocmds/check_for_closed_prompt_with_preference.lua +++ b/lua/codetyper/adapters/nvim/autocmds/check_for_closed_prompt_with_preference.lua @@ -1,4 +1,5 @@ local check_for_closed_prompt = require("codetyper.adapters.nvim.autocmds.check_for_closed_prompt") +local preferences = require("codetyper.config.preferences") --- Check for closed prompt with preference check --- If auto_process is enabled, process; otherwise do nothing (manual mode) @@ -11,7 +12,7 @@ local function check_for_closed_prompt_with_preference() return end - if auto_process then + if preferences.is_auto_process_enabled() then check_for_closed_prompt() end end diff --git a/lua/codetyper/init.lua b/lua/codetyper/init.lua index f84c3f9..f1e5762 100644 --- a/lua/codetyper/init.lua +++ b/lua/codetyper/init.lua @@ -9,7 +9,7 @@ local M = {} -M.version = "1.0.2" +M.version = "1.0.3" ---@type CoderConfig M.config = {} diff --git a/lua/codetyper/window/init.lua b/lua/codetyper/window/init.lua index 8728417..4e62079 100644 --- a/lua/codetyper/window/init.lua +++ b/lua/codetyper/window/init.lua @@ -1 +1 @@ -// TODO: Migrate the prompt window here to centralized the logic +-- TODO: Migrate the prompt window here to centralize the logic