Initial working version for VS Code

This commit is contained in:
ex61wi
2026-03-06 19:07:00 +01:00
commit 954d7d5a62
22 changed files with 13711 additions and 0 deletions
@@ -0,0 +1,5 @@
import { defineConfig } from '@vscode/test-cli';
export default defineConfig({
files: 'out/test/**/*.test.js',
});
@@ -0,0 +1,14 @@
.vscode/**
.vscode-test/**
out/**
node_modules/**
src/**
.gitignore
.yarnrc
esbuild.js
vsc-extension-quickstart.md
**/tsconfig.json
**/eslint.config.mjs
**/*.map
**/*.ts
**/.vscode-test.*
@@ -0,0 +1,9 @@
# Change Log
All notable changes to the "dutchies-dcs-scripting-tools" extension will be documented in this file.
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
## [Unreleased]
- Initial release
+19
View File
@@ -0,0 +1,19 @@
# dutchies-dcs-scripting-tools
My view on a toolset you'll need to write DCS mission scripts.
Direct DCS API checking and a Transpiler that can help keep huge complex scripts and frameworks simple and overseeable.
## Features
## Requirements
`sumenko.lua` : The VSCode Lua Language Server
## Release Notes
### 0.0.1
Initial.
Still very much in Test/Development
+59
View File
@@ -0,0 +1,59 @@
const esbuild = require("esbuild");
const production = process.argv.includes('--production');
const watch = process.argv.includes('--watch');
/**
* @type {import('esbuild').Plugin}
*/
const esbuildProblemMatcherPlugin = {
name: 'esbuild-problem-matcher',
setup(build) {
build.onStart(() => {
console.log('[watch] build started');
});
build.onEnd((result) => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
console.error(` ${location.file}:${location.line}:${location.column}:`);
});
console.log('[watch] build finished');
});
},
};
async function main() {
const ctx = await esbuild.context({
entryPoints: [
'src/extension.ts'
],
bundle: true,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'node',
outfile: 'dist/extension.js',
external: ['vscode'],
alias: {
'dcs-script-compiler': '../compiler/src/ScriptCompiler.ts'
},
logLevel: 'silent',
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
}
main().catch(e => {
console.error(e);
process.exit(1);
});
@@ -0,0 +1,27 @@
import typescriptEslint from "typescript-eslint";
export default [{
files: ["**/*.ts"],
}, {
plugins: {
"@typescript-eslint": typescriptEslint.plugin,
},
languageOptions: {
parser: typescriptEslint.parser,
ecmaVersion: 2022,
sourceType: "module",
},
rules: {
"@typescript-eslint/naming-convention": ["warn", {
selector: "import",
format: ["camelCase", "PascalCase"],
}],
curly: "warn",
eqeqeq: "warn",
"no-throw-literal": "warn",
semi: "warn",
},
}];
@@ -0,0 +1,6 @@
{
"name": "Dutchie DCS Toolkit",
"words" : [],
"files" : [],
"settings": {}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+89
View File
@@ -0,0 +1,89 @@
{
"name": "dutchies-dcs-scripting-tools",
"displayName": "Dutchies Dcs Scripting Tools",
"description": "Scripting tools to create DCS script and frameworks easier",
"version": "0.0.1",
"author": {
"name": "dutchie031",
"email": "54616262+dutchie031@users.noreply.github.com"
},
"publisher": "dutchie031",
"license": "MIT",
"engines": {
"vscode": "^1.108.1"
},
"repository": {
"type": "git",
"url": "https://github.com/dutchie031/DcsMissionScriptingTools"
},
"categories": [
"Other"
],
"activationEvents": [],
"main": "./dist/extension.js",
"contributes": {
"grammars": [
{
"path": "./syntaxes/lua-slocal.json",
"scopeName": "source.lua.slocal",
"injectTo": ["source.lua"]
}
],
"commands": [
{
"command": "dutchies-dcs-scripting-tools.enable",
"title": "Enable",
"category": "Dutchies DCS Tools"
},
{
"command": "dutchies-dcs-scripting-tools.disable",
"title": "Disable",
"category": "Dutchies DCS Tools"
},
{
"command": "dutchies-dcs-scripting-tools.compileLuaScripts",
"title": "Compile",
"category": "Dutchies DCS Tools"
}
]
},
"extensionDependencies": [
"sumneko.lua"
],
"files": [
"dist",
"README.md",
"lua-addons/**/*",
"syntaxes/**/*"
],
"dependencies": {
"dcs-script-compiler" : "*"
},
"scripts": {
"vscode:prepublish": "npm run build -w compiler && npm run package",
"compile": "npm run check-types && npm run lint && node esbuild.js",
"watch": "npm-run-all -p watch:*",
"watch:esbuild": "node esbuild.js --watch",
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
"watch:compiler": "cd ../compiler && npm run watch",
"package": "npm run check-types && npm run lint && node esbuild.js --production",
"compile-tests": "tsc -p . --outDir out",
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "npm run compile-tests && npm run compile && npm run lint",
"check-types": "tsc --noEmit",
"lint": "eslint src",
"test": "vscode-test"
},
"devDependencies": {
"@types/vscode": "^1.108.1",
"@types/mocha": "^10.0.10",
"@types/node": "22.x",
"typescript-eslint": "^8.52.0",
"eslint": "^9.39.2",
"esbuild": "^0.27.2",
"npm-run-all": "^4.1.5",
"typescript": "^5.9.3",
"@vscode/test-cli": "^0.0.12",
"@vscode/test-electron": "^2.5.2"
}
}
@@ -0,0 +1,119 @@
// 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';
import { ScriptCompiler, ScriptCompilerOptions, CompilationError } from 'dcs-script-compiler';
const luaWorkSpaceSettingKey = "Lua.workspace";
const librarySettingsKey = "library";
const diagnosticCollection = vscode.languages.createDiagnosticCollection('lua-transpiler');
let pluginPath : string | undefined;
// 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) {
pluginPath = context.asAbsolutePath('lua-addons');
vscode.commands.registerCommand('dutchies-dcs-scripting-tools.enable', () => {
addPluginPathToSettings();
vscode.commands.executeCommand(
"lua.startServer"
);
vscode.window.showInformationMessage('Dutchies DCS Scripting Tools enabled.');
});
vscode.commands.registerCommand('dutchies-dcs-scripting-tools.disable', () => {
removePluginPathFromSettings();
vscode.commands.executeCommand(
"lua.startServer"
);
vscode.window.showInformationMessage('Dutchies DCS Scripting Tools disabled.');
});
vscode.commands.registerCommand('dutchies-dcs-scripting-tools.compileLuaScripts', async () => {
try{
const start = Date.now();
await compileLuaScripts();
const end = Date.now();
console.log(`Lua scripts compiled in ${(end - start) / 1000} seconds.`);
vscode.window.showInformationMessage(`Lua scripts compiled successfully in ${(end - start) / 1000} seconds.`);
}catch(err){
vscode.window.showErrorMessage('Error compiling Lua scripts: ' + (err as Error).message);
}
});
}
// This method is called when your extension is deactivated
export function deactivate()
{
removePluginPathFromSettings();
}
async function compileLuaScripts() {
const config = vscode.workspace.getConfiguration('dcsScriptingTools');
const sourcePath = config.get<string>('luaSourcePath') || '${workspaceFolder}/src';
const outputPath = config.get<string>('luaOutputPath') || '${workspaceFolder}/dist';
const minify = config.get<boolean>('minifyLuaScripts') || false;
const resolvedSourcePath = sourcePath.replace('${workspaceFolder}', vscode.workspace.workspaceFolders?.[0].uri.fsPath || '');
const resolvedOutputPath = outputPath.replace('${workspaceFolder}', vscode.workspace.workspaceFolders?.[0].uri.fsPath || '');
diagnosticCollection.clear();
const errorsByFile = new Map<string, CompilationError[]>();
const options: ScriptCompilerOptions = {
sourcePath: resolvedSourcePath,
outputPath: resolvedOutputPath,
minify: minify,
onError: (error: CompilationError) => {
const errors = errorsByFile.get(error.filePath) || [];
errors.push(error);
errorsByFile.set(error.filePath, errors);
}
};
const compiler = new ScriptCompiler(options);
try {
await compiler.compile();
} catch (err) {
vscode.window.showErrorMessage('Compilation failed: ' + (err as Error).message);
}
// Update diagnostics
diagnosticCollection.clear();
for (const [filePath, errors] of errorsByFile) {
const uri = vscode.Uri.file(filePath);
const diagnostics = errors.map(error => {
const range = new vscode.Range(error.line, 0, error.line, 0);
const diagnostic = new vscode.Diagnostic(range, error.message, vscode.DiagnosticSeverity.Error);
diagnostic.source = 'DCS Lua Transpiler';
return diagnostic;
});
diagnosticCollection.set(uri, diagnostics);
}
}
function addPluginPathToSettings() {
if (pluginPath) {
const luaSettings = vscode.workspace.getConfiguration(luaWorkSpaceSettingKey);
const librarySettings = luaSettings.get<string[]>(librarySettingsKey) || [];
if (!librarySettings.includes(pluginPath)) {
librarySettings.push(pluginPath);
luaSettings.update(librarySettingsKey, librarySettings, vscode.ConfigurationTarget.Workspace);
}
}
}
function removePluginPathFromSettings() {
if (pluginPath) {
const luaSettings = vscode.workspace.getConfiguration(luaWorkSpaceSettingKey);
const librarySettings = luaSettings.get<string[]>(librarySettingsKey) || [];
const libIndex = librarySettings.indexOf(pluginPath);
if (libIndex !== -1) {
librarySettings.splice(libIndex, 1);
luaSettings.update(librarySettingsKey, librarySettings, vscode.ConfigurationTarget.Workspace);
}
}
}
@@ -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));
});
});
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "Node16",
"target": "ES2022",
"lib": [
"ES2022"
],
"sourceMap": true,
"strict": true, /* enable all strict type-checking options */
"paths": {
"dcs-script-compiler": ["../compiler/src/ScriptCompiler.ts"]
},
/* 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. */
}
}
@@ -0,0 +1,48 @@
# Welcome to your VS Code Extension
## What's in the folder
* This folder contains all of the files necessary for your extension.
* `package.json` - this is the manifest file in which you declare your extension and command.
* The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesnt yet need to load the plugin.
* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
* The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
* We pass the function containing the implementation of the command as the second parameter to `registerCommand`.
## Setup
* install the recommended extensions (amodio.tsl-problem-matcher, ms-vscode.extension-test-runner, and dbaeumer.vscode-eslint)
## Get up and running straight away
* Press `F5` to open a new window with your extension loaded.
* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`.
* Set breakpoints in your code inside `src/extension.ts` to debug your extension.
* Find output from your extension in the debug console.
## Make changes
* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`.
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
## Explore the API
* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`.
## Run tests
* Install the [Extension Test Runner](https://marketplace.visualstudio.com/items?itemName=ms-vscode.extension-test-runner)
* Run the "watch" task via the **Tasks: Run Task** command. Make sure this is running, or tests might not be discovered.
* Open the Testing view from the activity bar and click the Run Test" button, or use the hotkey `Ctrl/Cmd + ; A`
* See the output of the test result in the Test Results view.
* Make changes to `src/test/extension.test.ts` or create new test files inside the `test` folder.
* The provided test runner will only consider files matching the name pattern `**.test.ts`.
* You can create folders inside the `test` folder to structure your tests any way you want.
## Go further
* Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension).
* [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace.
* Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).