How janisdd/vscode-edit-csv works
Project Type and Purpose
• This is a VS Code extension (plus an optional standalone web app) that provides an Excel-like UI for editing CSV/TSV files.
• Core idea: The extension hosts a Webview in VS Code. The Webview runs browser‐side code (HTML/TS/CSS) that displays and edits the CSV in a Handsontable grid. The extension backend reads/writes the actual CSV file and mediates communication to/from the Webview.
High-Level File Structure
• /src: extension backend TypeScript (commands, file I/O, VS Code API integration).
• /csvEditorHtml: Webview frontend source and standalone web-app source (HTML, TS, CSS, build scripts, tests).
• /out: compiled extension backend JavaScript.
• /thirdParty: packaged third-party libs for the Webview (Papaparse, Handsontable, Mousetrap, Big.js, regression.js, etc.).
Key Components
a. VS Code Host
• VS Code Extension Host process
• Presents command palette entries (“Edit as CSV”, “Edit With Config”)
b. Extension Backend
• extension.ts: registers commands, listens for Webview messages
• configurationHelper.ts: builds configuration JSON
• instanceManager.ts: tracks open editor instances and URIs
• getHtml.ts: inlines the Webview’s HTML template with scripts and styles
• util.ts: helpers for chunking large files, handling settings
c. File System
• Reads the CSV/TSV file from disk
• Writes back on “Apply” or “Apply and Save”
d. Webview Frontend
• index.html + injected config
• main.ts/browser.ts, ui.ts: bootstraps the Handsontable grid
• io.ts: handles postMessage to/from the extension
• autoFill.ts, progressbar.ts, findWidget.ts: UI modules
• CSS files: themes (light, dark, high_contrast), settingsOverwrite.css
• thirdParty libs (Papaparse, Handsontable, etc.)
e. Message Bus
• Extension → Webview: webview.postMessage({ chunks, config })
• Webview → Extension: vscode.postMessage({ csvText, command })
Relationships and Data Flow
1. User issues “Edit as CSV” in VS Code
2. Extension reads file, splits it into chunks if large
3. Extension loads Webview, injects HTML + scripts + config
4. Extension calls webview.postMessage() with file chunks + config
5. Webview receives message, reassembles text, uses Papaparse to parse CSV → model
6. Handsontable renders the grid; user edits cells
7. On “Apply”: Webview serializes grid → CSV text, posts message back
8. Extension receives message, concatenates text, writes to disk
9. On “Apply and Save”: extension also issues file.save()
10. Commands like “Read again” re-inject saved config without re-reading disk
Architectural Patterns and Design Principles
• Separation of Concerns:
• Backend (Node/VS Code API) vs. Frontend (Browser/Webview)
• InstanceManager (state), ConfigurationHelper (config), IO vs. UI modules
• Message-Driven Integration: clear, one-way and two-way postMessage channels
• Modular Frontend: discrete UI features (auto-fill, find widget, progress bar)
• Single Source of Truth for configuration: injected JSON, read-only in Webview