vs code plugin prototype

This commit is contained in:
anon
2023-11-15 14:34:11 +01:00
parent e5f461914c
commit e362faf978
14 changed files with 1740 additions and 0 deletions

View File

@ -0,0 +1,30 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": [
"warn",
{
"selector": "import",
"format": [ "camelCase", "PascalCase" ]
}
],
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
}

7
plugin/vscode/.vscode/extensions.json vendored Normal file
View 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"
]
}

34
plugin/vscode/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,34 @@
// 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",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}

11
plugin/vscode/.vscode/settings.json vendored Normal file
View 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
plugin/vscode/.vscode/tasks.json vendored Normal file
View 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
}
}
]
}

1
plugin/vscode/.yarnrc Normal file
View File

@ -0,0 +1 @@
--ignore-engines true

View File

@ -0,0 +1,42 @@
{
"name": "cwheel",
"displayName": "cwheel",
"description": "",
"version": "0.0.1",
"engines": {
"vscode": "^1.84.0"
},
"categories": [
"Other"
],
"activationEvents": [],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "cwheel.cycle",
"title": "Cycle"
}
]
},
"scripts": {
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "yarn run compile && yarn run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/vscode": "^1.84.0",
"@types/mocha": "^10.0.3",
"@types/node": "18.x",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"eslint": "^8.52.0",
"glob": "^10.3.10",
"mocha": "^10.2.0",
"typescript": "^5.2.2",
"@vscode/test-electron": "^2.3.6"
}
}

View File

@ -0,0 +1,72 @@
import * as vscode from 'vscode';
import * as path from 'path';
import { exec } from 'child_process';
function cycle() {
const activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
vscode.window.showErrorMessage('No active editor.');
return;
}
const savedCursor = activeEditor.selection.active;
const currentFile = activeEditor.document.uri.fsPath;
const basename = path.basename(currentFile, path.extname(currentFile));
let outputFileName: string;
let forceFlag: string;
if (currentFile.toLowerCase().endsWith('.csml')) {
vscode.workspace.getConfiguration().update('files.exclude', { [basename + '.*']: true }, vscode.ConfigurationTarget.Workspace);
vscode.workspace.findFiles(`${basename}.*`).then((candidates: vscode.Uri[]) => {
if (candidates.length > 0) {
outputFileName = candidates[0].fsPath;
} else {
outputFileName = path.join(path.dirname(currentFile), `${basename}.html`);
vscode.window.showInputBox({ prompt: `Press Enter or override the output name '${outputFileName}':` })
.then((input) => {
if (input) {
outputFileName = path.join(path.dirname(currentFile), input);
}
});
}
forceFlag = '-c';
executeCWheel();
});
} else {
outputFileName = path.join(path.dirname(currentFile), `${basename}.csml`);
forceFlag = '-x';
executeCWheel();
}
function executeCWheel() {
const cwheelCommand = `cwheel ${forceFlag} -o ${outputFileName} ${currentFile}`;
exec(cwheelCommand, (error, stdout, stderr) => {
if (error) {
vscode.window.showErrorMessage(`Error executing command: ${error.message}`);
return;
}
vscode.workspace.openTextDocument(outputFileName).then(doc => {
vscode.window.showTextDocument(doc);
});
if (savedCursor && activeEditor) {
activeEditor.selection = new vscode.Selection(savedCursor, savedCursor);
}
});
}
}
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('cwheel.cycle', cycle));
context.subscriptions.push(vscode.commands.registerCommand('cwheel.cycleKeybinding', () => {
cycle();
}));
}

View File

@ -0,0 +1,23 @@
import * as path from 'path';
import { runTests } from '@vscode/test-electron';
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', err);
process.exit(1);
}
}
main();

View 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.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
});

View File

@ -0,0 +1,32 @@
import * as path from 'path';
import Mocha from 'mocha';
import { glob } from 'glob';
export async function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
color: true
});
const testsRoot = path.resolve(__dirname, '..');
const files = await glob('**/**.test.js', { cwd: testsRoot });
// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
try {
return new Promise<void>((c, e) => {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
});
} catch (err) {
console.error(err);
}
}

View File

@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "Node16",
"target": "ES2022",
"outDir": "out",
"lib": [
"ES2022"
],
"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. */
}
}

1434
plugin/vscode/yarn.lock Normal file

File diff suppressed because it is too large Load Diff