This commit is contained in:
ex61wi
2026-04-06 20:59:36 +02:00
parent aa0bc83c32
commit 3d9ea1f24e
6 changed files with 107 additions and 28 deletions
+5 -1
View File
@@ -9,5 +9,9 @@
"dist": true // set this to false to include "dist" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
"typescript.tsc.autoDetect": "off",
"cSpell.words": [
"dutchie",
"dutchies"
]
}
+13
View File
@@ -0,0 +1,13 @@
{
"name": "dcs-mission-scripting-tools-compiler",
"devDependencies": {
"@types/node": "25.5.2"
},
"scripts": {
"build": "tsc -p . --outDir dist",
"watch": "tsc -p . --outDir dist --watch"
},
"files": [
"dist/**/*"
]
}
+2
View File
@@ -64,6 +64,8 @@ export class ScriptCompiler {
const readStart = Date.now();
for (const entry of entries) {
if (entry.isFile() && entry.name.endsWith('.lua')) {
const fullPath = path.join(entry.parentPath ?? entry.path, entry.name);
const relativePath = path.relative(this.options.sourcePath, fullPath);
const content = fs.readFileSync(fullPath, 'utf-8');
+28 -3
View File
@@ -19,18 +19,38 @@
"categories": [
"Other"
],
"activationEvents": [],
"activationEvents": [
"onLanguage:lua",
"workspaceContains:**/*.lua"
],
"main": "./dist/extension.js",
"contributes": {
"configuration": {
"title": "Dutchies DCS Scripting Tools Settings",
"title": "Dutchies DCS Tools",
"type" : "object",
"properties": {
"dutchies-dcs-scripting-tools.dcsTypes": {
"type": "boolean",
"default": true,
"description": "Enable or disable DCS Types (adds types for DCS functions and objects)"
},
"dutchies-dcs-scripting-tools.spearheadTypes": {
"type": "boolean",
"default": false,
"description": "(Coming Soon) Enable or disable Spearhead Types (requires DCS Types to be enabled)"
},
"dutchies-dcs-scripting-tools.compileAt" : {
"type": "string",
"enum": ["onSave", "onCompileCommand"],
"default": "onCompileCommand",
"description": "When to compile the Lua scripts"
"description": "When to compile the Lua script"
},
"dutchies-dcs-scripting-tools.includeDevelopmentScript": {
"type": "boolean",
"default": false,
"description": "Adds an additional script. This can be referenced from DCS through doScriptFile. This will then execute the compiles script. This way you don't have to reinsert the script on each change, but can just hit 'restart'."
}
}
},
"grammars": [
@@ -41,6 +61,11 @@
}
],
"commands": [
{
"command": "dutchies-dcs-scripting-tools.openSettings",
"title": "Open Settings",
"category": "Dutchies DCS Tools"
},
{
"command": "dutchies-dcs-scripting-tools.enable",
"title": "Enable",
+34 -3
View File
@@ -13,30 +13,44 @@ let pluginPath : string | undefined;
const logger = new Logger();
const extensionName = 'dutchies-dcs-scripting-tools';
const publisherName = 'dutchie031';
const extensionSettingsFilter = `@ext:${publisherName}.${extensionName}`;
//TODO:
// - ENABLE/DISABLE with settings instead of commands (or both)
// 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');
context.subscriptions.push(
vscode.commands.registerCommand('dutchies-dcs-scripting-tools.enable', () => {
addPluginPathToSettings();
vscode.commands.executeCommand(
"lua.startServer"
);
vscode.window.showInformationMessage('Dutchies DCS Scripting Tools enabled.');
});
})
);
context.subscriptions.push(
vscode.commands.registerCommand('dutchies-dcs-scripting-tools.disable', () => {
removePluginPathFromSettings();
vscode.commands.executeCommand(
"lua.startServer"
);
vscode.window.showInformationMessage('Dutchies DCS Scripting Tools disabled.');
});
})
);
context.subscriptions.push(
vscode.commands.registerCommand('dutchies-dcs-scripting-tools.openSettings', () => {
vscode.commands.executeCommand("workbench.action.openSettings", `@ext:${extensionSettingsFilter}`);
}));
context.subscriptions.push(
vscode.commands.registerCommand('dutchies-dcs-scripting-tools.compileLuaScripts', async () => {
try{
const start = Date.now();
@@ -46,13 +60,28 @@ export function activate(context: vscode.ExtensionContext) {
}catch(err){
vscode.window.showErrorMessage('Error compiling Lua scripts: ' + (err as Error).message);
}
})
);
vscode.workspace.onDidSaveTextDocument(async(document) => {
logger.info(`Document saved: ${document.uri.fsPath} | Language: ${document.languageId}`);
if (document.languageId === 'lua') {
const config = vscode.workspace.getConfiguration(extensionName);
const compileAt = config.get<string>('compileAt') || "undefined";
if (compileAt === 'onSave') {
await compileLuaScripts();
}
}
});
logger.info('Dutchies DCS Scripting Tools extension activated');
}
// This method is called when your extension is deactivated
export function deactivate()
{
removePluginPathFromSettings();
logger.info('Dutchies DCS Scripting Tools extension deactivated');
}
class CompilationLogger implements ICompilationLogger {
@@ -72,6 +101,8 @@ class CompilationLogger implements ICompilationLogger {
}
async function compileLuaScripts() {
logger.clear();
logger.info("Compiling...");
const config = vscode.workspace.getConfiguration('dcsScriptingTools');
const sourcePath = config.get<string>('luaSourcePath') || '${workspaceFolder}/src';
@@ -20,6 +20,10 @@ export class Logger {
this.outputChannel.appendLine(`[${new Date().toISOString()}][ERROR] ${message}`);
}
clear() {
this.outputChannel.clear();
}
dispose() {
this.outputChannel.dispose();
}