Extension Development: How to get list of ALL open files in JupyterLab?

I’m building a JupyterLab extension. I need to get list of all open files in JupyterLab session on the client side extension. (open = open inside a JypyterLab tab)

Currently I’m using INotebookTracker & IEditorTracker core tokens to get list of open notebooks and files respectively. I observed these token do not return certain file types (e.g. .csv file). Is there any API / token to get list of ALL currently open files in JupyterLab?

I’ve looked through the guide and documentation but couldn’t find anything. Sorry If I’ve missed something.

1 Like

Hi @amirathi, the lifecycle for all documents is handled by the DocumentManager. You should be able to request the IDocumentManager token for your extension, and then check if a given widget belongs to it. In this way you can filter out widgets that are not documents (e.g., terminals).

So, it would look something like

  1. Iterate over all of the widgets in the main area using this function on the lab shell.
  2. Check if each widget belongs to the document manager using the contextForWidget function.

Thanks @ian-r-rose, sounds good. I will give it a shot.

Just to clarify if contextForWidget returns any value (except undefined) then the widget is associated with a DocumentManager. Is that correct?

@amirathi Yes, that is correct. undefined indicates that it is not a document.

1 Like