Support Jupytext-style line comments for REPL evaluation ranges (#15073)

This adds support for detecting line comments in the
[Jupytext](https://jupytext.readthedocs.io/) format. When line comments
such as `# %%` is present, invoking `repl: run` will evaluate the code
between these line comments as a unit.

/cc @rgbkrk 

```py
# %%
# This is my first block
print(1)
print(2)

# %%
# This is my second block
print(3)
```

Release Notes:

- N/A

---------

Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Antonio <antonio@zed.dev>
Co-authored-by: Thorsten <thorsten@zed.dev>
Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
This commit is contained in:
Nathan Sobo 2024-07-24 11:53:58 +02:00 committed by GitHub
parent af4b9805c9
commit 87d93033d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 295 additions and 81 deletions

View file

@ -377,7 +377,12 @@ impl Session {
self.blocks.clear();
}
pub fn execute(&mut self, code: &str, anchor_range: Range<Anchor>, cx: &mut ViewContext<Self>) {
pub fn execute(
&mut self,
code: String,
anchor_range: Range<Anchor>,
cx: &mut ViewContext<Self>,
) {
let Some(editor) = self.editor.upgrade() else {
return;
};
@ -387,7 +392,7 @@ impl Session {
}
let execute_request = ExecuteRequest {
code: code.to_string(),
code,
..ExecuteRequest::default()
};