Skip to content

Conversation

@jsonify
Copy link
Owner

@jsonify jsonify commented Nov 16, 2025

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

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
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jsonify, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a significant refactoring of the template browser view. The primary goal was to decompose a single, excessively large TypeScript file into a set of smaller, more manageable modules. This architectural change aims to enhance the overall maintainability, testability, and clarity of the template browser's codebase by clearly separating responsibilities, such as UI presentation, client-side interactivity, and backend data operations, into distinct components.

Highlights

  • Major Refactoring: The monolithic templateBrowserView.ts file, which was over 4,500 lines long, has been refactored into a modular structure, significantly improving code organization.
  • Separation of Concerns: HTML, CSS, and client-side JavaScript for the webview are now separated into dedicated .html, .css, and .js files, enhancing IDE support and clarity.
  • Backend Logic Extraction: Message handling functions and template CRUD operations have been extracted into messageHandlers.ts and templateOperations.ts respectively, promoting single responsibility for each module.
  • Improved Maintainability and Testability: The new modular architecture makes the template browser's codebase easier to understand, maintain, and unit test, aligning with modern software engineering best practices.
  • Documentation Update: The CLAUDE.md documentation has been updated to reflect the new modular architecture, detailing the new directory structure and its benefits.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is an excellent refactoring that dramatically improves the maintainability of the template browser feature. Splitting the monolithic templateBrowserView.ts file into focused, single-responsibility modules is a great move. The new structure with separate files for orchestration, message handling, data operations, and front-end assets (HTML, CSS, JS) is much cleaner and easier to work with.

I've left a few comments with suggestions for improvement:

  • A critical fix for a ReferenceError in the client-side JavaScript.
  • A couple of performance optimizations to use asynchronous I/O and avoid file system calls inside a loop.

Overall, this is a high-quality pull request that significantly reduces technical debt. Great work!

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.
@jsonify jsonify merged commit 0e9fd12 into main Nov 16, 2025
8 checks passed
jsonify pushed a commit that referenced this pull request Nov 16, 2025
jsonify added a commit that referenced this pull request Nov 16, 2025
This reverts commit 0e9fd12.

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants