diff --git a/.vscode/settings.json b/.vscode/settings.json index 5c5ac48..456a965 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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" + ] } \ No newline at end of file diff --git a/compiler/package.json b/compiler/package.json new file mode 100644 index 0000000..1223d4a --- /dev/null +++ b/compiler/package.json @@ -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/**/*" + ] +} \ No newline at end of file diff --git a/compiler/src/ScriptCompiler.ts b/compiler/src/ScriptCompiler.ts index 4324e0e..160038b 100644 --- a/compiler/src/ScriptCompiler.ts +++ b/compiler/src/ScriptCompiler.ts @@ -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'); diff --git a/dutchies-dcs-scripting-tools/package.json b/dutchies-dcs-scripting-tools/package.json index 5ceca6c..d818eca 100644 --- a/dutchies-dcs-scripting-tools/package.json +++ b/dutchies-dcs-scripting-tools/package.json @@ -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", diff --git a/dutchies-dcs-scripting-tools/src/extension.ts b/dutchies-dcs-scripting-tools/src/extension.ts index 09339d8..0075b7b 100644 --- a/dutchies-dcs-scripting-tools/src/extension.ts +++ b/dutchies-dcs-scripting-tools/src/extension.ts @@ -13,46 +13,75 @@ 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'); - - 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.'); - }); + 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.'); + }) + ); - vscode.commands.registerCommand('dutchies-dcs-scripting-tools.compileLuaScripts', async () => { - try{ - const start = Date.now(); - await compileLuaScripts(); - const end = Date.now(); - 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); + 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(); + await compileLuaScripts(); + const end = Date.now(); + 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); + } + }) + ); + + 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('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('luaSourcePath') || '${workspaceFolder}/src'; diff --git a/dutchies-dcs-scripting-tools/src/logger.ts b/dutchies-dcs-scripting-tools/src/logger.ts index a80a7d5..99d4a09 100644 --- a/dutchies-dcs-scripting-tools/src/logger.ts +++ b/dutchies-dcs-scripting-tools/src/logger.ts @@ -20,6 +20,10 @@ export class Logger { this.outputChannel.appendLine(`[${new Date().toISOString()}][ERROR] ${message}`); } + clear() { + this.outputChannel.clear(); + } + dispose() { this.outputChannel.dispose(); }