From 7e660452cc37b4845ae915338d04e0bed1481092 Mon Sep 17 00:00:00 2001 From: livecodeAlex Date: Fri, 19 Apr 2024 18:52:58 +0100 Subject: [PATCH] Fix for document name parsing --- .../livecodescript/LCSserverProvider.ts | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/features/livecodescript/LCSserverProvider.ts b/src/features/livecodescript/LCSserverProvider.ts index 46adc98..df48811 100644 --- a/src/features/livecodescript/LCSserverProvider.ts +++ b/src/features/livecodescript/LCSserverProvider.ts @@ -14,22 +14,24 @@ export default class LivecodescriptServerProvider { subscriptions.push(this); subscriptions.push( vscode.workspace.onDidSaveTextDocument( - async ({ fileName, languageId, lineAt }) => { - console.log("DOCUMENT SAVED"); - if (this.enabled && languageId === "livecodescript") { - const regex = '"([-.:a-zA-Z0-9_s?!]+)"'; - const scriptName = lineAt(0).text.match(regex)[1]; - const query = { - command: "reload script", - stack: scriptName, - filename: fileName, - }; + async ({ fileName, languageId, lineAt }) => { + console.log("DOCUMENT SAVED"); + if (this.enabled && languageId === "livecodescript") { + const regex = /"([-.:a-zA-Z0-9_\s?!]+)"/; + const match = lineAt(0).text.match(regex) + /* if the regex finds nothing it returns null so we run a check to avoid erroring out */ + const scriptName = match ? match[1] : null + const query = { + command: scriptName === null ? `Error parsing script name from file ${fileName}!` : "reload script", + stack: scriptName, + filename: fileName, + }; - await this.sender.send(query); - } - } - ) - ); + await this.sender.send(query); + } + } + ) + ); subscriptions.push( vscode.workspace.onDidChangeConfiguration(() => this.loadConfiguration()