Skip to content

Resolve diagnostic node mapping for value entities in getNodeForTarget#10921

Open
Copilot wants to merge 8 commits into
mainfrom
copilot/fix-html-program-viewer-crash
Open

Resolve diagnostic node mapping for value entities in getNodeForTarget#10921
Copilot wants to merge 8 commits into
mainfrom
copilot/fix-html-program-viewer-crash

Conversation

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Diagnostics were resolving targets as if all entities were types, which could surface the wrong source location when the target was a value (notably function values). This change makes node extraction entity-aware so diagnostics map to the actual originating node for values and mixed constraints.

  • Problem context

    • TypeSpecDiagnosticTarget includes Entity, but getNodeForTarget only handled symbols/nodes/types, so value entities could be rendered with misleading locations.
  • Compiler change: entity-aware target resolution

    • getNodeForTarget now explicitly handles entityKind branches:
      • Typetarget.node
      • Value → value node (when present) with fallback to target.type.node
      • MixedParameterConstraintnode ?? type.node ?? valueType.node (documented precedence)
      • Indeterminatetarget.type.node
    • Added getValueNode(value) to centralize node extraction for value kinds that carry syntax nodes (Function, ObjectValue, ArrayValue).
  • Coverage added

    • Extended core diagnostics tests to cover:
      • function value node preference
      • value → type-node fallback
      • object value node handling
      • mixed-constraint precedence
      • indeterminate entity node resolution
if ("entityKind" in target) {
  switch (target.entityKind) {
    case "Type":
      return target.node;
    case "Value":
      return getValueNode(target) ?? target.type.node;
    case "MixedParameterConstraint":
      return target.node ?? target.type?.node ?? target.valueType?.node;
    case "Indeterminate":
      return target.type.node;
  }
}

Copilot AI and others added 2 commits June 8, 2026 18:52
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@pkg-pr-new

pkg-pr-new Bot commented Jun 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@10921
npm i https://pkg.pr.new/@typespec/html-program-viewer@10921

commit: 6ff6ca5

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot AI changed the title Prevent html-program-viewer crash when search renders malformed type nodes Guard html-program-viewer search/tree icon rendering against missing type kind Jun 8, 2026
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Jun 8, 2026
Copilot AI and others added 4 commits June 8, 2026 20:02
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot AI changed the title Guard html-program-viewer search/tree icon rendering against missing type kind Resolve diagnostic node mapping for value entities in getNodeForTarget Jun 8, 2026
@timotheeguerin timotheeguerin marked this pull request as ready for review June 8, 2026 20:15
@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

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

Labels

compiler:core Issues for @typespec/compiler ui:type-graph-viewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants