If I ask Cody (usually via Sonnet 3.7) to make a fix to a large source file, e.g. 2000 LOC, it comes up with a reasonable looking fix, but choosing Apply in Editor almost always screws up the file, typically by truncating it. Other typical problems include messing up brace matching.
The problem occurs even for fixes that are limited to a very small section of the code.
The really frustrating thing is that Cody does significantly better at analyzing and suggesting fixes for a large file than for the same code split into multiple smaller files. But then it screws up applying the changes 
1 Like
Hey @Michael-F-Ellis
Applying changes does indeed not work properly with large files. The issue is, that Cody needs to understand, where it should apply the changes and need the full context of the file to determine the location of the change. If in this case the file is too large, it might not know where to apply those changes and fails, because the content of the file does not fit into the context window.
Therefore, to have smaller files does not only help Cody understand the context better but might be beneficial for the developer too.
@PriNova Thanks! I’d like to better understand Cody’s limitations here. The file in question is just under 60 Kb of CSS+HTML+JS . Here’s the output from wc:
1841 6383 59298 index.html
I don’t have a token count, but based on the word count and file size it seems unlikely to be more than 12K tokens, which is well within the context limits given in Cody’s documentation for Claude (15K conversation + 30K @-mention) in Cody Input and Output Token Limits - Sourcegraph docs
The file is the only content of the repo (other than a brief readme.md
). It’s a chat client intended for personal use and, hence, wants to be able to run as a file:
resource without needing a server. It doesn’t link or include any third party content.
I started out with the conventional multiple file approach with a build script to bundle the components. I found that Cody tended to generate overly complex code that touched multiple files. As I said in the original post, I find that Cody does a much better job of understanding the bundled file and suggesting improvements.
What I don’t understand is why the Apply in Editor option then screws up the file in ways that have nothing to do with the changes being applied.