feat: add api for running text input as attempt
closes #11
this PR adds the run_lines and open_extension_select apis, which allows the user to run an attempt using a list of lines as code.
instead of opening ad attempt in a separate buffer and then running it, you can now use this api to run code you have in your visual selection, code in a register, or your clipboard as a few examples.
the open_extension_select is a convenience wrapper for selecting an extension from the configured config.opts.ext_options before passing the chosen ext to run_lines.
@m-demare heyo, here's a draft which only implements the run_lines function. i find that it's a bit dodgy and have a few more questions i need your help with.
for a lack of understanding of how lua async works. . . when i use the run_lines function on some code, its very inconsistent as to when it works. sometimes it runs fine, sometimes it fails, and the success rates depend on what language i'm trying to execute the code as. it also might fail in two different ways, either because the file doesn't exist, or because Vimscript function must not be called in a fast event context, but i have no idea where thats happening. i'll keep digging, but any insight is very welcome :)
Seemed to just be me having missing deps... this is ready now @m-demare
You've probably already discovered this (sorry again for the delay, crazy weeks) but the error "Vimscript function must not be called in a fast event context" is usually related to a missing vim.schedule:
vim.schedule({fn}) *vim.schedule()*
Schedules {fn} to be invoked soon by the main event-loop. Useful to avoid
|textlock| or other temporary restrictions.
A lot of buffer-related functions cannot be called from an async libuv callback. vim.schedule schedules it to be run in the next iteration of the main event-loop, avoiding this issue
Hey, i'm on a business trip at the moment. I'll see if i can find some time this weekend to look over your comments properly. I believe i solved the schedule stuff. It was an error with my config code, not any of the PR stuff if i remember correctly.
I havent really tested many use cases with this, but my own use case seems to work fine after a small bit if tinkering in my own setup. I have a thing where i put the results in a split instead of showing it as a notification. That has cause a few extra issues. I did try to turn all that off for a few tests and it seemed to work fine for c#, lua, python, and json (just running jq on it). If you find some time in your busy schedule to just do some quick tests yourself as a sanity check that would be very helpful :)
(Leaving this for myself)
Add some help documentation
@m-demare i'd say its ready now. lmk if you need anything else :)
@m-demare any change on getting merged soon? i under you're busy so just wanted to ping you in-case it just slipped your mind :)