Sub topic 6
Accepting, Rejecting and Partially Accepting Suggestions
This chapter assumes you have read the earlier chapters on ghost text and context assembly. You should be comfortable editing in VS Code or a JetBrains IDE and reading short Python.
Why acceptance is a decision, not a reflex
An inline completion appears as dim ghost text at the cursor. Nothing is written to your file until you accept it. That makes every suggestion a small review task: read it, judge it, then take it, change it, or ignore it.
Accepting a long suggestion without reading it is the most common source of subtle bugs. Partial acceptance exists so you can take only the part you trust.
The basic actions
Most editors map the same actions to similar keys. Defaults vary by editor and version, so check your keybindings.
| Action | Typical default | Effect |
|---|---|---|
| Accept all | Tab | Inserts the whole suggestion and moves the cursor to its end |
| Accept next word | Ctrl+Right (Cmd+Right on macOS) in VS Code | Inserts one word of the suggestion |
| Accept next line | Configurable, often unbound | Inserts one line of the suggestion |
| Reject | Esc | Hides the suggestion without changing the file |
| Keep typing | Any character | Narrows or replaces the suggestion |
| Next or previous alternative | Alt+] and Alt+[ | Cycles through other candidates when the provider returned several |
Typing is also a form of response. If the characters you type match the start of the ghost text, most editors keep showing the rest. If they differ, the suggestion is dropped and a new request may start.
Partial acceptance
Suppose you type def mean(values): and the editor suggests this body:
if not values:
return 0
return sum(values) / len(values)You may want the loop-free arithmetic but not the silent return 0, which hides an empty-input error. Accept one line at a time, or accept all and edit. Partial acceptance is useful in three cases:
- The first line is right and later lines drift from your intent.
- The suggestion uses a name or API you do not want, so you take the prefix and type the rest.
- You want to see how the model continues before committing to a long block.
After a partial accept, the remaining text is usually still shown. The editor may also request a fresh completion from the new cursor position.
What the editor records
Each outcome is usually logged as an event, which feeds the metrics covered in a later chapter. A simplified model looks like this:
from enum import Enum
class Outcome(Enum):
SHOWN = "shown"
ACCEPTED = "accepted"
PARTIAL = "partial"
REJECTED = "rejected"
IGNORED = "ignored"
def classify(shown_chars: int, accepted_chars: int, dismissed: bool) -> Outcome:
if accepted_chars == 0:
return Outcome.REJECTED if dismissed else Outcome.IGNORED
if accepted_chars >= shown_chars:
return Outcome.ACCEPTED
return Outcome.PARTIAL
print(classify(40, 40, False)) # Outcome.ACCEPTED
print(classify(40, 12, False)) # Outcome.PARTIAL
print(classify(40, 0, True)) # Outcome.REJECTEDAn explicit dismissal and a suggestion you simply typed over are different signals. Products that treat them the same overstate how often suggestions were useful.
The suggestion life cycle
Habits that work
- Read before pressing Tab, especially for blocks longer than a line or two.
- Prefer word or line acceptance when the suggestion spans several statements.
- Press Esc rather than typing over a bad suggestion if you want it recorded as a rejection.
- Run tests after accepting multi-line code. Plausible-looking code can still be wrong.
- Use version control diffs to review what you accepted before committing.
Exercise
Exercise
You type a function signature and the editor shows a ten-line body. The first three lines are correct, but line four calls a function that does not exist in your project. What do you do, and why is that better than accepting all?
Show answer
Accept only the first three lines using line-by-line acceptance, then write line four yourself and let the editor suggest again from there. Accepting all would insert a call to a missing function, which fails at run time or at the type check and may be missed during a quick review. Partial acceptance keeps the trusted part and leaves the unverified part to you.
Exercise
A metrics dashboard counts every suggestion you typed over as "rejected". Why can this mislead the team?
Show answer
Typing over a suggestion often means you never read it or already knew what you wanted, which is different from judging it wrong and pressing Esc. Merging the two signals makes the rejection rate look worse than the quality of the suggestions justifies, and it hides how many suggestions were simply ignored.