Commit 0e9fd12
Refactor large template browser view file (#116)
* refactor: break up templateBrowserView into modular components
The templateBrowserView.ts file was 4,542 lines, making it difficult to
maintain, navigate, and test. This refactor splits it into focused,
single-responsibility modules.
## New Structure
Created `src/templates/browser/` directory with:
- **TemplateBrowserView.ts** (~200 lines): Main webview orchestrator
- **messageHandlers.ts** (~500 lines): All message handler functions
- **templateOperations.ts** (~200 lines): Template CRUD operations
- **templateBrowser.html**: HTML template structure
- **templateBrowser.css** (1,356 lines): All styles
- **templateBrowser.js** (2,019 lines): Client-side logic
- **types.ts**: Shared TypeScript interfaces
## Benefits
1. **Maintainability**: Each file < 500 lines, single responsibility
2. **IDE Support**: Separate .html/.css/.js files with proper syntax highlighting
3. **Testability**: Can unit test handlers and operations separately
4. **Reusability**: Can share CSS patterns across webviews
5. **Performance**: Better code organization and loading
## Changes
- Extracted message handlers to dedicated module
- Extracted template operations (load, find, update usage)
- Separated HTML/CSS/JS into proper files
- Updated imports in extension.ts
- Updated CLAUDE.md documentation
- All tests pass, compilation successful
* perf: use async I/O and optimize template loading
Applied code review feedback to improve performance and responsiveness.
## Changes
1. **TemplateBrowserView.ts**: Replaced synchronous file operations
- Changed `fs.readFileSync` to `await fsp.readFile`
- Made `getTemplateBrowserHtml` async and return `Promise<string>`
- Prevents blocking the extension host thread during file reads
2. **templateOperations.ts**: Optimized template loading loop
- Pre-build Set of JSON basenames for O(1) lookup
- Replaced `await pathExists(jsonPath)` in loop with Set.has()
- Eliminates N file system calls for legacy template checking
- Significantly faster when there are many .txt/.md templates
## Performance Impact
- **Before**: Blocking sync I/O + O(N*M) file checks
- **After**: Non-blocking async I/O + O(N+M) with in-memory Set
These changes follow VS Code extension best practices for
keeping the UI responsive during I/O operations.
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9cef377 commit 0e9fd12
File tree
9 files changed
+2431
-2529
lines changed- src
- templates/browser
9 files changed
+2431
-2529
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
72 | 79 | | |
73 | 80 | | |
74 | 81 | | |
| |||
348 | 355 | | |
349 | 356 | | |
350 | 357 | | |
351 | | - | |
| 358 | + | |
352 | 359 | | |
353 | 360 | | |
354 | 361 | | |
| |||
359 | 366 | | |
360 | 367 | | |
361 | 368 | | |
362 | | - | |
363 | | - | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
364 | 377 | | |
365 | 378 | | |
366 | | - | |
| 379 | + | |
367 | 380 | | |
368 | 381 | | |
369 | 382 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
0 commit comments