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

Change code location information for debugging (Pluto usecase) #582

Open
disberd opened this issue Aug 19, 2023 · 1 comment
Open

Change code location information for debugging (Pluto usecase) #582

disberd opened this issue Aug 19, 2023 · 1 comment

Comments

@disberd
Copy link
Contributor

disberd commented Aug 19, 2023

Hi All,

I have a question that would be helpful for adding debugger support for Pluto and I thought this would be the best place to ask.

I have tried hooking a running Pluto notebook with an active VSCode instance for debugging purposes and it was actually easier than expected so I had created a small utility package for that here:
https://github.com/disberd/PlutoVSCodeDebugger.jl

The debugging and breakpoint creations works very nicely when one wants to add breakpoint to functions that are not defined directly in the notebook (so functions that are either defined in imported modules or in directly included files)

The reason this is not very straightforward for code defined in the notebook is that Pluto itself modifies the LineNumberNodes of the code within the notebook to also include information about the notebook cell where the code is defined.

The format of this modified LNN is the following filename#==#cell_uuid:line_number_from_cell_start. So it basicaly changes the filename to add the cell uuid (separated by #==#) and modifies the line number by counting lines only from the start of the cell.

This is the reason why adding a breakpoint in the notebook file won't cause the debugger to stop, as the file actually tracked by the debugger is another (nonexistant) one.

For example, entering (e.g. with @enter) inside this function defined in the notebook:
image

the debugger in VSCode will open a new non-existent file as follows:
image

Pluto relies pretty heavily on this modified LNN to simplify error stacktraces within the notebook so I believe it would be very difficult to change that part of Pluto.

What I would like to know is whether there is a way to modify those LNN just for debugger purposes with some code that maybe exists either in JuliaInterpreter or CodeTracking.
This could happen directly within custom @run or @enter macro specifically devised for Pluto which ideally would do something like this:

macro run(command)
# Clean LNNs of code defined inside Pluto by removing cell data from file name
# Execute the normal @run
# Put back the Pluto LNNs in the code defined in the notebook
end

Let me know if you have any idea on whether this is feasible or not without forcing requiring Pluto itself to change its internal LNN representation.

Alberto

@timholy
Copy link
Member

timholy commented Aug 20, 2023

Without looking into it myself, I can't really say. Note that CodeTracking does provide some support for functions defined in the REPL, which is conceptually a bit similar.

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

No branches or pull requests

2 participants