Skip to content

Handle blank lines when classifying reference spans - #85031

Merged
dibarbet merged 1 commit into
dotnet:mainfrom
dibarbet:dibarbet-fix-blank-reference-spans
Aug 26, 2026
Merged

Handle blank lines when classifying reference spans#85031
dibarbet merged 1 commit into
dotnet:mainfrom
dibarbet:dibarbet-fix-blank-reference-spans

Conversation

@dibarbet

@dibarbet dibarbet commented Aug 25, 2026

Copy link
Copy Markdown
Member

Summary

Test plan

  • dotnet test .\src\Features\Test\Microsoft.CodeAnalysis.Features.UnitTests.csproj --filter "FullyQualifiedName=Microsoft.CodeAnalysis.UnitTests.Classification.ClassifiedSpansAndHighlightSpanFactoryTests.ClassifyAsync_ReferenceOnBlankLine" --no-restore --verbosity minimal
  • dotnet build .\src\Features\Core\Portable\Microsoft.CodeAnalysis.Features.csproj --no-restore --verbosity minimal

Fixes dotnet/vscode-csharp#9482

Microsoft Reviewers: Open in CodeFlow

Fall back to the source line start when a reference is reported on a line without non-whitespace content.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@dibarbet
dibarbet marked this pull request as ready for review August 25, 2026 17:17
@dibarbet
dibarbet requested a review from a team as a code owner August 25, 2026 17:17
Copilot AI lite review requested due to automatic review settings August 25, 2026 17:17
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Roslyn’s reference-span classification logic to safely handle cases where a reported reference span lands on a line with no non-whitespace content (e.g., blank/whitespace-only lines), preventing a crash while producing a reasonable fallback span.

Changes:

  • Update GetLineSpanForReference to handle GetFirstNonWhitespacePosition() returning null by falling back to sourceLine.Start.
  • Add a focused regression unit test that exercises classification when the reference is on a blank first line.
Show a summary per file
File Description
src/Features/Core/Portable/ClassifiedSpansAndHighlightSpanFactory.cs Avoids null dereference when widening a reference span on blank/whitespace-only lines by falling back to the line start.
src/Features/Test/Classification/ClassifiedSpansAndHighlightSpanFactoryTests.cs Adds a regression test ensuring classification on a blank line returns empty classified spans and a default highlight span (and does not throw).

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Goto impl: Nullable object must have a value at ClassifiedSpansAndHighlightSpanFactory.GetLineSpanForReference

4 participants