From 3083cf4b0b85c2d0599b34a384b166e6533e0898 Mon Sep 17 00:00:00 2001 From: ex61wi <54616262+dutchie031@users.noreply.github.com> Date: Tue, 7 Apr 2026 09:30:35 +0200 Subject: [PATCH] Better error handling --- compiler/src/ScriptCompiler.ts | 17 ++++---- compiler/tsconfig.json | 14 +++++++ dutchies-dcs-scripting-tools/src/extension.ts | 40 ++++++++++++++++--- dutchies-dcs-scripting-tools/tsconfig.json | 3 +- package-lock.json | 6 +-- package.json | 11 ++++- 6 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 compiler/tsconfig.json diff --git a/compiler/src/ScriptCompiler.ts b/compiler/src/ScriptCompiler.ts index 160038b..2ce632b 100644 --- a/compiler/src/ScriptCompiler.ts +++ b/compiler/src/ScriptCompiler.ts @@ -64,9 +64,7 @@ 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 fullPath = path.join(entry.parentPath, entry.name); const relativePath = path.relative(this.options.sourcePath, fullPath); const content = fs.readFileSync(fullPath, 'utf-8'); @@ -90,7 +88,7 @@ export class ScriptCompiler { const writeEnd = Date.now(); metricsMeter.writeTimeMs = (writeEnd - writeStart); - writer.logDependencyTree(); + // writer.logDependencyTree(); this.logger.info(`Compilation complete. Output written to ${path.join(this.options.outputPath, this.options.outputFileName!)}`); const end = Date.now(); @@ -370,16 +368,19 @@ class Writer { const depth : number = 1; this.logger.writeLine('Dependency Tree :'); const logFileRecursive = (parsedFile: ParsedFile, currentDepth: number) => { - if (visited.has(parsedFile.fileKey)) { + if(currentDepth === 0 && visited.has(parsedFile.fileKey)) { return; } + visited.add(parsedFile.fileKey); - let padding = ' '.repeat(currentDepth); + let padding = ' '.repeat(currentDepth * 2); if (currentDepth > 0) { - padding = ' '.repeat(currentDepth) + '└─>'; + padding += '└─>'; } + const printable = parsedFile.fileKey.replace(LUA_SCRIPT_GLOBAL_KEYWORD + '.', ''); - this.logger.writeLine(padding + printable); + const lastPart = printable.split('.').pop(); + this.logger.writeLine(`${padding} ${lastPart} ${' '.repeat(Math.max(0, 64 - padding.length - (lastPart ? lastPart.length : 0)))} ${printable}`); for (const dep of parsedFile.dependencies) { const depFile = this.files.get(dep.fileKey); if (depFile) { diff --git a/compiler/tsconfig.json b/compiler/tsconfig.json new file mode 100644 index 0000000..a3ea781 --- /dev/null +++ b/compiler/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "module": "Node16", + "target": "ES2022", + "lib": ["ES2022"], + "strict": true, + "sourceMap": true, + "types": ["node"], + "esModuleInterop": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src/**/*"] +} diff --git a/dutchies-dcs-scripting-tools/src/extension.ts b/dutchies-dcs-scripting-tools/src/extension.ts index 0075b7b..82517c1 100644 --- a/dutchies-dcs-scripting-tools/src/extension.ts +++ b/dutchies-dcs-scripting-tools/src/extension.ts @@ -26,9 +26,9 @@ export function activate(context: vscode.ExtensionContext) { pluginPath = context.asAbsolutePath('lua-addons'); context.subscriptions.push( - vscode.commands.registerCommand('dutchies-dcs-scripting-tools.enable', () => { + vscode.commands.registerCommand('dutchies-dcs-scripting-tools.enable', async () => { addPluginPathToSettings(); - vscode.commands.executeCommand( + await vscode.commands.executeCommand( "lua.startServer" ); vscode.window.showInformationMessage('Dutchies DCS Scripting Tools enabled.'); @@ -36,9 +36,9 @@ export function activate(context: vscode.ExtensionContext) { ); context.subscriptions.push( - vscode.commands.registerCommand('dutchies-dcs-scripting-tools.disable', () => { + vscode.commands.registerCommand('dutchies-dcs-scripting-tools.disable', async () => { removePluginPathFromSettings(); - vscode.commands.executeCommand( + await vscode.commands.executeCommand( "lua.startServer" ); vscode.window.showInformationMessage('Dutchies DCS Scripting Tools disabled.'); @@ -46,8 +46,8 @@ export function activate(context: vscode.ExtensionContext) { ); context.subscriptions.push( - vscode.commands.registerCommand('dutchies-dcs-scripting-tools.openSettings', () => { - vscode.commands.executeCommand("workbench.action.openSettings", `@ext:${extensionSettingsFilter}`); + vscode.commands.registerCommand('dutchies-dcs-scripting-tools.openSettings', async () => { + await vscode.commands.executeCommand("workbench.action.openSettings", `@ext:${extensionSettingsFilter}`); })); context.subscriptions.push( @@ -74,6 +74,18 @@ export function activate(context: vscode.ExtensionContext) { } }); + vscode.workspace.onDidChangeConfiguration(async(event) => { + if (event.affectsConfiguration(`${extensionName}.dcsTypes`)) { + const config = vscode.workspace.getConfiguration(extensionName); + const dcsTypesEnabled = config.get('dcsTypes') || false; + if (dcsTypesEnabled) { + addPluginPathToSettings(); + } else { + removePluginPathFromSettings(); + } + } + }); + logger.info('Dutchies DCS Scripting Tools extension activated'); } @@ -148,6 +160,22 @@ async function compileLuaScripts() { } } +async function enableIntellisense() { + addPluginPathToSettings(); + await vscode.commands.executeCommand( + "lua.startServer" + ); + vscode.window.showInformationMessage('Dutchies DCS Scripting Tools enabled.'); +} + +async function disableIntellisense() { + removePluginPathFromSettings(); + await vscode.commands.executeCommand( + "lua.startServer" + ); + vscode.window.showInformationMessage('Dutchies DCS Scripting Tools disabled.'); +} + function addPluginPathToSettings() { if (pluginPath) { const luaSettings = vscode.workspace.getConfiguration(luaWorkSpaceSettingKey); diff --git a/dutchies-dcs-scripting-tools/tsconfig.json b/dutchies-dcs-scripting-tools/tsconfig.json index 1816a24..b413cb5 100644 --- a/dutchies-dcs-scripting-tools/tsconfig.json +++ b/dutchies-dcs-scripting-tools/tsconfig.json @@ -11,7 +11,8 @@ "dcs-script-compiler": ["../compiler/src/ScriptCompiler.ts"] }, "types": [ - "node" + "node", + "mocha" ], /* Additional Checks */ "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ diff --git a/package-lock.json b/package-lock.json index e76ebb0..1a0b4f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dutchies-dcs-scripting-tools" ], "devDependencies": { + "@types/mocha": "^10.0.10", "@types/node": "^25.5.2" } }, @@ -911,7 +912,6 @@ "integrity": "sha512-BtE0k6cjwjLZoZixN0t5AKP0kSzlGu7FctRXYuPAm//aaiZhmfq1JwdYpYr1brzEspYyFeF+8XF5j2VK6oalrA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.54.0", "@typescript-eslint/types": "8.54.0", @@ -1144,7 +1144,6 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -2081,7 +2080,6 @@ "integrity": "sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -5171,7 +5169,6 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -5302,7 +5299,6 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 6256f4e..d8351ff 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,15 @@ "dutchies-dcs-scripting-tools" ], "devDependencies": { - "@types/node": "^25.5.2" + "@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" } }