BusyCode shares insights into using GitHub Copilot in Visual Studio, noting its challenges with modifying code and offering strategies for better results with AI code assistance.

Understanding GitHub Copilot’s Code Modification Limitations in Visual Studio

BusyCode raises a common concern among developers using GitHub Copilot in Visual Studio: when requesting code changes, Copilot frequently inserts new code alongside the existing code rather than replacing or removing old code. In about 75% of cases, after accepting Copilot’s suggestions, developers observe the new implementation is added before, after, or within the scope of the original code, leaving obsolete code in place.

Key Challenges with Copilot Code Changes

  • Non-destructive Additions: Copilot typically appends or prepends suggested code instead of removing outdated blocks. This can result in duplicated or conflicting logic unless manually removed.
  • Lack of Intent Understanding: As an AI language model, Copilot predicts probable code continuations but does not fully grasp developer intentions or the required structural changes. It doesn’t ‘understand’ code contextually like a human would.
  • Prompt Sensitivity: When users paste large blocks of code and give generic instructions such as “fix this,” Copilot’s suggestions are less targeted and more prone to errors.

Effective Strategies for Copilot Use

  • Work with Small Code Blocks: For best results, request changes on concise, self-contained segments of code. Smaller, explicit instructions are easier for Copilot to act upon correctly.
  • Be Precise with Prompts: Clearly state what needs to be added, changed, or removed. For example, “Replace method X with Y implementation” rather than “fix this class.”
  • Manually Review and Refactor: Always review Copilot’s inserted code, remove any obsolete sections yourself, and refactor as needed to maintain code quality.
  • Understand LLM Limitations: Copilot predicts the next likely characters, not structural code intentions. It lacks full awareness of the bigger picture unless given sufficient context and precise requirements.

Community Takeaway

If you rely on Copilot to make sweeping changes across large files or classes, expect inconsistent results. Approaching code changes in smaller, purposeful increments will reduce errors and prevent code clutter. Ultimately, Copilot is a powerful assistant but not a replacement for manual quality control and clear developer direction.


Author: BusyCode

“The bigger the block of code you paste into it, the more likely it is to fuck up.”

This post appeared first on “Reddit Visual Studio”. Read the entire article here