Skip to content

Commit b46e79d

Browse files
committed
wip
1 parent e252354 commit b46e79d

File tree

1 file changed

+45
-34
lines changed

1 file changed

+45
-34
lines changed

crates/ark/src/interface.rs

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ impl RMain {
597597
buflen: c_int,
598598
_hist: c_int,
599599
) -> ConsoleResult {
600+
// TODOC: Why incomplete is fine (vec is necessarily empty, if there's a
601+
// syntax error R will throw and vec will be flushed)
602+
600603
if let Some(console_result) = self.handle_pending_line(buf, buflen) {
601604
return console_result;
602605
}
@@ -849,7 +852,7 @@ impl RMain {
849852
self.error_occurred = false;
850853

851854
match input {
852-
ConsoleInput::Input(mut code) => {
855+
ConsoleInput::Input(code) => {
853856
// Handle commands for the debug interpreter
854857
if self.dap.is_debugging() {
855858
let continue_cmds = vec!["n", "f", "c", "cont"];
@@ -858,13 +861,8 @@ impl RMain {
858861
}
859862
}
860863

861-
// In notebooks, wrap in braces so that only the last complete
862-
// expression is auto-printed
863-
if let SessionMode::Notebook = self.session_mode {
864-
code = format!("{{ {code} }}");
865-
}
864+
// Check for incomplete inputs
866865

867-
// WIP: Split input into multiple lines
868866
let code = self.handle_input(code);
869867

870868
Self::on_console_input(buf, buflen, code);
@@ -1348,33 +1346,46 @@ This is a Positron limitation we plan to fix. In the meantime, you can:
13481346
}
13491347
}
13501348

1351-
// If we are at top-level, we're handling visible output auto-printed by
1352-
// the R REPL. We accumulate this output (it typically comes in multiple
1353-
// parts) so we can emit it later on as part of the execution reply
1354-
// message sent to Shell, as opposed to an Stdout message sent on IOPub.
1355-
//
1356-
// However, if autoprint is dealing with an intermediate expression
1357-
// (i.e. `a` and `b` in `a\nb\nc`), we should emit it on IOPub. We
1358-
// only accumulate autoprint output for the very last expression. The
1359-
// way to distinguish between these cases is whether there are still
1360-
// lines of input pending. In that case, that means we are on an
1361-
// intermediate expression.
1362-
//
1363-
// Note that we implement this behaviour (streaming autoprint results of
1364-
// intermediate expressions) specifically for Positron, and specifically
1365-
// for versions that send multiple expressions selected by the user in
1366-
// one request. Other Jupyter frontends do not want to see output for
1367-
// these intermediate expressions. And future versions of Positron will
1368-
// never send multiple expressions in one request
1369-
// (https://github.com/posit-dev/positron/issues/1326).
1370-
//
1371-
// Note that warnings emitted lazily on stdout will appear to be part of
1372-
// autoprint. We currently emit them on stderr, which allows us to
1373-
// differentiate, but that could change in the future:
1374-
// https://github.com/posit-dev/positron/issues/1881
1375-
if otype == 0 && is_auto_printing() && self.pending_lines.is_empty() {
1376-
self.autoprint_output.push_str(&content);
1377-
return;
1349+
if stream == Stream::Stdout && is_auto_printing() {
1350+
// If we are at top-level, we're handling visible output auto-printed by
1351+
// the R REPL. We accumulate this output (it typically comes in multiple
1352+
// parts) so we can emit it later on as part of the execution reply
1353+
// message sent to Shell, as opposed to an Stdout message sent on IOPub.
1354+
//
1355+
// However, if autoprint is dealing with an intermediate expression
1356+
// (i.e. `a` and `b` in `a\nb\nc`), we should emit it on IOPub. We
1357+
// only accumulate autoprint output for the very last expression. The
1358+
// way to distinguish between these cases is whether there are still
1359+
// lines of input pending. In that case, that means we are on an
1360+
// intermediate expression.
1361+
//
1362+
// Note that we implement this behaviour (streaming autoprint results of
1363+
// intermediate expressions) specifically for Positron, and specifically
1364+
// for versions that send multiple expressions selected by the user in
1365+
// one request. Other Jupyter frontends do not want to see output for
1366+
// these intermediate expressions. And future versions of Positron will
1367+
// never send multiple expressions in one request
1368+
// (https://github.com/posit-dev/positron/issues/1326).
1369+
//
1370+
// Note that warnings emitted lazily on stdout will appear to be part of
1371+
// autoprint. We currently emit them on stderr, which allows us to
1372+
// differentiate, but that could change in the future:
1373+
// https://github.com/posit-dev/positron/issues/1881
1374+
1375+
// Handle last expression
1376+
if self.pending_lines.is_empty() {
1377+
self.autoprint_output.push_str(&content);
1378+
return;
1379+
}
1380+
1381+
// In notebooks, we don't emit results of intermediate expressions
1382+
if self.session_mode == SessionMode::Notebook {
1383+
return;
1384+
}
1385+
1386+
// In Positron, fall through if we have pending input. This allows
1387+
// autoprint output for intermediate expressions to be emitted on
1388+
// IOPub.
13781389
}
13791390

13801391
// Stream output via the IOPub channel.

0 commit comments

Comments
 (0)