This document targets developers who want to build, debug or extend the PostIt VS Code extension.
PostIt is a minimal Webview-based VS Code extension that offers small sticky notes persisted locally using ExtensionContext.globalState. The extension exposes a status-bar command (postit.toggle) which opens a WebviewPanel beside the editor containing the note UI.
Goals:
- Very lightweight runtime and build-time configuration
- Simple local persistence (no network)
- Webview handshake to avoid race conditions
src/extension.ts— extension entry point, registers commands and manages the WebviewPanel lifecycle.src/html-template.ts— produces the Webview HTML/CSS/JS. The webview sends/receives messages viapostMessage.media/— static assets (icon.svg).tsconfig.json— TypeScript configuration (incremental build enabled, no sourcemaps for a lighter build).
Persistence:
- Key:
postit.notesstored incontext.globalStateas an array of notes:{ text: string, color: string }[].
Webview handshake:
- Webview posts
{ type: 'ready' }when initialized. - Extension replies with
{ type: 'init', value: notes, theme }.
Message protocol (webview <-> extension)
- From webview to extension:
ready— webview loaded and ready for initsave{ index, value, color } — save note at indexadd{ value, color } — add a new notedelete{ index } — delete note (no confirmation)requestDelete{ index } — extension shows modal confirmation then may deletechangeColor{ index, color } — change colorreorder{ value: Array<{text,color}> } — reorder notes array
- From extension to webview:
init{ value: notes, theme } — initial payloadadded{ index, value, color } — at add, extension returns the assigned index so webview can setdata-indextheme{ value } — theme changed event
src/extension.ts— command registration, WebviewPanel creation (retainContextWhenHidden: falseby default), message handling and globalState updates.src/html-template.ts— inline HTML/CSP/nonce generation and webview script.media/icon.svg— activity bar / fallback icon.tsconfig.json— lightweight settings used for faster incremental builds.package.json— contributes commands and configuration keys.
- cd into extension directory:
cd extension-vscode
- Install exact dev deps from lockfile (reproducible):
npm ci
- Build:
npm run build
- Launch Extension Development Host
- From root of the workspace or extension folder:
code --extensionDevelopmentPath=., or press F5 in the extension VS Code debug configuration.
- From root of the workspace or extension folder:
Useful scripts (from package.json):
npm run build— compile TypeScript (tsc -p ./)npm run watch— tsc watch mode
tsconfig.jsonis optimized for speed:incremental: true,sourceMap: false,declaration: false.- If you enable stricter checks for development, consider toggling
strictornoUnusedLocalslocally.
- Ensure
npm run buildcompletes andout/contains the compiled extension. - Use
vsceor@vscode/vsceto package and publish to Marketplace.
retainContextWhenHiddenis set tofalseto reduce memory usage while the Webview is hidden (trades off keeping live DOM state when hidden).- Webview handshake avoids unnecessary re-renders and race conditions.
tsconfigis tuned for incremental builds and minimal emitted artifacts.
- To embed the full UI inside the Activity Bar view (instead of opening a floating panel), implement a
WebviewViewProviderand render the same HTML. Be mindful of available height andretainContextWhenHiddensemantics.
- Error "There is no data provider registered that can provide view data." — indicates a contributed view exists but no
WebviewViewProvideris registered. Ensurevscode.window.registerWebviewViewProvider('viewId', provider)is called during activation if you contributeviewsinpackage.json.
Open issues or PRs against the repository. Keep changes small and focused on low-runtime overhead.
If you want, I can also add a DEVELOPMENT.md with step-by-step debugging scenarios and a minimal test skeleton. Want that?