Relying on inline ghost text to refactor legacy code is a recipe for silent architectural rot.
At 365Finds, we see developers make this mistake repeatedly: they open an eight-year-old service, highlight nothing, start typing, and hope the grey autocomplete ghost text will somehow understand that they want to migrate an ugly nested callback into an async pipeline. It won't. What it will actually do is aggressively predict the continuation of your legacy debt. It autocompletes the very antipatterns you are trying to erase.
When modifying an established codebase, GitHub Copilot splits into two fundamentally divergent tools: Inline Code Completions (the passive autocomplete engine) and GitHub Copilot Chat (including inline chat Ctrl+I/Cmd+I, workspace edits, and the sidebar assistant). Treating them as interchangeable is where refactoring efforts fall apart.
Here is where the boundary actually lies, what each tool does to your codebase, and how 365Finds recommends orchestrating them.
The Fundamental Architectural Divide
The two interfaces operate on opposing mental models and context windows:
| Dimension | Inline Code Completions | GitHub Copilot Chat (Inline Chat & Sidebar) |
|---|---|---|
| Trigger Mechanism | Passive; triggers automatically on cursor pauses and keystrokes | Active; triggered by explicit keyboard shortcuts (Cmd+I / Ctrl+I) or prompt input |
| Context Window Scope | Immediate cursor neighborhood, neighboring lines, recently opened editor tabs | Explicitly scoped code selections, @workspace indexing, referenced #file anchors |
| Operational Intent | Token continuation based on statistical probability | Declarative transformation based on natural language instructions |
| Review Surface | Fleeting ghost text accepted via Tab | Structured inline diffs (red/green) with explicit accept/discard controls |
| Bias on Legacy Code | Perpetuates existing patterns, variable naming, and technical debt | Capable of breaking existing idioms to introduce modern paradigms |
Why Inline Completions Fail at Refactoring
Inline completions are designed for forward velocity, not structural revision.
When you refactor, your goal is almost always to invert a pattern:
- Decomposing a 600-line monolithic handler into testable domain functions.
- Replacing mutable global state with dependency-injected interfaces.
- Migrating raw SQL string concatenation to parameterized query builders.
Inline completion cannot deduce this strategic reversal from an empty line. It looks at the 500 lines above your cursor and the 100 lines below it. Because the surrounding context is saturated with legacy syntax, the autocomplete model naturally assumes you want to write more legacy syntax.
If you rename a variable on line 12 and move down to line 15, Next Edit Suggestions (NES) may occasionally guess your next cursor jump. But the moment you delete a block and pause, Copilot completions will eagerly offer to recreate the exact lines you just removed. Fighting your autocomplete while attempting a delicate refactor destroys flow. 365Finds strongly advises disabling or ignoring inline completions during the initial structural teardown of legacy modules.
How GitHub Copilot Chat Handles Refactoring
GitHub Copilot Chat is where refactoring actually happens. It shifts the interaction from statistical guessing to explicit semantic instruction.
Instead of typing and hoping, you select the problematic block, invoke inline chat (Cmd+I on macOS or Ctrl+I on Windows/Linux), and declare the desired target state.
1. Targeted Extraction and Functional Purity
When tackling long procedural functions, highlight the isolated logic block:
Refactor this block into a standalone pure function named `calculateTieredDiscount`.
Do not mutate input objects. Return an explicit result type with error boundaries.
Copilot Chat analyzes the selected block, identifies closed-over variables, extracts the parameters cleanly, and presents a visual diff. You inspect line-by-line before accepting.
2. Cross-File Context with @workspace
Legacy codebases rarely isolate complexity inside a single file. A change to an interface in types/billing.ts ripples through three controllers and four adapters.
Through the Copilot Chat sidebar, @workspace queries index your codebase symbols:
@workspace We are deprecating `LegacyAuthContext`. Analyze `src/middleware/auth.ts` and `src/routes/api.ts`, then outline the steps to adopt `TokenSessionManager` without breaking existing session validation.
Inline completions cannot perform this multi-hop semantic audit. Chat can. It maps the dependencies and lets you plan the transition before writing a single line of code.
3. Behavioral Guardrails and Test Generation
Refactoring without automated tests is simply introducing bugs with cleaner syntax.
Copilot Chat allows you to generate regression baselines before touching legacy code:
Generate comprehensive unit tests using Vitest for this `LegacyTaxCalculator` class covering edge cases, negative totals, and null currency codes before we refactor it.
Once your test harness is green, you refactor with inline chat. If the tests break, you revert the diff.
The 365Finds Refactoring Workflow
At 365Finds, we follow a strict sequential rule when refactoring legacy modules: Chat to sculpt, completions to sweep.
flowchart TD
A["Legacy Codebase Target"] --> B["Step 1: Copilot Chat Sidebar (@workspace)"]
B -->|"Generate tests & map cross-file dependencies"| C["Step 2: Inline Chat (Cmd+I / Ctrl+I)"]
C -->|"Highlight block, apply targeted transformation, review diff"| D["Step 3: Inline Completions (Tab / Ghost Text)"]
D -->|"Sweep repetitive call-sites, fill boilerplate mocks"| E["Clean, Tested Modern Code"]
Phase 1: Planning and Scaffolding (Copilot Chat Sidebar)
Open the sidebar. Use @workspace to trace call hierarchies and verify where deprecated signatures are consumed. Ask Copilot to draft characterization tests for undocumented legacy logic.
Phase 2: Structural Transformation (Inline Chat)
Highlight target blocks inside the active file. Use natural language commands to extract classes, modernise async patterns, or implement design patterns. Critically evaluate the green/red diff view before pressing accept. Never let AI code into your tree without a diff review.
Phase 3: Mechanical Repetition (Inline Completions)
Once the new pattern is established and committed to the file, switch back to inline completions. As you navigate to secondary consumer files, Copilot's local context engine picks up on the freshly authored pattern in your open tabs. Now, ghost text becomes an asset: it auto-fills the updated argument lists and repetitive boilerplate call-sites at high speed.
What to Watch Out For
Copilot Chat is powerful, but refactoring legacy code introduces unique hazards:
- Hallucinated Internal Utilities: When asked to simplify complex logic, Copilot Chat often invents plausible-sounding utility functions (e.g.,
StringUtils.sanitizeDeep()) that do not exist in your internal libraries. Always verify imports. - Silent Loss of Edge-Case Logic: Legacy code often looks horrifying precisely because it contains defensive fixes for obscure production bugs discovered five years ago. Copilot will happily "clean up" that weird nested
ifstatement, completely erasing critical edge-case handling. Always specify: "Preserve all existing edge-case null checks and error handling verbatim." - Diff Complacency: In inline chat, developers tend to hit
Acceptbecause the code looks neat. Reading a diff generated by an LLM requires greater vigilance than reading human pull requests, because machine hallucinations look syntactically immaculate.
Inline completions accelerate what you are already doing; GitHub Copilot Chat changes what you are doing. For existing codebases, master the transition between them.