Skip to content

[FEATURE]: Add pre-commit hook to ensure VSCode recommended extensions are synced with devcontainer configuration #239

@smorin

Description

@smorin

Feature Type

New Functionality

Priority/Impact

High

Problem Statement

Currently, there's no automated way to ensure that VSCode extensions listed in .vscode/extensions.json are properly synced with the extensions configured in .devcontainer/devcontainer.json. This can lead to inconsistent development environments where some extensions are recommended but not automatically available in the devcontainer. Developers may set up their local VSCode with recommended extensions but find that the same extensions aren't available when working in the devcontainer, causing confusion and reducing development efficiency.

Requires Proposal

No, straightforward implementation

Proposed Solution

Create a Python validation script in the scripts/ directory that:

  1. Script: scripts/check_extension_sync.py

    • Reads both .vscode/extensions.json and .devcontainer/devcontainer.json files
    • Compares the recommended extensions in both configurations
    • Validates that ALL extensions from .vscode/extensions.json are present in the devcontainer configuration
    • Provides clear, actionable error messages when extensions are out of sync
  2. Pre-commit Hook Integration:

    • Add the script to the existing pre-commit configuration
    • Fails the commit if extensions are not in sync
    • Forces engineers to manually update the appropriate configuration files
  3. Just Recipe: Add a justfile recipe:

    # Check if VSCode recommended extensions are synced with devcontainer
    check-extension-sync:
        uvx scripts/check_extension_sync.py
    
  4. Error Reporting Features:

    • Lists specific extension IDs that are missing
    • Clearly indicates which file needs to be updated (devcontainer.json)
    • Provides easy-to-follow instructions for resolving sync issues
    • Example output:
      ❌ VSCode extensions not synced with devcontainer configuration!
      
      Missing from .devcontainer/devcontainer.json:
      - ms-python.python
      - ms-python.black-formatter
      
      To fix: Add these extensions to the "customizations.vscode.extensions" 
      array in .devcontainer/devcontainer.json
      
  5. Implementation Details:

    • Cross-platform compatibility (macOS, Linux, Windows)
    • Robust JSON parsing with error handling
    • Integration with existing pre-commit hook workflow
    • Option to run manually: uvx scripts/check_extension_sync.py

Script Specifications

  • Location: scripts/check_extension_sync.py
  • Execution: Run with uv run and integrated into pre-commit hooks
  • Exit Codes:
    • 0: Extensions are in sync
    • 1: Extensions are out of sync (with detailed error message)
    • 2: Script error (file not found, parsing error, etc.)

File Parsing Requirements

  • Parse .vscode/extensions.json to extract recommended extensions
  • Parse .devcontainer/devcontainer.json to extract configured extensions from customizations.vscode.extensions
  • Handle both string arrays and objects with version specifications
  • Gracefully handle missing files or malformed JSON

Error Message Specifications

  • Use clear, colored output (if terminal supports it)
  • Provide specific extension IDs that are missing
  • Include path to target file that needs updating
  • Offer brief instructions on how to resolve the issue
  • Use consistent formatting with other project tooling

Research Needed

No

Research Details

No response

Acceptance Criteria Confirmation

Yes

Pre-submission Confirmation

Yes

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions