Context in Edit Mode Ignores Most of the Current File

I’ve noticed while experimenting with commands like this:

"Test": {
    "prompt": "Analyze the entire code and create a list of its methods in the comments.",
    "context": {
      "selection": true,
      "currentFile": true,
      "openTabs": true
    },
    "mode": "edit"
  },

that Cody demonstrates excellent awareness of the context from all open tabs, but heavily truncates the current file (likely only analyzing the area near the cursor or selection). This is odd. Ideally, to reduce context, we strive to write modular code where the LLM only needs a single class. However, even the current class is heavily truncated.

I’ve tried different variations, including:

"selection": false,
      "currentFile": true,
      "openTabs": false

This doesn’t help; it’s still clear that Cody doesn’t understand most of the current file. This issue doesn’t exist in “ask” mode.

If this is intentional or there’s a workaround, I’d be grateful to know. Currently, it feels like a bug (since I’m explicitly setting these context options), and it discourages me from using edit mode, forcing me to rely on the chat instead. Of course, I can select the entire file, which would solve the problem, but I often ask Cody to write code or refactor a specific part of the file based on a comment, while considering the context of the entire file.

Thanks in advance for your response.

Hello @NikoBellic
Indeed, in edit mode, only a portion of the currently open file is used as additional context. This mode typically applies to selected code ranges, including 50 lines before and after the selection. Conversely, in ask mode, the entire file is selected as additional context, along with other open files, depending on the configuration of the custom command, as illustrated in your example.

I noticed that, but it’s illogical. It’s not even about reducing the context size - other files in edit mode are included in the context entirely, but the file being edited is truncated! If I had to choose, I’d prefer the opposite. However, I suspect that given the current situation and access to all open tabs, the developers should simply fix this. If “currentFile”: true or “openTabs”: true is selected, the current file should be analyzed in its entirety, even in edit mode. This would often significantly improve the quality of edits and eliminate the need for workarounds like selecting the entire file (which is simply inconvenient).

I feel you. So said, the current opened file should have precedence as full context against all other opened tabs.
Depending on the context token window the question arises, which file should be truncated if they are to big?
Should the tab order be considered?

The issue is that the file is demonstrably not very large (e.g., it might be 200 lines of code). Its context is fully processed if I use edit mode in another file where I ask Cody to list methods from all classes in open files. In that case, Cody has no problem considering its entire context. However, as soon as I select a specific line within that file, part of the context is lost and cannot be recovered.

The fact that this is likely a bug rather than an issue of “context being too large” is further evidenced by the ability to select the entire file - in edit mode, the entire context is considered. But for some reason, it’s not considered if I only select a portion of it.

I don’t know how else to explain this. It’s not difficult to reproduce. Open a few files with 200 lines of code and use a task similar to what I was doing. You will see that selecting a portion of the code triggers this error (I’m 99% sure it’s an error; it doesn’t make sense considering that alternative scenarios don’t lose context). I would simply suggest that the developers look into this and fix it.