microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.27k stars 284 forks source link

Add `pathMappings` to remote Jupyter server debugging #12826

Open mcitoler opened 1 year ago

mcitoler commented 1 year ago

One of my favorite features of the vscode-jupyter extension is the ability to debug notebook cells and put breakpoints on my own python modules. However, I find myself in a situation where this is not possible. If you are running your notebooks in a remote server, this no longer works because stepping through the code will use the remote filepaths and, unless your local directory layout is exactly the same as your remote layout, you won't be able to step through your code because VSCode tries to open the file with the remote filepath: Screenshot 2023-02-13 at 09 12 32

Depending on your remote setup, you might get around this by setting up a devcontainer with the same image as your remote server but oftentimes you don't have the flexibility to do so.

Fortunately, we already have the pathMappings feature that can be used to configure your launch.json to debug scripts remotely, see docs. It would be very useful to include a hook through the settings.json so we can add a pathMappings property to debug in remote Jupyter servers. i.e. something like:

...
"jupyter.debugJustMyCode": true,
"jupyer.remoteDebugging": [
    // One configuration per specified jupyter server
    // in `Jupyter: Specify Jupyter Server for Connections` picker
    {
        "host": "<Remote Jupyter Server URL>",
        "pathMappings": [
            {
                "local": "/path/to/local/dir",
                "remote": "path/to/remote/dir",
            }
        ]
    }
]
...
roblourens commented 1 year ago

I suppose it works when the file layout is the same as on the remote? But even if the relative file layout is the same, you might be in a different root directory, and that would break it, right?

mcitoler commented 1 year ago

I suppose it works when the file layout is the same as on the remote?

That's correct. In my setting, I was able to make it work because I could run a devcontainer using the same image that is running in the remote server and I could replicate the source code mounts.

But even if the relative file layout is the same, you might be in a different root directory, and that would break it, right?

As far as I understand that is correct as well. Unless the absolute path in both local and remote is the same, it currently doesn't work.