Fix route document highlights across partial-class files#66770
Conversation
Agent-Logs-Url: https://github.com/dotnet/aspnetcore/sessions/f72c280a-9207-4fbe-8061-b03a4f2dd957 Co-authored-by: danroth27 <1874516+danroth27@users.noreply.github.com>
AspNetCoreDocumentHighlights cannot carry a Document reference, so every highlight span the route highlighter emits must belong to the active document. Spans from other syntax trees would be mis-mapped into the active document and highlight unrelated text. - Skip parameter/method DeclaringSyntaxReferences whose SyntaxTree differs from semanticModel.SyntaxTree. This obsoletes the per-tree semantic model branching introduced earlier in this PR. - Tighten the cross-file regression test to assert exactly the route literal span is highlighted (no stray spans from the handler file). - Rename the test to describe the desired behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Pushed a follow-up commit (14bb9c2) that addresses the latent correctness issue and tightens the test. Why a follow-up was needed
Both spans are Change In Trade-off: the parameter highlight in the other file is not surfaced. That's a feature gap rather than a bug — the API simply has no way to express cross-document highlights from an embedded language highlighter. The route literal span is still highlighted, and there is no crash. A complete cross-file highlighting experience would require extending Roslyn's embedded-language highlighter contract; out of scope here. Test
|
Fix route document highlights across partial-class files
Prevent cross-tree semantic lookup in route highlighter
Description
Document highlights could throw
Syntax node is not within syntax treewhen a Minimal API route mapping and its handler method are in different files of the same partial class. This change makes symbol resolution tree-correct and adds a regression test for that shape.Analyzer fix (RoutePatternHighlighter)
Compilation.GetSemanticModel(...)for cross-file declarations.Regression coverage
MapPost(..., LoadAsync)whereMap...andLoadAsyncare in separate partial-class files.