ai.nvim
ai.nvim copied to clipboard
Percent caracter must be escaped
When AI answer contains %, that caracter is silently ignored.
Lets take as exemple this Symfony services.yaml file:
# This is a services.yaml file in a Symfony project.
# In ../.env file, I set MIHAMINA_ID to 1234.
# I want to set the parameter mihamina_id to the value of MIHAMINA_ID.
# Modify the parameters section of this services.yaml file
# to set the mihamina_id parameter to the value of MIHAMINA_ID.
parameters:
services:
_defaults:
autowire: true
autoconfigure: true
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
If I prompt AI with the whole file, the displayed result is :
parameters:
mihamina_id: 'env(MIHAMINA_ID)'
services:
_defaults:
autowire: true
autoconfigure: true
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
We notice the % are missing.
It should be:
parameters:
mihamina_id: '%env(MIHAMINA_ID)%'
services:
_defaults:
autowire: true
autoconfigure: true
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
We must escape the % in the AI response with a kind of :
function query.escapePercent(s)
return string.gsub(s, "%%", "%%%%")
end
I made it quickly in https://github.com/natixgroup/ai.nvim/commit/0356e9a7ecb19937720d4cd5b8c6239870821fa6 but it very ugly as it needs to be factorized.
I cannot reproduce this issue. It works for me as expected.