Skip to content

Commit

Permalink
feat(vscode-extension): hello world
Browse files Browse the repository at this point in the history
  • Loading branch information
chengcyber committed Jan 16, 2022
1 parent ebee584 commit 15afb42
Show file tree
Hide file tree
Showing 17 changed files with 498 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ dist
*.sass.ts

# Visual Studio Code
.vscode
.vscode/**
!.vscode/launch.json
!.vscode/tasks.json

# Heft
.heft
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@
"type": "node",
"request": "attach",
"port": 5858
},
{
"name": "Launch Rush Extension",
"type": "extensionHost",
"request": "launch",
"cwd": "${workspaceFolder}/apps/vscode-extension",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/apps/vscode-extension"
],
"outFiles": [
"${workspaceFolder}/apps/vscode-extension/out/**/*.js"
],
"preLaunchTask": "npm: build:watch - apps/vscode-extension"
}
]
}
45 changes: 45 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build",
"path": "apps/vscode-extension/",
"group": "build",
"problemMatcher": [],
"label": "npm: build - apps/vscode-extension",
"detail": "heft build --clean"
},
{
"type": "npm",
"script": "build:watch",
"path": "apps/vscode-extension/",
"group": "build",
"isBackground": true,
"presentation": {
"reveal": "never",
},
"problemMatcher": [
{
"owner": "heft",
"fileLocation": ["relative", "${workspaceFolder}"],
"background": {
"activeOnStart": true,
"beginsPattern": "File change detected\\. Starting incremental compilation\\.\\.\\.",
"endsPattern": "Found\\s+\\d+\\s+errors\\. Watching for file changes\\."
},
"pattern": {
"regexp": "^(Error):\\s+(.*):(\\d+):(\\d+)\\s+-\\s+(.*)$",
"file": 2,
"line": 3,
"column": 4,
"severity": 1,
"message": 5,
}
}
],
"label": "npm: build:watch - apps/vscode-extension",
"detail": "heft build --watch"
}
]
}
11 changes: 11 additions & 0 deletions apps/vscode-extension/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('@rushstack/eslint-config/patch/modern-module-resolution');

module.exports = {
ignorePatterns: ['out', 'dist', '**/*.d.ts'],
extends: [
'@rushstack/eslint-config/profile/node-trusted-tool',
'@rushstack/eslint-config/mixins/friendly-locals'
],
parserOptions: { tsconfigRootDir: __dirname }
};
5 changes: 5 additions & 0 deletions apps/vscode-extension/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
out
dist
node_modules
.vscode-test/
*.vsix
11 changes: 11 additions & 0 deletions apps/vscode-extension/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vscode/**
.vscode-test/**
src/**
config/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
3 changes: 3 additions & 0 deletions apps/vscode-extension/config/rush-project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"projectOutputFolderNames": ["dist", "out"]
}
51 changes: 51 additions & 0 deletions apps/vscode-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "rushstack-vscode-extension",
"displayName": "RushStack",
"version": "0.0.0",
"description": "Visual Studio Extension for RushStack",
"repository": {
"type": "git",
"url": "https://github.com/microsoft/rushstack.git",
"directory": "apps/vscode-extension"
},
"license": "MIT",
"author": "Cheng Liu<[email protected]>",
"main": "./out/extension.js",
"scripts": {
"build": "heft build --clean",
"build:watch": "heft build --watch",
"pretest": "npm run build",
"test": "node ./out/test/runTest.js"
},
"contributes": {
"commands": [
{
"command": "rushstack.helloWorld",
"title": "Hello World"
}
]
},
"activationEvents": [
"onCommand:rushstack.helloWorld"
],
"devDependencies": {
"@rushstack/eslint-config": "workspace:*",
"@rushstack/heft": "workspace:*",
"@rushstack/heft-node-rig": "workspace:*",
"@types/glob": "7.1.1",
"@types/heft-jest": "1.0.1",
"@types/mocha": "^9.0.0",
"@types/node": "12.20.24",
"@types/vscode": "^1.63.0",
"@typescript-eslint/eslint-plugin": "~5.6.0",
"@typescript-eslint/parser": "~5.6.0",
"@vscode/test-electron": "^1.6.2",
"eslint": "~8.3.0",
"glob": "~7.0.5",
"mocha": "^9.1.3",
"typescript": "^4.4.4"
},
"engines": {
"vscode": "^1.63.0"
}
}
25 changes: 25 additions & 0 deletions apps/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext): void {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "vscode-hello-world" is now active!');

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
const disposable: vscode.Disposable = vscode.commands.registerCommand('rushstack.helloWorld', async () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
await vscode.window.showInformationMessage('Hello World from RushStack!');
});

context.subscriptions.push(disposable);
}

// this method is called when your extension is deactivated
export function deactivate(): void {}
24 changes: 24 additions & 0 deletions apps/vscode-extension/src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as path from 'path';

import { runTests } from '@vscode/test-electron';

async function main(): Promise<void> {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath: string = path.resolve(__dirname, '../../');

// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath: string = path.resolve(__dirname, './suite/index');

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
main();
16 changes: 16 additions & 0 deletions apps/vscode-extension/src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as assert from 'assert';

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';

suite('Extension Test Suite', () => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
vscode.window.showInformationMessage('Start all tests.');

test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
});
38 changes: 38 additions & 0 deletions apps/vscode-extension/src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as path from 'path';
import Mocha from 'mocha';
import glob from 'glob';

export function run(): Promise<void> {
// Create the mocha test
const mocha: Mocha = new Mocha({
ui: 'tdd',
color: true
});

const testsRoot: string = path.resolve(__dirname, '..');

return new Promise((resolve, reject) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return reject(err);
}

// Add files to the test suite
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));

try {
// Run the mocha test
mocha.run((failures) => {
if (failures > 0) {
reject(new Error(`${failures} tests failed.`));
} else {
resolve();
}
});
} catch (err) {
console.error(err);
reject(err);
}
});
});
}
7 changes: 7 additions & 0 deletions apps/vscode-extension/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./node_modules/@rushstack/heft-node-rig/profiles/default/tsconfig-base.json",
"compilerOptions": {
"outDir": "out",
"types": ["mocha", "node"]
}
}
12 changes: 10 additions & 2 deletions common/config/rush/nonbrowser-approved-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"allowedCategories": [ "tests" ]
},
{
"name": "@jest/create-cache-key-function",
"name": "@jest/core",
"allowedCategories": [ "libraries" ]
},
{
"name": "@jest/core",
"name": "@jest/create-cache-key-function",
"allowedCategories": [ "libraries" ]
},
{
Expand Down Expand Up @@ -242,6 +242,10 @@
"name": "@typescript-eslint/typescript-estree",
"allowedCategories": [ "libraries" ]
},
{
"name": "@vscode/test-electron",
"allowedCategories": [ "libraries" ]
},
{
"name": "@yarnpkg/lockfile",
"allowedCategories": [ "libraries" ]
Expand Down Expand Up @@ -474,6 +478,10 @@
"name": "minimatch",
"allowedCategories": [ "libraries" ]
},
{
"name": "mocha",
"allowedCategories": [ "libraries" ]
},
{
"name": "node-fetch",
"allowedCategories": [ "libraries" ]
Expand Down
Loading

0 comments on commit 15afb42

Please sign in to comment.