From bff8c59d930625730748a722fc3fe36aae10e7a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Bene=C5=A1?= Date: Sun, 20 Oct 2024 17:47:38 +0200 Subject: [PATCH] Cleanup module parsing --- src/extension.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index b5250cc..a8eb1cd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -40,11 +40,21 @@ async function getEffektRepl() { } async function runEffektFile(uri: vscode.Uri) { + // Save the document if it has unsaved changes + const document = await vscode.workspace.openTextDocument(uri); + if (document.isDirty) { + await document.save(); + } + const repl = await getEffektRepl(); - const relativePath = path.parse(vscode.workspace.asRelativePath(uri)); - const modulePrefix = relativePath.dir.split(path.delimiter).join('/') - const module = `${modulePrefix}${modulePrefix ? '/' : ''}${relativePath.name}` + const relativePath = vscode.workspace.asRelativePath(uri); + const parsedPath = path.parse(relativePath); + + // Remove .effekt or .effekt.md extension + const moduleName = parsedPath.base.replace(/\.effekt(\.md)?$/, ''); + + const module = path.join(parsedPath.dir, moduleName).split(path.sep).join('/'); repl.sendText(':reset') repl.sendText(`import ${module}`);