posit-dev / positron

Positron, a next-generation data science IDE
Other
2.42k stars 73 forks source link

Show legacy Jupyter execute_reply data in Console #508

Open petetronic opened 1 year ago

petetronic commented 1 year ago

While the Jupyter specification mentions that the use of payloads is deprecated, a replacement has not been finalized. Some ipython output still makes use of the execute_reply message with a payload defined.

If the data in the payload is text/plain, we should at least consider showing this in the Positron Console REPL, even if it is not intended for Jupyter notebook cell output.

We may need a bit of plumbing in our runtime middleware to get these messages to the Console.

petetronic commented 1 year ago

One example that generates this type of output is the iPython %less magic. If you try to print the contents of a text file in your working directory, the content is returned on the shell channel in an execute_reply message, however we do not show this in the Console.

petetronic commented 1 year ago

Truncated example of a reply to %less yourfile.txt:

[Positron] RECV execute_reply from shell: 

{
    "header":
    {
        "msg_type": "execute_reply",
        ...
    },
    "parent_header":
    {
        "msg_type": "execute_request",
        ...
    },
    ...
    "content":
    {
        "status": "ok",
        ...
        "payload":
        [
            {
                "source": "page",
                "data":
                {
                    "text/plain": "Your text file content is returned here..."
                }
            }
        ]
    }
}
petetronic commented 1 year ago

We can discuss with the team if these output types are marked in some way different from those from execute_result.

jmcphers commented 1 year ago

Because this is file content, I've half a mind to have it hosted in an editor buffer instead of dumped into the Console. You said that some of these are decorated with ANSI escape sequences, though, right?

petetronic commented 1 year ago

Right, so another example I've seen is "help" like information about a magic. For example, %colors? tells you how to use the %colors magic. Its content describing the colors magic's options is sent in an execute_reply payload but it has ANSI control sequences to color items.

petetronic commented 1 year ago

(As an aside, some other magics, like the %ls alias, sends its output through the normal iopub execute_result, and that does show up in our Console today).

seeM commented 1 year ago

For reference, here are the magic commands I've found that use the page payload type:

I agree that we could probably intercept these and either display the result in a new buffer, or in the help pane.