refactor(list): extract build_list_prefix helper and simplify marker functions#223
Merged
YousefHadder merged 2 commits intomainfrom Mar 7, 2026
Merged
Conversation
…functions Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors list-handling code in markdown-plus.nvim to reduce duplication and simplify marker/prefix construction while preserving existing list behavior.
Changes:
- Extracted a shared
build_list_prefixhelper to centralize list prefix creation in list handlers. - Simplified
get_next_marker/get_previous_markerby collapsing duplicated branches in the list parser. - Renamed a local accumulator in
utils.get_text_in_rangefor clearer intent.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lua/markdown-plus/list/handlers.lua | Extracts a helper to build list prefixes and reuses it across Enter/o/O list item creation. |
| lua/markdown-plus/list/parser.lua | Simplifies ordered/letter marker increment and previous-marker selection logic to reduce branching/duplication. |
| lua/markdown-plus/utils.lua | Renames a local accumulator variable in get_text_in_range for clarity. |
…kbox param The checkbox parameter was annotated as boolean|nil but callers pass list_info.checkbox which is string|nil (e.g., " ", "x"). Fix the type to match actual usage and align with the ListInfo type definition.
YousefHadder
added a commit
that referenced
this pull request
Mar 7, 2026
Address 6 issues found in PR #223 generated by the code-simplifier: 1. Add ci-bot.yml to run CI on bot-created PRs (workflow_run trigger) - GitHub blocks pull_request triggers for PRs from github-actions[bot] - Runs stylua, luacheck, and plenary tests on the PR branch - Reports combined status back to the PR commit 2. Add tool installation instructions to code-simplifier prompt (Phase 3.0) - Neovim, plenary.nvim, luacheck, stylua install commands - Blocks PR creation if any tool fails to install 3. Add type annotation verification step (Phase 2.3, step 4) - Requires reading type definition files before writing annotations - Prevents inferring types from runtime behavior alone 4. Add post-refactor standards audit (Phase 3.4) - Checks nesting depth, function length, file size, immutability - Reverts changes that violate project coding standards 5. Add human reviewer alongside copilot - Changed reviewers from [copilot] to [copilot, YousefHadder] 6. Add minimum impact threshold (Principle 5) - Skips low-value changes like local variable renames in small scopes - Requires measurable improvement: DRY, complexity, or standard fix Also adds network.allowed (github + lua ecosystems) for tool downloads.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR applies targeted simplifications to recently added code, reducing duplication and improving clarity while preserving all functionality.
Files Simplified
lua/markdown-plus/list/handlers.lua— extractedbuild_list_prefixhelper used in 4 placeslua/markdown-plus/list/parser.lua— simplifiedget_next_markerandget_previous_markerlua/markdown-plus/utils.lua— renamed ambiguoustextvariable totext_partsImprovements Made
1. Extracted
build_list_prefixhelper (handlers.lua)The pattern of building a list item prefix from indent + marker + optional checkbox appeared 4 times verbatim (in
create_next_list_item,handle_enter,handle_normal_o,handle_normal_O). Extracted into a local helper:2. Simplified
get_next_marker(parser.lua)Reduced 6 branches to 3 by extracting the delimiter directly from the marker string (
list_info.marker:match("[%.%)]$")). Theorderedandordered_parencases share identical logic modulo delimiter, same for each letter pair.3. Simplified
get_previous_marker(parser.lua)Three near-identical blocks (each doing: "check previous item at same indent, increment, or return initial") collapsed into one shared lookup block. The
get_line+parse_list_linecall now appears once instead of 3 times.4. Renamed
text→text_parts(utils.lua)In
get_text_in_range, the accumulator was ambiguously namedtext(same name as the concept being built). Renamed totext_partsfor clarity.Changes Based On
Recent changes from:
d4d836b— feat(ci): add agentic workflow code-simplifier (feat(ci): add agentic workflow code-simplifier #222) which introduced the full codebaseTesting
plenary.nvim(not installed in CI environment); linting tools (luacheck,stylua) also not available in this runnerReview Focus
Please verify:
build_list_prefixcorrectly replicates the 4 inline patterns it replacesget_next_markerdelimiter extraction (marker:match("[%.%)]$")) covers all 6 type variants correctlyget_previous_markerrestructuring preserves the "check prev item → fallback to initial" logic for all 3 ordered/letter typesReferences:
Warning
The following domain was blocked by the firewall during workflow execution:
index.crates.ioTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.