Skip to content

refactor(list): extract build_list_prefix helper and simplify marker functions#223

Merged
YousefHadder merged 2 commits intomainfrom
code-simplifier/2026-03-07-2d01f401fff9c842
Mar 7, 2026
Merged

refactor(list): extract build_list_prefix helper and simplify marker functions#223
YousefHadder merged 2 commits intomainfrom
code-simplifier/2026-03-07-2d01f401fff9c842

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Mar 7, 2026

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 — extracted build_list_prefix helper used in 4 places
  • lua/markdown-plus/list/parser.lua — simplified get_next_marker and get_previous_marker
  • lua/markdown-plus/utils.lua — renamed ambiguous text variable to text_parts

Improvements Made

1. Extracted build_list_prefix helper (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:

local function build_list_prefix(indent, marker, checkbox)
  local prefix = indent .. marker .. " "
  if checkbox then prefix = prefix .. "[ ] " end
  return prefix
end

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("[%.%)]$")). The ordered and ordered_paren cases 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_line call now appears once instead of 3 times.

4. Renamed texttext_parts (utils.lua)

In get_text_in_range, the accumulator was ambiguously named text (same name as the concept being built). Renamed to text_parts for clarity.

Changes Based On

Recent changes from:

Testing

  • ✅ No functional changes — logic is identical, only structure differs
  • ⚠️ Test suite requires plenary.nvim (not installed in CI environment); linting tools (luacheck, stylua) also not available in this runner
  • All changes are purely structural refactors with no behavior difference

Review Focus

Please verify:

  • build_list_prefix correctly replicates the 4 inline patterns it replaces
  • get_next_marker delimiter extraction (marker:match("[%.%)]$")) covers all 6 type variants correctly
  • get_previous_marker restructuring preserves the "check prev item → fallback to initial" logic for all 3 ordered/letter types

References:

Generated by Code Simplifier ·

To install this agentic workflow, run

gh aw add github/gh-aw/.github/workflows/code-simplifier.md@852cb06ad52958b402ed982b69957ffc57ca0619

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • index.crates.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "index.crates.io"

See Network Configuration for more information.

  • expires on Mar 8, 2026, 6:04 AM UTC

…functions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_prefix helper to centralize list prefix creation in list handlers.
  • Simplified get_next_marker / get_previous_marker by collapsing duplicated branches in the list parser.
  • Renamed a local accumulator in utils.get_text_in_range for 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 YousefHadder changed the title [code-simplifier] refactor(list): extract build_list_prefix helper and simplify marker functions refactor(list): extract build_list_prefix helper and simplify marker functions Mar 7, 2026
@YousefHadder YousefHadder merged commit c37670a into main Mar 7, 2026
15 of 16 checks passed
@YousefHadder YousefHadder deleted the code-simplifier/2026-03-07-2d01f401fff9c842 branch March 7, 2026 06:33
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants