@@ -1349,15 +1349,30 @@ This is a Positron limitation we plan to fix. In the meantime, you can:
13491349 }
13501350
13511351 // 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
1353- // multiple parts) so we can emit it later on as part of execution
1354- // results.
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).
13551370 //
13561371 // Note that warnings emitted lazily on stdout will appear to be part of
13571372 // autoprint. We currently emit them on stderr, which allows us to
13581373 // differentiate, but that could change in the future:
13591374 // https://github.com/posit-dev/positron/issues/1881
1360- if otype == 0 && is_auto_printing ( ) {
1375+ if otype == 0 && is_auto_printing ( ) && self . pending_lines . is_empty ( ) {
13611376 self . autoprint_output . push_str ( & content) ;
13621377 return ;
13631378 }
0 commit comments