mirror of
https://github.com/fanzeyi/cargo-play
synced 2024-11-10 05:04:13 +00:00
Adding VSCode extension (#23)
This commit is contained in:
parent
dda8dfe6bc
commit
d137ff06fb
21 changed files with 2363 additions and 1 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -8,3 +8,8 @@ Cargo.lock
|
|||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
|
||||
# Extension local development files
|
||||
/extension/node_modules/
|
||||
/extension/out/
|
17
.vscode/tasks.json
vendored
Normal file
17
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "shell",
|
||||
"label": "CargoPlay",
|
||||
"command": "cargo",
|
||||
"args": [
|
||||
"play",
|
||||
"${file}",
|
||||
],
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -106,10 +106,14 @@ With your code file open, running `:CargoPlay` will allow you to test your curre
|
|||
|
||||
### VSCode
|
||||
|
||||
Install the [VSCode Extension](./extension/README.md)
|
||||
|
||||
OR
|
||||
|
||||
Open Command Palette and select **Configure Task**
|
||||
- *This will either create a new tasks.json or open your existing tasks.json*
|
||||
|
||||
Add the following task:
|
||||
Add the following [task](./.vscode/tasks.json):
|
||||
|
||||
```json
|
||||
{
|
||||
|
|
19
extension/.eslintrc.json
Normal file
19
extension/.eslintrc.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/class-name-casing": "warn",
|
||||
"@typescript-eslint/semi": "warn",
|
||||
"curly": "warn",
|
||||
"eqeqeq": "warn",
|
||||
"no-throw-literal": "warn",
|
||||
"semi": "off"
|
||||
}
|
||||
}
|
7
extension/.vscode/extensions.json
vendored
Normal file
7
extension/.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"dbaeumer.vscode-eslint"
|
||||
]
|
||||
}
|
36
extension/.vscode/launch.json
vendored
Normal file
36
extension/.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Run Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/out/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "${defaultBuildTask}"
|
||||
},
|
||||
{
|
||||
"name": "Extension Tests",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/out/test/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "${defaultBuildTask}"
|
||||
}
|
||||
]
|
||||
}
|
11
extension/.vscode/settings.json
vendored
Normal file
11
extension/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.exclude": {
|
||||
"out": false // set this to true to hide the "out" folder with the compiled JS files
|
||||
},
|
||||
"search.exclude": {
|
||||
"out": true // set this to false to include "out" folder in search results
|
||||
},
|
||||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
|
||||
"typescript.tsc.autoDetect": "off"
|
||||
}
|
20
extension/.vscode/tasks.json
vendored
Normal file
20
extension/.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch",
|
||||
"problemMatcher": "$tsc-watch",
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "never"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
12
extension/DEVELOPMENT.md
Normal file
12
extension/DEVELOPMENT.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Development
|
||||
|
||||
## Testing/Debugging
|
||||
Add this directory as a workspace folder in VSCode and you can use the debugger to run the extension in a VSCode window. [Debug Guide](https://code.visualstudio.com/api/get-started/your-first-extension)
|
||||
|
||||
## Bundling / Publishing
|
||||
[Guide](https://code.visualstudio.com/api/working-with-extensions/publishing-extension)
|
||||
|
||||
```
|
||||
(cargo-play/extension) $ vsce package
|
||||
(cargo-play/extension) $ vsce publish
|
||||
```
|
37
extension/README.md
Normal file
37
extension/README.md
Normal file
|
@ -0,0 +1,37 @@
|
|||
# cargo-play VSCode Extension
|
||||
|
||||
![cargo-play demo](images/cargo_play_vscode.gif)
|
||||
|
||||
## Features
|
||||
|
||||
- CargoPlay: Run
|
||||
- Run the current Rust file in a CargoPlay playground [Usage instructions](../README.md#usage)
|
||||
|
||||
- CargoPlay: Install
|
||||
- Install the cargo-play Cargo extension (only needs to be done once)
|
||||
|
||||
## Requirements
|
||||
|
||||
- Installation of [Rustup](https://rustup.rs/) and `cargo` in your `$PATH`
|
||||
|
||||
## Installation
|
||||
|
||||
Install from Github:
|
||||
```
|
||||
$ git clone https://github.com/fanzeyi/cargo-play
|
||||
$ code --install-extension cargo-play/extension/cargo-play.0.0.1.vsix
|
||||
```
|
||||
|
||||
## Known Issues
|
||||
|
||||
- At least one folder must be added to the workspace
|
||||
- The extension is not aware of `cargo play` being installed or not
|
||||
|
||||
|
||||
## Release Notes
|
||||
|
||||
### 1.0.0
|
||||
|
||||
Initial release of Cargo-Play extension, supports:
|
||||
- CargoPlay installation
|
||||
- Quick access to CargoPlay playground feature of running Rust files
|
BIN
extension/cargo-play-0.0.1.vsix
Normal file
BIN
extension/cargo-play-0.0.1.vsix
Normal file
Binary file not shown.
BIN
extension/images/cargo_play.png
Normal file
BIN
extension/images/cargo_play.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 64 KiB |
BIN
extension/images/cargo_play_icon.png
Normal file
BIN
extension/images/cargo_play_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.6 KiB |
BIN
extension/images/cargo_play_vscode.gif
Normal file
BIN
extension/images/cargo_play_vscode.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 681 KiB |
2003
extension/package-lock.json
generated
Normal file
2003
extension/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
59
extension/package.json
Normal file
59
extension/package.json
Normal file
|
@ -0,0 +1,59 @@
|
|||
{
|
||||
"name": "cargo-play",
|
||||
"displayName": "CargoPlay",
|
||||
"description": "A local Rust playground",
|
||||
"version": "0.0.1",
|
||||
"publisher": "fanzeyi",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/fanzeyi/cargo-play"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.43.0"
|
||||
},
|
||||
"icon": "images/cargo_play_icon.png",
|
||||
"keywords": [
|
||||
"rust"
|
||||
],
|
||||
"categories": [
|
||||
"Programming Languages"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:extension.cargoPlay",
|
||||
"onCommand:extension.installCargoPlay"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "extension.cargoPlay",
|
||||
"title": "CargoPlay: Run"
|
||||
},
|
||||
{
|
||||
"command": "extension.installCargoPlay",
|
||||
"title": "CargoPlay: Install"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"lint": "eslint src --ext ts",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "npm run compile && npm run lint",
|
||||
"test": "node ./out/test/runTest.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/glob": "^7.1.1",
|
||||
"@types/mocha": "^7.0.1",
|
||||
"@types/node": "^12.11.7",
|
||||
"@types/vscode": "^1.43.0",
|
||||
"eslint": "^6.8.0",
|
||||
"@typescript-eslint/parser": "^2.18.0",
|
||||
"@typescript-eslint/eslint-plugin": "^2.18.0",
|
||||
"glob": "^7.1.6",
|
||||
"mocha": "^7.0.1",
|
||||
"typescript": "^3.7.5",
|
||||
"vscode-test": "^1.3.0"
|
||||
}
|
||||
}
|
35
extension/src/extension.ts
Normal file
35
extension/src/extension.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import * as vscode from 'vscode';
|
||||
|
||||
interface CargoPlayTaskDefinition extends vscode.TaskDefinition {
|
||||
/* The Rust file to compile */
|
||||
target_file: string;
|
||||
}
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
let play = vscode.commands.registerCommand('extension.cargoPlay', async () => {
|
||||
const filename = vscode.window.activeTextEditor?.document.fileName;
|
||||
if (filename === undefined || !filename.endsWith(".rs")) {
|
||||
vscode.window.showWarningMessage("CargoPlay: No active Rust file found");
|
||||
return;
|
||||
}
|
||||
|
||||
let def: CargoPlayTaskDefinition = {
|
||||
type: 'cargo-play',
|
||||
target_file: filename
|
||||
};
|
||||
let execution = new vscode.ShellExecution(`cargo play ${def.target_file}`);
|
||||
let task = new vscode.Task(def, vscode.TaskScope.Global.toString(), 'cargo-play', execution, ["$rustc"]);
|
||||
vscode.tasks.executeTask(task);
|
||||
});
|
||||
context.subscriptions.push(play);
|
||||
|
||||
let install = vscode.commands.registerCommand('extension.installCargoPlay', async () => {
|
||||
let def: vscode.TaskDefinition = { type: 'cargo-play-install' };
|
||||
let execution = new vscode.ShellExecution(`cargo install cargo-play`);
|
||||
let task = new vscode.Task(def, vscode.TaskScope.Global.toString(), 'cargo-play-install', execution, ["$rustc"]);
|
||||
await vscode.tasks.executeTask(task);
|
||||
});
|
||||
context.subscriptions.push(install);
|
||||
}
|
||||
|
||||
export function deactivate() { }
|
23
extension/src/test/runTest.ts
Normal file
23
extension/src/test/runTest.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import * as path from 'path';
|
||||
|
||||
import { runTests } from 'vscode-test';
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// The folder containing the Extension Manifest package.json
|
||||
// Passed to `--extensionDevelopmentPath`
|
||||
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
|
||||
|
||||
// The path to test runner
|
||||
// Passed to --extensionTestsPath
|
||||
const extensionTestsPath = 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);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
15
extension/src/test/suite/extension.test.ts
Normal file
15
extension/src/test/suite/extension.test.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
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', () => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
|
||||
test('Sample test', () => {
|
||||
assert.equal(-1, [1, 2, 3].indexOf(5));
|
||||
assert.equal(-1, [1, 2, 3].indexOf(0));
|
||||
});
|
||||
});
|
38
extension/src/test/suite/index.ts
Normal file
38
extension/src/test/suite/index.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import * as path from 'path';
|
||||
import * as Mocha from 'mocha';
|
||||
import * as glob from 'glob';
|
||||
|
||||
export function run(): Promise<void> {
|
||||
// Create the mocha test
|
||||
const mocha = new Mocha({
|
||||
ui: 'tdd',
|
||||
});
|
||||
mocha.useColors(true);
|
||||
|
||||
const testsRoot = path.resolve(__dirname, '..');
|
||||
|
||||
return new Promise((c, e) => {
|
||||
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
||||
if (err) {
|
||||
return e(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) {
|
||||
e(new Error(`${failures} tests failed.`));
|
||||
} else {
|
||||
c();
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
e(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
21
extension/tsconfig.json
Normal file
21
extension/tsconfig.json
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"outDir": "out",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"strict": true /* enable all strict type-checking options */
|
||||
/* Additional Checks */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode-test"
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue