Skip to content

Commit

Permalink
Cleanup module parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jiribenes committed Oct 20, 2024
1 parent 49bc8c0 commit bff8c59
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down

0 comments on commit bff8c59

Please sign in to comment.