Skip to content

Commit 15afb42

Browse files
committed
feat(vscode-extension): hello world
1 parent ebee584 commit 15afb42

File tree

17 files changed

+498
-7
lines changed

17 files changed

+498
-7
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ dist
7676
*.sass.ts
7777

7878
# Visual Studio Code
79-
.vscode
79+
.vscode/**
80+
!.vscode/launch.json
81+
!.vscode/tasks.json
8082

8183
# Heft
8284
.heft

.vscode/launch.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@
4848
"type": "node",
4949
"request": "attach",
5050
"port": 5858
51+
},
52+
{
53+
"name": "Launch Rush Extension",
54+
"type": "extensionHost",
55+
"request": "launch",
56+
"cwd": "${workspaceFolder}/apps/vscode-extension",
57+
"args": [
58+
"--extensionDevelopmentPath=${workspaceFolder}/apps/vscode-extension"
59+
],
60+
"outFiles": [
61+
"${workspaceFolder}/apps/vscode-extension/out/**/*.js"
62+
],
63+
"preLaunchTask": "npm: build:watch - apps/vscode-extension"
5164
}
5265
]
5366
}

.vscode/tasks.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "npm",
6+
"script": "build",
7+
"path": "apps/vscode-extension/",
8+
"group": "build",
9+
"problemMatcher": [],
10+
"label": "npm: build - apps/vscode-extension",
11+
"detail": "heft build --clean"
12+
},
13+
{
14+
"type": "npm",
15+
"script": "build:watch",
16+
"path": "apps/vscode-extension/",
17+
"group": "build",
18+
"isBackground": true,
19+
"presentation": {
20+
"reveal": "never",
21+
},
22+
"problemMatcher": [
23+
{
24+
"owner": "heft",
25+
"fileLocation": ["relative", "${workspaceFolder}"],
26+
"background": {
27+
"activeOnStart": true,
28+
"beginsPattern": "File change detected\\. Starting incremental compilation\\.\\.\\.",
29+
"endsPattern": "Found\\s+\\d+\\s+errors\\. Watching for file changes\\."
30+
},
31+
"pattern": {
32+
"regexp": "^(Error):\\s+(.*):(\\d+):(\\d+)\\s+-\\s+(.*)$",
33+
"file": 2,
34+
"line": 3,
35+
"column": 4,
36+
"severity": 1,
37+
"message": 5,
38+
}
39+
}
40+
],
41+
"label": "npm: build:watch - apps/vscode-extension",
42+
"detail": "heft build --watch"
43+
}
44+
]
45+
}

apps/vscode-extension/.eslintrc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This is a workaround for https://github.com/eslint/eslint/issues/3458
2+
require('@rushstack/eslint-config/patch/modern-module-resolution');
3+
4+
module.exports = {
5+
ignorePatterns: ['out', 'dist', '**/*.d.ts'],
6+
extends: [
7+
'@rushstack/eslint-config/profile/node-trusted-tool',
8+
'@rushstack/eslint-config/mixins/friendly-locals'
9+
],
10+
parserOptions: { tsconfigRootDir: __dirname }
11+
};

apps/vscode-extension/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
out
2+
dist
3+
node_modules
4+
.vscode-test/
5+
*.vsix

apps/vscode-extension/.vscodeignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.vscode/**
2+
.vscode-test/**
3+
src/**
4+
config/**
5+
.gitignore
6+
.yarnrc
7+
vsc-extension-quickstart.md
8+
**/tsconfig.json
9+
**/.eslintrc.json
10+
**/*.map
11+
**/*.ts
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"projectOutputFolderNames": ["dist", "out"]
3+
}

apps/vscode-extension/package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "rushstack-vscode-extension",
3+
"displayName": "RushStack",
4+
"version": "0.0.0",
5+
"description": "Visual Studio Extension for RushStack",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/microsoft/rushstack.git",
9+
"directory": "apps/vscode-extension"
10+
},
11+
"license": "MIT",
12+
"author": "Cheng Liu<[email protected]>",
13+
"main": "./out/extension.js",
14+
"scripts": {
15+
"build": "heft build --clean",
16+
"build:watch": "heft build --watch",
17+
"pretest": "npm run build",
18+
"test": "node ./out/test/runTest.js"
19+
},
20+
"contributes": {
21+
"commands": [
22+
{
23+
"command": "rushstack.helloWorld",
24+
"title": "Hello World"
25+
}
26+
]
27+
},
28+
"activationEvents": [
29+
"onCommand:rushstack.helloWorld"
30+
],
31+
"devDependencies": {
32+
"@rushstack/eslint-config": "workspace:*",
33+
"@rushstack/heft": "workspace:*",
34+
"@rushstack/heft-node-rig": "workspace:*",
35+
"@types/glob": "7.1.1",
36+
"@types/heft-jest": "1.0.1",
37+
"@types/mocha": "^9.0.0",
38+
"@types/node": "12.20.24",
39+
"@types/vscode": "^1.63.0",
40+
"@typescript-eslint/eslint-plugin": "~5.6.0",
41+
"@typescript-eslint/parser": "~5.6.0",
42+
"@vscode/test-electron": "^1.6.2",
43+
"eslint": "~8.3.0",
44+
"glob": "~7.0.5",
45+
"mocha": "^9.1.3",
46+
"typescript": "^4.4.4"
47+
},
48+
"engines": {
49+
"vscode": "^1.63.0"
50+
}
51+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// The module 'vscode' contains the VS Code extensibility API
2+
// Import the module and reference it with the alias vscode in your code below
3+
import * as vscode from 'vscode';
4+
5+
// this method is called when your extension is activated
6+
// your extension is activated the very first time the command is executed
7+
export function activate(context: vscode.ExtensionContext): void {
8+
// Use the console to output diagnostic information (console.log) and errors (console.error)
9+
// This line of code will only be executed once when your extension is activated
10+
console.log('Congratulations, your extension "vscode-hello-world" is now active!');
11+
12+
// The command has been defined in the package.json file
13+
// Now provide the implementation of the command with registerCommand
14+
// The commandId parameter must match the command field in package.json
15+
const disposable: vscode.Disposable = vscode.commands.registerCommand('rushstack.helloWorld', async () => {
16+
// The code you place here will be executed every time your command is executed
17+
// Display a message box to the user
18+
await vscode.window.showInformationMessage('Hello World from RushStack!');
19+
});
20+
21+
context.subscriptions.push(disposable);
22+
}
23+
24+
// this method is called when your extension is deactivated
25+
export function deactivate(): void {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as path from 'path';
2+
3+
import { runTests } from '@vscode/test-electron';
4+
5+
async function main(): Promise<void> {
6+
try {
7+
// The folder containing the Extension Manifest package.json
8+
// Passed to `--extensionDevelopmentPath`
9+
const extensionDevelopmentPath: string = path.resolve(__dirname, '../../');
10+
11+
// The path to test runner
12+
// Passed to --extensionTestsPath
13+
const extensionTestsPath: string = path.resolve(__dirname, './suite/index');
14+
15+
// Download VS Code, unzip it and run the integration test
16+
await runTests({ extensionDevelopmentPath, extensionTestsPath });
17+
} catch (err) {
18+
console.error('Failed to run tests');
19+
process.exit(1);
20+
}
21+
}
22+
23+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
24+
main();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as assert from 'assert';
2+
3+
// You can import and use all API from the 'vscode' module
4+
// as well as import your extension to test it
5+
import * as vscode from 'vscode';
6+
// import * as myExtension from '../../extension';
7+
8+
suite('Extension Test Suite', () => {
9+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
10+
vscode.window.showInformationMessage('Start all tests.');
11+
12+
test('Sample test', () => {
13+
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
14+
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
15+
});
16+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as path from 'path';
2+
import Mocha from 'mocha';
3+
import glob from 'glob';
4+
5+
export function run(): Promise<void> {
6+
// Create the mocha test
7+
const mocha: Mocha = new Mocha({
8+
ui: 'tdd',
9+
color: true
10+
});
11+
12+
const testsRoot: string = path.resolve(__dirname, '..');
13+
14+
return new Promise((resolve, reject) => {
15+
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
16+
if (err) {
17+
return reject(err);
18+
}
19+
20+
// Add files to the test suite
21+
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
22+
23+
try {
24+
// Run the mocha test
25+
mocha.run((failures) => {
26+
if (failures > 0) {
27+
reject(new Error(`${failures} tests failed.`));
28+
} else {
29+
resolve();
30+
}
31+
});
32+
} catch (err) {
33+
console.error(err);
34+
reject(err);
35+
}
36+
});
37+
});
38+
}

apps/vscode-extension/tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./node_modules/@rushstack/heft-node-rig/profiles/default/tsconfig-base.json",
3+
"compilerOptions": {
4+
"outDir": "out",
5+
"types": ["mocha", "node"]
6+
}
7+
}

common/config/rush/nonbrowser-approved-packages.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"allowedCategories": [ "tests" ]
1616
},
1717
{
18-
"name": "@jest/create-cache-key-function",
18+
"name": "@jest/core",
1919
"allowedCategories": [ "libraries" ]
2020
},
2121
{
22-
"name": "@jest/core",
22+
"name": "@jest/create-cache-key-function",
2323
"allowedCategories": [ "libraries" ]
2424
},
2525
{
@@ -242,6 +242,10 @@
242242
"name": "@typescript-eslint/typescript-estree",
243243
"allowedCategories": [ "libraries" ]
244244
},
245+
{
246+
"name": "@vscode/test-electron",
247+
"allowedCategories": [ "libraries" ]
248+
},
245249
{
246250
"name": "@yarnpkg/lockfile",
247251
"allowedCategories": [ "libraries" ]
@@ -474,6 +478,10 @@
474478
"name": "minimatch",
475479
"allowedCategories": [ "libraries" ]
476480
},
481+
{
482+
"name": "mocha",
483+
"allowedCategories": [ "libraries" ]
484+
},
477485
{
478486
"name": "node-fetch",
479487
"allowedCategories": [ "libraries" ]

0 commit comments

Comments
 (0)