Skip to content

Type graph: hide library types and show where a type comes from - #11810

Open
Timothee Guerin (timotheeguerin) wants to merge 2 commits into
microsoft:mainfrom
timotheeguerin:type-graph-viewer-upgrades
Open

Type graph: hide library types and show where a type comes from#11810
Timothee Guerin (timotheeguerin) wants to merge 2 commits into
microsoft:mainfrom
timotheeguerin:type-graph-viewer-upgrades

Conversation

@timotheeguerin

@timotheeguerin Timothee Guerin (timotheeguerin) commented Sep 1, 2026

Copy link
Copy Markdown
Member

The type graph opens on a wall of TypeSpec, Reflection, Http, Azure.*… namespaces, and your own service is one line lost in the middle. Once you find a type there is also no way to tell where it came from, or to get back to it in the editor.

Fixes Azure/typespec-azure#1904

  • Library and compiler types are hidden by default. The navigation pane gets a compact toolbar with a single toggle to bring them back (or the new defaultOnlyProjectCode prop for hosts that want everything). Navigating to a hidden type — a link, ⌘⇧F, or a shared type-graph:path — still shows it, with a slim notice that the tree is not listing it, rather than a dead end.
  • Every type says where it was declared: Your code main.tsp:5, @typespec/http lib/main.tsp:51, Standard library. In the playground, clicking that badge on your own types selects the declaration in the editor (new onRevealSource prop on TypeGraph, wired by the playground to Monaco).

type-graph.png

@pkg-pr-new

pkg-pr-new Bot commented Sep 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/html-program-viewer@11810
npm i https://pkg.pr.new/@typespec/playground@11810

commit: cc0c35b

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/html-program-viewer
  • @typespec/playground
Show changes

@typespec/playground - feature ✏️

Clicking the source location of a type in the type graph now selects its declaration in the editor.

@typespec/html-program-viewer - fix ✏️

Fix scrollbars showing in the type graph breadcrumb bar. The path now scrolls horizontally without a scrollbar and keeps the selected node in view.

@typespec/html-program-viewer - feature ✏️

Hide the types coming from the compiler standard library and the loaded libraries from the type graph navigation tree. They can be shown again with the new toolbar button of the navigation pane, or by default with the new defaultOnlyProjectCode prop. Navigating to one of those types (from a link or a saved path) still shows it, with a notice that the tree does not list it.

@typespec/html-program-viewer - feature ✏️

Show where a type was declared (your code, the standard library or a library) in the type view, with its file and line. When the host provides the new onRevealSource callback, clicking the badge of a type declared in your code reveals its declaration.

@azure-sdk-automation

azure-sdk-automation Bot commented Sep 1, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Hide the compiler and library types behind a toolbar toggle, and show where
a type is declared and let the host reveal it in its editor.

Fixes Azure/typespec-azure#1904
@timotheeguerin Timothee Guerin (timotheeguerin) changed the title Type graph: hide library types, show where a type comes from, kind icons Type graph: hide library types and show where a type comes from Sep 2, 2026
@timotheeguerin
Timothee Guerin (timotheeguerin) marked this pull request as ready for review September 3, 2026 17:27
Copilot AI lite review requested due to automatic review settings September 3, 2026 17:27

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.

🟡 Changes recommended

There are a few small but user-facing typos in new changelog/doc comments that should be corrected before merging.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves the type graph experience in @typespec/html-program-viewer and wires it up in the @typespec/playground so users can focus on their own API types and quickly see (and optionally navigate to) where a type was declared.

Changes:

  • Hide compiler/library namespaces in the type graph navigation tree by default, with a toolbar toggle and “hidden by filter” notice for deep-linked library types.
  • Add a “type origin” badge to type view showing whether a type comes from user code, standard library, or a library (including file + line when available).
  • Add an onRevealSource callback path from the playground host through output-viewers to select/reveal the declaration in Monaco.
