Edit code in VS code, "Apply" throws error

I guess it’s not helping much that VS code, and Cody is relatively new to me.

However: I can open Cody, choose a file by selecting “edit code”. Then in the chat window I can ask specific questions, cody offers a solution, and I press “apply”. Apply however does not word, it returns 2 errors:

1st:
Error: The chat input has exceeded the token limit. If you are copying and pasting a file into the chat, try using the @-mention feature to attach the file instead.

2nd:
Unable to apply this change to the file. Please try applying this code manually

Can anybody gove me a hint what I am doing wrong? One hint was selecting the file with “@”, but as stated at the beginning, the file had been selected at the very beginning, or am I missing something?

I can generate a new file, but the new file only contains the suggested lines of code to change, not the entire code where I would like to see Cody apply the changes.

Hey @Joihnny579

Welcome to Cody.

Cody has limits on how much content in a file can be processed. These are the so-called “tokens”. If this token limit or token window exceeds specific limits, Cody throws those errors you mentioned.

You can learn more about the token limits here: Cody Input and Output Token Limits - Sourcegraph docs

The best practice in such a case is to keep the file smaller. Break down functions or classes into its own files. Therefore, a file has a specific responsibility and is separated by its concerns. This not only makes the life of Cody easier but also your own mental cognitive workload.

Later on, if you are working on a use case or goal, you can mention the file for the task at hand and Cody can handle it within its limits much better.

I hope that helped.

Thanks. Yes, it does help, because it tells me that my file is too large for Cody to modify it, and it tells me that I should check if I could put certain parts of the code (maybe functions) in external files. Need to check. Am playing with MQL4, not yet aware that I can do that. But then again: Just playing around with little experience.

@Joihnny579

With MQL4 files it is somehow different, because you need to have all the code in one file for an Expert Advisor. Custom Indicators won’t be so large except they are handling a lot of data.

If you want outsource functions or code you can utilize the include macro in MQL4, but I haven’t tested it out so far.

Another option you have is to only select parts of the file and reference them to Cody.
For example, you are working on trade management, like closing and opening orders in a specific scenario or signal given and want test things out in the Strategy Tester, you can simply reference the specific code to Cody. The same goes for the Lot calculation in risk management modules and such.

Only reference what you really need to. Think of it from the point of view of data. What comes in, needs to be transformed and what is the desired output. Group that in logical and semantical code or function modules.