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

Feature/edit code #830

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sbendary25
Copy link

Describe the changes you have made:

scan and edit recently edited code by creating a while loop around the "executing" chunk conditional block

Reference any relevant issue (Fixes #000)

this is based on the following PR by ericrallen
#612

  • I have performed a self-review of my code:

I have tested the code on the following OS:

  • Windows
  • MacOS
  • Linux

AI Language Model (if applicable)

  • GPT4
  • GPT3
  • Llama 7B
  • Llama 13B
  • Llama 34B
  • Huggingface model (Please specify which one)

@KillianLucas
Copy link
Collaborator

Nice, thanks @sbendary25 for working on this and of course @ericrallen for the incredible initial PR.

If this can be adapted to the current codebase (I think this PR is from a few weeks ago) I'd be happy to merge. I'd probably simplify it tho — for example I think this shouldn't interface with any code scanning utils (any code the user has written = deemed safe by them, I think). Is the only reason for that crossover because we also use a tempfile to scan code?

I'd probably want to reduce it to a magic command which edits the last code block, then continues OI from there.

This way user's can:

  • Decline to run a code block by pressing N
  • Press %e or %edit or something
  • We create a temporary file, populate it with the last code block
  • ↑ Open it in the user's preferred editor
  • yaspin fires up, "Code editor opened. Save your changes then press ENTER here to run modified code."
  • They edit the file, save it, press ENTER
  • We edit the last code block in interpreter.messages, re-display it, continue OI from there

@Kreijstal
Copy link

I am excited for this one

@Eliaskhal
Copy link

I think what we can do:
1- ask the user to set their favorite editor once (maybe in the beginning), for example 'code'.
2- Instead of asking the user if they want to run the code or no, we can add another option to run the code.
3- if they choose to edit the code: save the code in a temp file, then run a subprocess opening the editor and waiting for it to close.

if system_platform == 'windows':
        subprocess.run(['start', 'your_editor', filename], shell=True)

When the user is done we can give the option to re-edit the code or run it.

@Notnaton
Copy link
Collaborator

#942

@Notnaton Notnaton mentioned this pull request Feb 3, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants