Skip to content

Conversation

Copy link

Copilot AI commented Sep 28, 2025

This PR implements a configurable YAML parser system for frontmatter parsing, addressing the discussion in #1 about providing flexibility for users who don't have access to the lyaml dependency.

Problem

The current implementation hardcodes the use of lyaml for parsing YAML frontmatter in markdown files. This creates a barrier for users who don't have lyaml installed or available in their environment (e.g., users without LuaRocks access).

Solution

Added a configuration system to the frontmatter module that allows users to specify custom YAML parser functions while maintaining full backward compatibility:

local frontmatter = require('codecompanion.filewise.frontmatter')

-- Option 1: Default behavior (tries lyaml, falls back to built-in parser)
-- No configuration needed - works automatically

-- Option 2: Explicit custom parser
frontmatter.setup({
  yaml_parser = function(yaml_text)
    -- Your custom YAML parsing logic
    return parsed_table_or_nil
  end
})

-- Option 3: Use the built-in parser explicitly
local yaml_parser = require('codecompanion.filewise.yaml_parser')
frontmatter.setup({
  yaml_parser = yaml_parser.parse
})

Key Features

  • Backward Compatible: Existing users with lyaml see no changes in behavior
  • Automatic Fallback: When lyaml is unavailable, automatically uses the built-in YAML parser
  • Configurable: Users can provide their own YAML parser functions
  • Zero Breaking Changes: All existing extensions continue to work without modification
  • Well Documented: Added comprehensive configuration documentation to README

Implementation Details

  • Modified lua/codecompanion/filewise/frontmatter.lua to support configurable parsers
  • Added setup() function for configuration
  • Added get_yaml_parser() function that intelligently selects the appropriate parser
  • Maintained the same public API (parse() function remains unchanged)
  • Updated README.md with configuration examples and usage instructions

Testing

Comprehensive testing covers all scenarios:

  • Default behavior with lyaml available/unavailable
  • Custom parser configuration
  • Error handling and edge cases
  • Integration with all three extensions (Custom Instructions, Custom Prompts, Custom Modes)
  • Configuration persistence and multiple setup calls

This solution provides the requested "configuration field that allows to specify a custom YAML parser" while ensuring no disruption to existing workflows.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

dyamon#1 (comment)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Eckii24 <35373554+Eckii24@users.noreply.github.com>
Copilot AI changed the title [WIP] https://github.com/dyamon/codecompanion-filewise.nvim/pull/1#issuecomment-3327326841 Add configurable YAML parser support for frontmatter parsing Sep 28, 2025
Copilot AI requested a review from Eckii24 September 28, 2025 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants