Skip to content

Troubleshooting ‐ Cline Deleting Code with "Rest of Code Here" Comments

Saoud Rizwan edited this page Oct 17, 2024 · 7 revisions

Sometimes when using Cline to edit files, you may notice it replaces large chunks of code with placeholder comments like // rest of code here. This behavior occurs due to the AI model's maximum output token limit. For large files, the model may truncate portions of the code to fit within its constraints.

Note: Anthropic has announced an upcoming feature called "Fast Edit Mode" for Claude 3.5 Sonnet, which will enable faster and more reliable token output when editing files. It works by letting the model essentially regurgitate previously read tokens, and only have to "think" about changes to the file, rather than the entire contents. I will update the extension with this feature as soon as it becomes available, and this lazy coding issue will be a thing of the past. In the meantime, please try the troubleshooting steps below.

Best Practices

To mitigate this issue:

  1. Keep your files relatively small and modular.
  2. Consider moving large constants (e.g. big strings) into separate files.

Workaround: Using VSCode's Diff Editor

When Cline edits a file, it opens in VSCode's diff editor view. This presents two side-by-side versions of the file:

  • Left side: Virtual document with file's original contents
  • Right side: Updated file with Cline's changes

Step 1: Expand the Diff View for Easier Editing

  1. By default, the diff view may be collapsed, showing changes merged into a single view. This can make editing more challenging.
  2. To improve visibility and ease of editing, resize the window or tab to be wider. This will expand the diff view, splitting it into left (original) and right (modified) panels, making it much easier to compare and edit the changes.

Step 2: Using the Revert Block Button

  1. Locate the truncated section in the right-side document.
  2. Click the "Revert Block" button in the gutter between the two views to restore the original content for that section.

Alternative: Manual Copy and Paste

If you're having trouble with the revert block button:

  1. Select the missing content from the left-side document.
  2. Copy the selected text.
  3. Paste it into the appropriate location in the right-side document.

By using these methods, you can easily restore any content that the model may have truncated, ensuring your code remains intact. When you make these manual adjustments, the extension communicates these edits back to the model so it knows the final state of the file before proceeding in the task.

Support

If you've followed these steps and are still experiencing problems, please:

  1. Check the Cline GitHub Issues to see if others have reported similar problems
  2. If not, create a new issue with details about your operating system, VSCode/Cursor version, and the steps you've tried

For additional help, join our Discord.