Skip to main content
Views are the building blocks of VS Code’s sidebar, panel, and auxiliary bar. They provide custom UI for displaying hierarchical data, trees, webviews, and other content.

Understanding Views

A view is a UI component that:
  • Lives inside a view container (sidebar, panel, or auxiliary bar)
  • Can display trees, lists, webviews, or custom content
  • Has a title, icon, and optional actions
  • Can be shown, hidden, moved, or resized by users
  • Integrates with VS Code’s layout system
Views are registered through the IViewsRegistry and managed by the IViewDescriptorService.

View Architecture

View Hierarchy

View Locations

Sidebar (ViewContainerLocation.Sidebar)
  • Primary location for navigation and exploration
  • Examples: Explorer, Search, Source Control, Extensions
  • Typically on the left (or right if configured)
Panel (ViewContainerLocation.Panel)
  • Secondary location for tools and output
  • Examples: Terminal, Problems, Output, Debug Console
  • Typically at the bottom
Auxiliary Bar (ViewContainerLocation.AuxiliaryBar)
  • Additional sidebar for extra views
  • Can be placed opposite the main sidebar
  • For overflow or secondary content

Creating a View Container

Step 1: Register the View Container

Step 2: Create a View Pane

Step 3: Register the View

Creating a Tree View

For hierarchical data, use a tree view:

View Pane Container

The ViewPaneContainer manages multiple view panes:

View Descriptor Service

The ViewDescriptorService manages view registration and location:

Real-World Example: Debug Views

From the Debug contribution:

View Actions

Add actions to view titles:

View Context

Use context keys to control view visibility:

Webview Views

For custom HTML/CSS/JS content:

Best Practices

  1. Lazy Loading: Use when context keys to only show views when relevant
  2. Proper Disposal: Always dispose resources in dispose() method
  3. Responsive Layout: Handle layoutBody() for proper resizing
  4. State Persistence: Use storage service to save view state
  5. Performance: Virtualize large lists/trees for better performance
  6. Accessibility: Ensure keyboard navigation and screen reader support
  7. Context Keys: Use specific context keys for view-specific commands
  8. Error Handling: Show user-friendly messages for errors

Debugging Views

Use these techniques to debug views:

Next Steps

Tree Views

Learn more about creating tree views

Webviews

Create rich HTML/CSS/JS views with webviews

Commands

Add commands and actions to your views

Themes

Style your views with theme colors