Bugfix: How to access ExtensionContext.globalState from WebviewViewP...

Documentation for Sessions

🐛 Bugfix: How to access ExtensionContext.globalState from WebviewViewP...

Date: 2026-02-05
Time: 04:39:03 UTC
Session: editor2-89.9
Agent: storage
Confidence: 95%
Status: ✅ Documented


📋 Decision Context

Question:

How to access ExtensionContext.globalState from WebviewViewProvider?

Task: VSCode Extension Context Access


🎯 Decision Made

Chosen:

Pass context to constructor and store as property

Options Considered:

  1. Access via static singleton
  2. Pass context to constructor and store as property
  3. Use getExtension() API
  4. Import from extension.ts

💭 Reasoning

WebviewViewProvider classes need explicit access to ExtensionContext for globalState operations. The constructor receives extensionUri by default, but context must be explicitly passed: 1) Update constructor signature: constructor(extensionUri: vscode.Uri, context: vscode.ExtensionContext), 2) Store as class property: private readonly extensionContext: vscode.ExtensionContext, 3) Update registration: new MainPanelProvider(context.extensionUri, context). Common mistake: using _context parameter from resolveWebviewView() which is WebviewViewResolveContext, NOT ExtensionContext - they are different types!


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation