Skip to content

feat: Refactor hard-coded HTML/CSS/JS in chartViewProvider.ts (lines 191-1466) #2

@Anselmoo

Description

@Anselmoo

Problem

Lines 191 to 1466 in src/providers/chartViewProvider.ts contain approximately 1,275 lines of hard-coded HTML, CSS, and JavaScript embedded directly in a TypeScript string literal within the _getHtmlForWebview() method.

This approach creates several maintenance and development challenges:

  • Difficult to maintain: Any UI changes require editing a massive string literal with escaped characters
  • Hard to test: The embedded webview logic cannot be easily unit tested or verified
  • Poor readability: Syntax highlighting and IDE support is limited within string literals
  • Error-prone: Easy to introduce syntax errors or miss closing tags in the embedded code
  • Hard to review: Code reviews of UI changes are challenging due to the string literal format

Suggested Refactoring

  1. Extract HTML/CSS to separate template files - Move the webview HTML structure to dedicated .html and .css files in a media/ or templates/ directory
  2. Extract JavaScript logic - Move the embedded JavaScript to a separate .js file that can be loaded as a webview resource
  3. Use proper templating - Consider using a simple template system to inject dynamic values (configuration, URIs, nonces) into the HTML
  4. Modularize webview scripts - Break down the monolithic inline script into smaller, testable modules
  5. Add tests - Once extracted, add unit tests for the webview logic and integration tests for the chart rendering

Benefits

  • Significantly improved code maintainability and readability
  • Easier to extend with new chart features
  • Better IDE support and syntax checking
  • Ability to test webview logic independently
  • Simpler code reviews and collaboration

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions