-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/replace lyaml with custom impl #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feature/replace lyaml with custom impl #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces the external lyaml dependency with a custom lightweight YAML parser specifically designed for frontmatter parsing. The change reduces external dependencies while maintaining the same functionality for parsing YAML frontmatter in markdown files.
- Removes dependency on external Lua YAML libraries (
lyaml) - Implements a built-in YAML parser optimized for frontmatter use cases
- Updates documentation to reflect the removal of external dependencies
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lua/codecompanion/filewise/yaml_parser.lua |
New custom YAML parser implementation with support for key-value pairs, lists, and block scalars |
lua/codecompanion/filewise/frontmatter.lua |
Updates import and function call to use the new custom YAML parser instead of lyaml |
docs/project-description.md |
Updates documentation to reflect the use of built-in YAML parser instead of external libraries |
README.md |
Removes installation requirement note about the lyaml dependency |
| if line == '' or line:match('^#') then | ||
| i = i + 1 | ||
| else | ||
| local key, value = line:match('^([%w_%-]+)%s*:%s*(.*)$') |
Copilot
AI
Sep 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key pattern [%w_%-]+ allows hyphens anywhere in the key name, but YAML keys with leading/trailing hyphens or consecutive hyphens may cause parsing issues. Consider using a more restrictive pattern like [%w_]+[%w_%-]*[%w_]+ or [%w_][%w_%-]* to ensure valid key names.
| local key, value = line:match('^([%w_%-]+)%s*:%s*(.*)$') | |
| local key, value = line:match('^([%w_]+[%w_%-]*[%w_]+)%s*:%s*(.*)$') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about this one...
| local inline = value:match('^%[(.*)%]$') | ||
| if inline then | ||
| local items = {} | ||
| for part in inline:gmatch('[^,]+') do |
Copilot
AI
Sep 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parsing logic will incorrectly split quoted strings containing commas. For example, [\"a, b\", \"c\"] will be split into three parts instead of two. The comment on line 41 acknowledges this limitation, but it could cause issues with frontmatter that contains quoted strings with commas.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Hey @Eckii24, thanks for the PR. I'm thinking about this but to be completely honest why would I maintain some custom yaml parser just to avoid installing a dependency. |
|
Hi @dyamon, totally valid! My reason for considering this PR is really, that I'm only using nvim without e.g. LuaRocks. Therefore there is no easy way to install this dependency (at least I'm not aware of it). Not sure if I'm alone with this. |
|
I'm not sure because I use Nix to manage the installation, so it is rather straightforward to declare dependencies. A possible solution would be to have a configuration field that allows to specify a custom YAML parser (so you can use yours). Smells a bit like feature creep, but still I'd be happy to add this. |
|
tl;dr I do not know how to install lua-dependencies for a neovim-setup. I only use lua through NeoVim I am still in the process of figuring out how to install the dependency and where and how to point neovim there and now I am 3 yaks deep into avoiding to type "Please read AGENTS.md with @{read_file}." which could also be a custom prompt on a keybinding. I think the plugin could make things better, but the dependency (regardless of how standard and easy it seems to you), is effectively blocking me for now. Therefore, I vote for switching to this little parsing-addition which of course is not a complete YAML-parser and never will be. Alternatively, better instructions on how to install the dependency would also work, if the dependency is better for your project. |
Discussion
I'm not sure, if you will even consider this PR. At least I want to avoid external dependencies as much as possible.
The YAML logic is only used to parse the frontmatter, which has a rather simple yaml structure.
Changes
This pull request introduces a built-in lightweight YAML parser for frontmatter parsing, removing the dependency on external Lua YAML libraries. The main changes update documentation to reflect this, replace the YAML parsing implementation, and add the new parser.
Disclaimer
The changes itself are generated by copilot...