Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code lens for running main #28

Merged
merged 6 commits into from
Oct 21, 2024
Merged

Code lens for running main #28

merged 6 commits into from
Oct 21, 2024

Conversation

jiribenes
Copy link
Contributor

@jiribenes jiribenes commented Oct 20, 2024

Addresses the main (haha!) part of #12 by adding "Run" options over def main(), that opens up a REPL, imports a file, and runs it:
Screenshot 2024-10-20 at 17 53 56


How does it work?

  • search for functions that look like def main() =
  • if it finds one, create a code lens for the URI/file it is in
  • clicking run creates a REPL terminal (if it doesn't exist for that file already), imports the file and runs main

The code still needs heavy refactoring and a bit of testing, this is just a proof of concept born out of frustration.


TODO:

  • literate effekt
  • should the "Run" button also save the file? otherwise the results might be unexpected (otherwise it runs on the previous saved version)
  • how do other languages manage the terminals? should there always be only at most one for the whole project? ~> one per project only
  • should the terminal be even a terminal? wouldn't it be better if it was just an output? ~> REPL terminal
  • use a custom, less talkative, path-taking :import? (see below)
  • ideally, get a list of "runnable" defs from the compiler (no args, no effects, no custom captures), then show this |> Run button over all of those instead of showing it only over things starting with def main() [as outlined in Allow running Effekt programs directly from VS Code #12]

@jiribenes jiribenes added the enhancement New feature or request label Oct 20, 2024
src/extension.ts Outdated
Comment on lines 46 to 47
const modulePrefix = relativePath.dir.split(path.delimiter).join('/')
const module = `${modulePrefix}${modulePrefix ? '/' : ''}${relativePath.name}`
Copy link
Contributor Author

@jiribenes jiribenes Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty sad, we need to convert a relative path to a module path.
It doesn't work for files named "weirdly" like 1-intro.effekt.md since those aren't valid module identifiers.

A reasonable workaround would be to use something like :import "<path-as-a-string>", letting the compiler deal with it. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +43 to +47
// Save the document if it has unsaved changes
const document = await vscode.workspace.openTextDocument(uri);
if (document.isDirty) {
await document.save();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried out a version where this was a pop-up, but it was annoying -- I never want to run the stale version that I can't see...

@jiribenes jiribenes marked this pull request as ready for review October 21, 2024 13:35
@jiribenes jiribenes merged commit 79c05e0 into master Oct 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant