jupyterlab-contrib / jupyterlab-quickopen

Quickly open a file in JupyterLab by typing part of its name
BSD 3-Clause "New" or "Revised" License
76 stars 14 forks source link

Support opening Jupytext notebooks as notebooks #63

Open yjoer opened 3 days ago

yjoer commented 3 days ago

Is your feature request related to a problem? Please describe.

The current extension does not differentiate Python source files and Jupytext notebooks as they share the same .py extension. Therefore, it will open all files ending with .py in a text editor.

Describe the solution you'd like

Open Jupytext notebooks as notebooks.

Describe alternatives you've considered

I created a POC at https://github.com/yjoer/jupyterlab-quickopen/tree/poc-1. When we hit enter after selecting a path, the client sends a request to the server if it ends with .py. On the server, we will read the first line of the file to identify the file type. I have implemented the tests for the percent format with and without metadata. If it matches, the handler will return "notebook" as the widget name otherwise "default". This allows us to open a conventional Python file in a text editor.

https://github.com/user-attachments/assets/6dd7dc15-8eca-421e-a6bf-1694511a52b8

Additional context

N/A

jtpio commented 2 days ago

Thanks @yjoer for opening the issue :+1:

I haven't looked too much into it yet, but maybe there is something to be done on the client side only, that would involve checking the preferred factory for a document before opening it here:

https://github.com/jupyterlab-contrib/jupyterlab-quickopen/blob/042880ab1d9b26c742c303c048bc1d48b22acd8e/src/index.ts#L158

yjoer commented 2 days ago

The challenge is that the path alone does not help identify the appropriate widget. It could be opened in the text editor or notebook before looking at the content. I believe DocumentManager does not know the content given a path. Do we have some other ways to peek at the files?