From 0823b1cf5ff0b7f759edb5342d6371c5c4efe02b Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Fri, 16 Jun 2023 12:18:15 +0200 Subject: [PATCH] Add more comments --- packages/application-extension/src/index.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index 305ffe3d99..c867d81197 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -71,6 +71,12 @@ const TREE_PATTERN = new RegExp('/(notebooks|edit)/(.*)'); */ const STRIP_IPYNB = /\.ipynb$/; +/** + * The JupyterLab document manager plugin id. + */ +const JUPYTERLAB_DOCMANAGER_PLUGIN_ID = + '@jupyterlab/docmanager-extension:plugin'; + /** * The command IDs used by the application plugin. */ @@ -189,7 +195,7 @@ const opener: JupyterFrontEndPlugin = { const command = 'router:tree'; commands.addCommand(command, { - execute: async (args: any) => { + execute: (args: any) => { const parsed = args as IRouter.ILocation; const matches = parsed.path.match(TREE_PATTERN) ?? []; const [, , path] = matches; @@ -204,17 +210,19 @@ const opener: JupyterFrontEndPlugin = { // Explicitely get the default viewers from the settings because // JupyterLab might not have had the time to load the settings yet (race condition) + // Relevant code: https://github.com/jupyterlab/jupyterlab/blob/d56ff811f39b3c10c6d8b6eb27a94624b753eb53/packages/docmanager-extension/src/index.tsx#L265-L293 if (settingRegistry) { const settings = await settingRegistry.load( - '@jupyterlab/docmanager-extension:plugin' + JUPYTERLAB_DOCMANAGER_PLUGIN_ID ); - // Handle default widget factory overrides. const defaultViewers = settings.get('defaultViewers').composite as { [ft: string]: string; }; - // get the file types for the path const types = docRegistry.getFileTypesForPath(path); + // for each file type, check if there is a default viewer and if it + // is available in the docRegistry. If it is the case, use it as the + // default factory types.forEach((ft) => { if ( defaultViewers[ft.name] !== undefined &&