A demonstration project showing how to create a VS Code extension that can be previewed in GitHub Codespaces directly from Pull Requests.
This extension demonstrates three core VS Code extension capabilities:
- Command Palette Integration: Execute "Hello World" command via Command Palette (
Ctrl+Shift+P
) - Activation Notification: Displays welcome message when extension activates
- Custom View Panel: Shows Hello World content in Explorer sidebar
-
Clone the repository:
git clone https://github.com/your-username/codespace-extension.git cd codespace-extension
-
Install dependencies:
yarn install
-
Compile TypeScript:
yarn compile
-
Launch Extension Development Host:
- Press
F5
in VS Code - Or run "Debug: Start Debugging" from Command Palette
- Press
- From Repository: Click "Code" → "Create codespace on main"
- From PR: Use the Codespace link automatically added to PR comments
- Dependencies install automatically via devcontainer configuration
Once the Extension Development Host launches:
-
Test Command Palette:
- Open Command Palette (
Ctrl+Shift+P
/Cmd+Shift+P
) - Type "Hello World" and execute the command
- Verify information message appears
- Open Command Palette (
-
Check Activation Notification:
- Should appear automatically when extension activates
- Look for "Codespace Extension has been activated successfully!"
-
View Custom Panel:
- Open Explorer sidebar if not already open
- Look for "Hello World" section
- Should display extension status messages
codespace-extension/
├── .devcontainer/
│ └── devcontainer.json # Codespace configuration
├── .github/
│ └── workflows/
│ └── codespace-preview.yml # PR preview automation
├── docs/
│ ├── implementation-plan.md # Development roadmap
│ └── software-requirements.md # Requirements specification
├── src/
│ └── extension.ts # Main extension code
├── out/ # Compiled JavaScript (generated)
├── package.json # Extension manifest
└── tsconfig.json # TypeScript configuration
When you create a Pull Request:
- GitHub Actions triggers automatically on PR creation/updates
- Workflow validates extension compiles successfully
- Comment is added to PR with Codespace preview link
- Team members can test changes directly in Codespace
-
Create a feature branch:
git checkout -b feature/test-changes
-
Make changes to the extension (e.g., modify messages in
src/extension.ts
) -
Commit and push:
git add . git commit -m "Test extension changes" git push origin feature/test-changes
-
Create PR via GitHub UI or CLI:
gh pr create --title "Test Extension Changes" --body "Testing PR preview workflow"
-
Check PR comments for Codespace preview link
yarn compile
- Compile TypeScript to JavaScriptyarn watch
- Watch mode compilation for developmentyarn vscode:prepublish
- Prepare for publishing (runs compile)
- Ensure TypeScript compilation succeeded (
yarn compile
) - Check console for activation errors (Developer Tools → Console)
- Verify
package.json
manifest is correct
- Check
.devcontainer/devcontainer.json
configuration - Ensure required extensions are listed in devcontainer
- Verify Node.js version compatibility
- Check workflow logs in GitHub Actions tab
- Ensure repository has Actions enabled
- Verify workflow permissions for commenting on PRs
This is a demonstration project for internal team use. To replicate for your own extension:
- Fork this repository
- Update
package.json
with your extension details - Modify
src/extension.ts
with your functionality - Update documentation as needed
- Test the PR preview workflow
After understanding this workflow, consider:
- Adding unit tests with
@vscode/test-electron
- Implementing more complex extension features
- Setting up automated publishing to VS Code Marketplace
- Adding integration with other GitHub features