Skip to content

Commit 07c2159

Browse files
Copilotosortega
andcommitted
Complete Hello World extension with documentation and validation
Co-authored-by: osortega <[email protected]>
1 parent 5733913 commit 07c2159

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

extensions/hello-world/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Hello World Extension
2+
3+
A simple "Hello World" extension for Visual Studio Code that demonstrates the basic structure and functionality of a VS Code extension.
4+
5+
## Features
6+
7+
This extension provides a single command that displays a "Hello World" message.
8+
9+
## Commands
10+
11+
- `Hello World` - Shows an information message with "Hello World from VS Code!"
12+
13+
## Usage
14+
15+
1. Open the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P`)
16+
2. Type "Hello World" and select the command
17+
3. A message will appear showing "Hello World from VS Code!"
18+
19+
## Extension Structure
20+
21+
- `package.json` - Extension manifest with metadata and contributions
22+
- `src/extension.ts` - Main extension code with activate/deactivate functions
23+
- `tsconfig.json` - TypeScript configuration
24+
- `out/` - Compiled JavaScript output
25+
26+
## Development
27+
28+
This extension is built using TypeScript and follows VS Code extension development best practices:
29+
30+
- Uses the VS Code Extension API
31+
- Registers commands through the `contributes.commands` section
32+
- Activates on command execution via `activationEvents`
33+
- Properly manages subscriptions for cleanup
34+
35+
## Build
36+
37+
The extension is compiled using TypeScript:
38+
39+
```bash
40+
npx tsc
41+
```
42+
43+
The compiled output is placed in the `out/` directory.

extensions/hello-world/validate.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env node
2+
3+
/*---------------------------------------------------------------------------------------------
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
5+
* Licensed under the MIT License. See License.txt in the project root for license information.
6+
*--------------------------------------------------------------------------------------------*/
7+
8+
const fs = require('fs');
9+
const path = require('path');
10+
11+
const extensionRoot = __dirname;
12+
13+
function validateExtension() {
14+
console.log('🔍 Validating Hello World Extension...\n');
15+
16+
// Check package.json
17+
const packageJsonPath = path.join(extensionRoot, 'package.json');
18+
if (!fs.existsSync(packageJsonPath)) {
19+
console.error('❌ package.json not found');
20+
return false;
21+
}
22+
23+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
24+
console.log('✅ package.json found');
25+
console.log(` - Name: ${packageJson.name}`);
26+
console.log(` - Display Name: ${packageJson.displayName}`);
27+
console.log(` - Version: ${packageJson.version}`);
28+
29+
// Check activation events
30+
if (packageJson.activationEvents && packageJson.activationEvents.includes('onCommand:helloWorld.hello')) {
31+
console.log('✅ Activation event configured');
32+
} else {
33+
console.error('❌ Missing activation event');
34+
return false;
35+
}
36+
37+
// Check commands
38+
if (packageJson.contributes && packageJson.contributes.commands) {
39+
const helloCommand = packageJson.contributes.commands.find(cmd => cmd.command === 'helloWorld.hello');
40+
if (helloCommand) {
41+
console.log('✅ Hello World command configured');
42+
console.log(` - Command: ${helloCommand.command}`);
43+
console.log(` - Title: ${helloCommand.title}`);
44+
} else {
45+
console.error('❌ Hello World command not found');
46+
return false;
47+
}
48+
} else {
49+
console.error('❌ No commands configured');
50+
return false;
51+
}
52+
53+
// Check source file
54+
const mainSrcPath = path.join(extensionRoot, 'src', 'extension.ts');
55+
if (!fs.existsSync(mainSrcPath)) {
56+
console.error('❌ src/extension.ts not found');
57+
return false;
58+
}
59+
console.log('✅ Source file exists');
60+
61+
// Check compiled output
62+
const mainOutPath = path.join(extensionRoot, 'out', 'extension.js');
63+
if (!fs.existsSync(mainOutPath)) {
64+
console.error('❌ Compiled output not found (run: npx tsc)');
65+
return false;
66+
}
67+
console.log('✅ Compiled output exists');
68+
69+
// Check that compiled output contains the expected function
70+
const compiledContent = fs.readFileSync(mainOutPath, 'utf8');
71+
if (compiledContent.includes('helloWorld.hello') && compiledContent.includes('Hello World from VS Code!')) {
72+
console.log('✅ Compiled extension contains expected command and message');
73+
} else {
74+
console.error('❌ Compiled extension missing expected content');
75+
return false;
76+
}
77+
78+
console.log('\n🎉 Hello World Extension validation passed!');
79+
console.log('\nTo test the extension:');
80+
console.log('1. Open VS Code development host');
81+
console.log('2. Open Command Palette (Ctrl+Shift+P)');
82+
console.log('3. Type "Hello World" and execute the command');
83+
console.log('4. You should see: "Hello World from VS Code!" message');
84+
85+
return true;
86+
}
87+
88+
if (require.main === module) {
89+
const success = validateExtension();
90+
process.exit(success ? 0 : 1);
91+
}
92+
93+
module.exports = validateExtension;

0 commit comments

Comments
 (0)