Skip to content

Fix diagnostics on empty lines being invisible to get_errors tool#4025

Merged
roblourens merged 4 commits intomainfrom
copilot/fix-get-errors-tool-blank-lines
Mar 2, 2026
Merged

Fix diagnostics on empty lines being invisible to get_errors tool#4025
roblourens merged 4 commits intomainfrom
copilot/fix-get-errors-tool-blank-lines

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 26, 2026

Diagnostics reported on empty/blank lines (e.g., a trailing newline at EOF where a compiler reports a missing }) were silently dropped from the get_errors tool output and DiagnosticDescription prompts.

Root cause: DiagnosticDescription.render() extracted the line content and trimmed whitespace. For empty lines, this produced "", causing the if (code) guard to return an empty JSX fragment — swallowing the diagnostic message entirely. The model saw an <errors> tag with no content.

Changes

  • diagnosticsContext.tsx — Refactored DiagnosticDescription.render() to always emit the diagnostic message. When the line has content, renders the existing This code at line N / <CodeBlock> / has the problem reported format; when empty, renders At line N / has the problem reported without a code block:
return <>
    {code
        ? <>This code at line {range.start.line + 1}<br /><CodeBlock code={code} uri={document.uri} shouldTrim={false} /><br /></>
        : <>At line {range.start.line + 1}<br /></>}
    has the problem reported:<br />
    <Tag name='compileError'>{d.message}</Tag>
</>;
  • getErrorsTool.spec.tsx — Added test with a file containing a diagnostic on a trailing empty line, verifying it appears in tool output.
Original prompt

This section details on the original issue you should resolve

<issue_title>get_errors tool and "Explain" action ignore diagnostics on empty lines</issue_title>
<issue_description>- Copilot Chat Extension Version: 0.37.1

  • VS Code Version: 1.109.0
  • OS Version: Windows_NT x64 10.0.26100
  • Feature (e.g. agent/edit/ask mode): agent mode
  • Selected model (e.g. GPT 4.1, Claude 3.7 Sonnet): Claude Opus 4.5 and Claude Opus 4.6 (both affected)
  • Logs: N/A (reproducible without logs)

Bug Summary

When a compiler error is reported on an empty/blank line, Copilot cannot see it. This affects both:

  • The get_errors agent tool — returns empty results for the file
  • The "Explain" quick action — not available in the Problems panel for that error

Steps to Reproduce

  1. Create any AL codeunit missing its closing }
  2. Ensure the file has a trailing empty line at EOF
  3. AL compiler reports Syntax error, '}' expected [AL0104] on the empty line (e.g., line 328)
  4. VS Code Problems panel shows the error correctly
  5. In Copilot chat, the get_errors tool returns no errors for this file
  6. In the Problems panel, the "Explain" action is missing for this error
  7. Delete the trailing empty line so the error moves to the last content line (e.g., line 327)
  8. Now get_errors returns the error, and "Explain" action appears

Expected Behavior

Errors reported on empty lines should be visible to Copilot agent tools and actions, same as errors on lines with content.

Root Cause Hypothesis

Copilot's diagnostics consumption layer appears to filter out errors when the referenced line has no content — possibly when trying to extract a code snippet to include with the error context.

Additional Testing

  • Confirmed the error appears correctly in the VS Code Problems panel in both scenarios
  • Confirmed inline syntax errors (e.g., missing quotes) on content lines ARE visible to Copilot
  • Confirmed this affects multiple models identically (it's a tool issue, not model issue)</issue_description>

<agent_instructions>Can you figure out why these diagnostics may be filtered out</agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…cDescription

When a diagnostic is reported on an empty/blank line (e.g., a trailing
empty line at EOF), the DiagnosticDescription component was returning
an empty JSX fragment because the code content was empty after trimEnd().
This caused the entire diagnostic (including its error message) to be
invisible to the AI model.

Fixed by removing the empty-line guard and always emitting the diagnostic
message, just without a code block when the line has no content.

Also adds a test case for diagnostics reported on empty lines.

Co-authored-by: roblourens <323878+roblourens@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix get_errors tool and explain action ignoring diagnostics on empty lines Fix diagnostics on empty lines being invisible to get_errors tool Feb 26, 2026
@roblourens roblourens marked this pull request as ready for review March 2, 2026 05:33
Copilot AI review requested due to automatic review settings March 2, 2026 05:33
@vs-code-engineering vs-code-engineering Bot added this to the March 2026 milestone Mar 2, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an issue in the Copilot Chat extension’s diagnostics prompting/tooling where diagnostics reported on blank lines were being omitted from rendered diagnostic text (impacting get_errors output and related prompt generation).

Changes:

  • Updated DiagnosticDescription.render() to always emit the diagnostic message, even when the extracted line content is empty/blank.
  • Added a GetErrorsTool test case that creates a diagnostic on a trailing empty line and snapshots the tool output.
  • Updated snapshots to reflect the new (now-visible) empty-line diagnostic output.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/extension/prompts/node/inline/diagnosticsContext.tsx Ensures diagnostic messages render even when the associated source line is empty/blank.
src/extension/tools/node/test/getErrorsTool.spec.tsx Adds a regression test covering diagnostics reported on an empty line.
src/extension/tools/node/test/snapshots/getErrorsTool.spec.tsx.snap Updates snapshots to include the newly reported empty-line diagnostic.

Comment thread src/extension/tools/node/test/getErrorsTool.spec.tsx Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@roblourens roblourens enabled auto-merge March 2, 2026 05:38
@roblourens roblourens added this pull request to the merge queue Mar 2, 2026
Merged via the queue into main with commit 077ce29 Mar 2, 2026
19 checks passed
@roblourens roblourens deleted the copilot/fix-get-errors-tool-blank-lines branch March 2, 2026 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_errors tool and "Explain" action ignore diagnostics on empty lines

4 participants