timkmecl / codegpt

VSCode extension that allows you to use GPT3 inside the IDE
219 stars 66 forks source link

Missing line while inserting answer #3

Closed DromHour closed 1 year ago

DromHour commented 1 year ago

Extension sometime erases template literals while inserting answer of GPT3:

image

Full code with that issue:

// const SipUser = require('../../models/SipUser.model');
const fs = require('fs');
const path = require('path');
const ccQueue = require('../../models/ccQueue.model');
// const {
//   handleResponse,
//   logger,
// } = require('../../../../utils/');
// TODO fix logger?

// This module handles the requests for configuration files 
module.exports = async (req, res) => {
  const params = req.body; 

  // Logging the params
  console.log(params.key_name, params.key_value);

  // Checking if we need to send the full directory or a file
  if (params.key_name === 'name' && params.key_value === 'callcenter.conf') {
    // Getting the queues
    let queues = await ccQueue.find({});
    queues = queues.map((queue) => queue.toXML()); 

    // Setting the response headers
    res.setHeader('Content-Type', 'freeswitch/xml');
    res.status(200);

    // Sending the response
    return res.send(`
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="freeswitch/xml">
  <section name="configuration">
    <configuration name="callcenter.conf" description="CallCenter (generated by **********)">                       
      <settings>

        <param name="odbc-dsn" value="mariadb://Server=secret :)"/>
        <param name="truncate-agents-on-load" value="false"/>
        <param name="truncate-tiers-on-load" value="false"/>

      </settings>

      <queues>

        ${queues.join('\n\n')}

      </queues>

    </configuration> 
  </section>
</document>
  `);
  }

  // Generating the file path
  const fileName = path.join(__dirname, '../../static/autoload_configs', `${params.key_value}.xml`);

  // Checking if that file exists
  if (fs.existsSync(fileName)) {
    // Reading the file
    const config = fs.readFileSync(fileName, 'utf8'); 

    // Setting the response headers
    res.setHeader('Content-Type', 'freeswitch/xml');
    res.status(200);

    // Sending the response
    return res.send(`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <document type="freeswitch/xml">
      <section name="configuration">
        ${config}
      </section>
    </document>`);
  }

  // Sending a not found response
  res.setHeader('Content-Type', 'freeswitch/xml');
  res.status(200);
  res.send(`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  <document type="freeswitch/xml">
    <section name="result">
      <result status="not found" />
    </section>
  </document>`);
};
DromHour commented 1 year ago

soz, forgot to show where's missing line image

timkmecl commented 1 year ago

Hi, thanks for letting me know about this. I've fixed the problem in the latest version, so if you update to v1.0.1 from the Marketplace it should work correctly (this behaviour was caused by VSCode trying to parse your template literals as its own snippet template literals when inserting your code into the editor, instead of just inserting the text directly as-is)