Show line range in agent host file-read tool display#312062
Merged
roblourens merged 5 commits intomainfrom Apr 23, 2026
Merged
Conversation
When the Copilot CLI's `view` tool is called with a `view_range`, surface the line range in the invocation and past-tense messages so users see e.g. "Reading file.ts, lines 10 to 20" instead of just "Reading file.ts". (Written by Copilot) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the agent host’s Copilot CLI tool-call display strings so view tool invocations/completions can show a requested line range (when provided via view_range) rather than only the file name.
Changes:
- Add
ICopilotViewToolArgswith optionalview_range?: number[]forviewtool parameters. - Add
formatViewRangehelper to parse/normalizeview_range. - Update
getInvocationMessage/getPastTenseMessageViewcases to render “line …” / “lines … to …” variants.
Show a summary per file
| File | Description |
|---|---|
| src/vs/platform/agentHost/node/copilot/copilotToolDisplay.ts | Parses view_range and includes the formatted line/range in view tool start/complete messages. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/vs/platform/agentHost/node/copilot/copilotToolDisplay.ts:95
formatViewRangecurrently accepts non-integer and non-positive line numbers (e.g.0,1.5) and can also return anendLinethat is less thanstartLine(e.g.[10, 5]), which then renders as “lines 10 to 5”. Sinceview_rangeis documented as 1-based inclusive, it should defensively validateNumber.isInteger,startLine >= 1, and (whenendLineis a number)endLine >= startLine(and treat invalid ranges as absent).
function formatViewRange(view_range: number[] | undefined): { startLine: number; endLine: number | undefined } | undefined {
if (!Array.isArray(view_range) || view_range.length < 1) {
return undefined;
}
const startLine = view_range[0];
if (typeof startLine !== 'number' || !isFinite(startLine)) {
return undefined;
}
const rawEnd = view_range.length >= 2 ? view_range[1] : undefined;
const endLine = typeof rawEnd === 'number' && isFinite(rawEnd) && rawEnd >= 0 ? rawEnd : undefined;
return { startLine, endLine };
}
- Files reviewed: 1/1 changed files
- Comments generated: 3
Drop the EOF-sentinel handling and require a strictly valid two-element range (`length === 2`, integers, `start >= 0`, `end >= start`); fall back to the path-only display otherwise. Mirrors `formatViewToolInvocation` in the Copilot Chat extension and addresses review feedback on the `-1` end-of-file sentinel and the stale doc comment. (Written by Copilot) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Copilot CLI uses `-1` as the documented "to end of file" sentinel
for the second element of `view_range`. The Copilot Chat extension
doesn't handle this and either drops the range or renders "-1"
literally; do better here by rendering "from line {n} to the end".
(Written by Copilot)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
(Written by Copilot) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
anthonykim1
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the Copilot CLI's
viewtool is called with aview_rangeargument, the agent host now surfaces the line range in both the invocation message and the past-tense message, instead of just showing the file name.Before: "Reading file.ts" / "Read file.ts"
After: "Reading file.ts, lines 10 to 20" / "Read file.ts, lines 10 to 20" (or "line 10" for a single line)
All changes are in
src/vs/platform/agentHost/node/copilot/copilotToolDisplay.ts:ICopilotViewToolArgsextendingICopilotFileToolArgswith optionalview_range?: number[].formatViewRangehelper that defensively parses the[start, end]array (handling missing/-1end-of-file sentinels).Viewcases ingetInvocationMessageandgetPastTenseMessageto render the range when present.The
readpermission display path is unchanged — the Copilot SDK'sreadpermission request only carriespath+intention, notview_range. The line range only flows through thetool.execution_startparsedparameters.(Written by Copilot)