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
View Container Locations
View Container Locations
Sidebar (
ViewContainerLocation.Sidebar)- Primary location for navigation and exploration
- Examples: Explorer, Search, Source Control, Extensions
- Typically on the left (or right if configured)
ViewContainerLocation.Panel)- Secondary location for tools and output
- Examples: Terminal, Problems, Output, Debug Console
- Typically at the bottom
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
TheViewPaneContainer manages multiple view panes:
View Descriptor Service
TheViewDescriptorService 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
View Development Best Practices
View Development Best Practices
- Lazy Loading: Use
whencontext keys to only show views when relevant - Proper Disposal: Always dispose resources in
dispose()method - Responsive Layout: Handle
layoutBody()for proper resizing - State Persistence: Use storage service to save view state
- Performance: Virtualize large lists/trees for better performance
- Accessibility: Ensure keyboard navigation and screen reader support
- Context Keys: Use specific context keys for view-specific commands
- 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