ai.nvim icon indicating copy to clipboard operation
ai.nvim copied to clipboard

Percent caracter must be escaped

Open rakotomandimby opened this issue 1 year ago • 1 comments

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.

rakotomandimby avatar May 22 '24 12:05 rakotomandimby

I cannot reproduce this issue. It works for me as expected.

gera2ld avatar Jul 17 '24 06:07 gera2ld