Development
This document describes how to develop and contribute to VS Code GPG.
Prerequisites
Getting Started
Clone the Repository
Install Dependencies
Build the Extension
Run in Development Mode
- Press
F5in VS Code - A new VS Code window will open with the extension loaded
- Make changes and press
F5to reload
Project Structure
vscode-gpg/
├── src/
│ ├── crypto/
│ │ ├── config.ts # Configuration management
│ │ ├── keyManager.ts # Key storage and management
│ │ └── openpgp.ts # OpenPGP operations (encrypt/decrypt)
│ ├── commands/
│ │ └── keyCommands.ts # Command registrations
│ ├── providers/
│ │ └── encryptedFileSystemProvider.ts # File system provider
│ ├── util/
│ │ └── logger.ts # Logging utilities
│ └── extension.ts # Extension entry point
├── package.json # Extension manifest
├── tsconfig.json # TypeScript configuration
└── build.mjs # Build script
Key Components
Extension Activation (extension.ts)
The extension activates on:
- onFileSystem:gpgfs - When a file with the gpgfs scheme is opened
- onLanguage:plaintext - When a plain text file is opened
- onCommand:vscode.openWith - When opening with a specific editor
File System Provider (encryptedFileSystemProvider.ts)
Implements vscode.FileSystemProvider to provide:
- readFile - Decrypts and returns file content
- writeFile - Encrypts and writes file content
- stat, delete, rename, readDirectory - Standard file operations
Key Manager (keyManager.ts)
Manages GPG keys through: - VS Code's global state for key storage - VS Code's secrets API for passphrase storage - Import/export/list/remove operations
OpenPGP Operations (openpgp.ts)
Wraps the openpgp.js library:
- encrypt() - Encrypts content with a public key
- decrypt() - Decrypts content with a private key
- generateKeyPair() - Generates new key pairs
- parseKeyInfo() - Extracts key information
Building and Packaging
Development Build
This will compile TypeScript and watch for changes.
Production Build
Package Extension
This creates a .vsix file that can be installed.
Publish Extension
This publishes the extension to the VS Code Marketplace.
Testing
Manual Testing
- Press
F5to launch the extension development host - Test key generation
- Test file encryption/decryption
- Test edge cases (wrong passphrase, missing keys, etc.)
Debugging
- Set breakpoints in TypeScript files
- Press
F5to launch with debugger attached - Use the
GPG: Show Logscommand to view output
Contributing
Code Style
- Use TypeScript for all new code
- Follow existing code formatting
- Add comments for complex logic
Commit Messages
Use clear, descriptive commit messages:
feat: add support for multiple recipients
fix: handle missing passphrase gracefully
docs: update installation instructions
Pull Requests
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request with a clear description
Resources
License
MIT