File summaries
File Description
packages/playground/src/react/types.ts Extends OutputViewerProps with onRevealSource callback type.
packages/playground/src/react/playground.tsx Wires onRevealSource to Monaco selection/reveal behavior.
packages/playground/src/react/output-view/type-graph-viewer.tsx Passes onRevealSource through to the TypeGraph component.
packages/playground/src/react/output-view/output-view.tsx Threads onRevealSource through OutputView component layers.
packages/html-program-viewer/src/react/use-tree-navigation.tsx Implements project-only filtering, toggling state, and “selection hidden” behavior; exports helpers for tests.
packages/html-program-viewer/src/react/type-view/type-view.tsx Adds the new TypeOrigin badge into the type header UI.
packages/html-program-viewer/src/react/type-view/type-view.module.css Header layout tweaks (wrap/gap) to accommodate the new origin badge.
packages/html-program-viewer/src/react/type-view/type-origin.tsx New component to compute and display a type’s origin + optional reveal action.
packages/html-program-viewer/src/react/type-view/type-origin.test.tsx Unit tests covering origin labeling, location display, and reveal behavior.
packages/html-program-viewer/src/react/type-view/type-origin.module.css Styling for origin badge and reveal button hover/focus.
packages/html-program-viewer/src/react/type-graph.tsx Adds defaultOnlyProjectCode/onRevealSource, “hidden by filter” notice, and provides reveal context.
packages/html-program-viewer/src/react/type-graph.module.css Moves scrolling responsibility to the tree container; adds styling for the hidden-by-filter notice.
packages/html-program-viewer/src/react/type-filter.ts New cached predicate for “is project type” determination.
packages/html-program-viewer/src/react/tree-navigation.tsx Adds a compact toolbar with a toggle to show/hide library types.
packages/html-program-viewer/src/react/tree-navigation.module.css Layout/styling for the new tree navigation toolbar and scroll container.
packages/html-program-viewer/src/react/tree-filter.test.tsx Tests for filtered vs full tree behavior, default behavior, toggle, and hidden selection messaging.
packages/html-program-viewer/src/react/reveal-source-context.ts New context for wiring host “reveal source” behavior into the UI.
packages/html-program-viewer/src/react/list-type-view/list-type-view.tsx Improves empty state when project-only filter hides all types; offers “Show everything”.
packages/html-program-viewer/src/react/list-type-view/list-type-view.module.css Adds styling for the new empty-state layout.
.chronus/changes/type-graph-type-origin-2026-9-1-12-0-2.md Changelog entry for type-origin badge + reveal support.
.chronus/changes/type-graph-only-my-code-2026-9-1-11-42-0.md Changelog entry for default project-only tree filter + toggle.
.chronus/changes/playground-type-graph-reveal-source-2026-9-1-13-30-0.md Changelog entry for playground wiring of reveal-to-editor.
Review details
  • Files reviewed: 22/22 changed files
  • Comments generated: 5
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

- "@typespec/html-program-viewer"
---

Hide the types coming from the compiler standard library and the loaded libraries from the type graph navigation tree. They can be shown again with the new toolbar button of the navigation pane, or by default with the new `defaultOnlyProjectCode` prop. Navigating to one of those types(from a link or a saved path) still shows it, with a notice that the tree does not list it.
- "@typespec/html-program-viewer"
---

Show where a type was declared(your code, the standard library or a library) in the type view, with its file and line. When the host provides the new `onRevealSource` callback, clicking the badge of a type declared in your code reveals its declaration.
Comment on lines +3 to +6
/**
* Create a predicate telling whether a type was declared in the user project(as opposed to the compiler standard library or a library).
* Results are cached as the same type is likely to be queried multiple times when building the type graph.
*/
Comment on lines +34 to +37
/**
* Called when the user clicks the source location of a type declared in their code.
* Provide it when the host can reveal that location(e.g. an editor showing the project files).
*/
Comment on lines +75 to +79
const relative = path.slice(index + marker.length);
const segments = relative.split("/");
// Drop the package name(`@scope/name` or `name`) to keep the path relative to the package root.
return segments.slice(segments[0].startsWith("@") ? 2 : 1).join("/");
}
The breadcrumb bar only set overflow-y, which per spec makes overflow-x
compute to auto too, so a long path showed a horizontal scrollbar and the
taller search combobox a vertical one. Only scroll horizontally, without a
scrollbar, and keep the selected node in view.

Also fix the missing spaces before parentheses reported in review.
Copilot AI review requested due to automatic review settings September 3, 2026 17:55

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.

🔵 Needs a closer look

The project-type predicate cache is currently incorrect for false values and one changeset filename includes an invalid timestamp segment (2026-0-...).

Review details

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

packages/html-program-viewer/src/react/type-filter.ts:13

  • createIsProjectTypePredicate() cache check treats false as a cache miss (cache.get() returns false, which is !== undefined), so non-project types will be recomputed every time. Use cache.has() (or a sentinel) to correctly cache both true and false.
    .chronus/changes/type-graph-breadcrumb-scroll-2026-0-24-0-0-0.md:1
  • The changeset filename type-graph-breadcrumb-scroll-2026-0-24-0-0-0.md contains an invalid timestamp segment (2026-0-... uses month 0). Other changesets in this PR use 1-based months (e.g. 2026-9-...), so this looks like a typo and can make changelog history confusing or tooling brittle; please rename/regenerate this changeset with a valid date segment.
  • Files reviewed: 25/25 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Playground] Have a "Show only my code" toggle in TypeGraph View

2 participants