From bc8e5f1cd178e467544d6b39ba781c8ff9b07b1e Mon Sep 17 00:00:00 2001 From: Aaron Diamond-Reivich Date: Wed, 29 Jan 2025 14:57:30 -0500 Subject: [PATCH 1/2] mito-ai: auto enable mito-ai without waiting for notification enable button --- .../src/Extensions/InlineCompleter/index.ts | 82 ++++++++----------- 1 file changed, 33 insertions(+), 49 deletions(-) diff --git a/mito-ai/src/Extensions/InlineCompleter/index.ts b/mito-ai/src/Extensions/InlineCompleter/index.ts index 577a1a10b..7fd2749e5 100644 --- a/mito-ai/src/Extensions/InlineCompleter/index.ts +++ b/mito-ai/src/Extensions/InlineCompleter/index.ts @@ -29,13 +29,13 @@ export const completionPlugin: JupyterFrontEndPlugin = { requires: [ ICompletionProviderManager, ISettingRegistry, - IVariableManager + IVariableManager, ], activate: ( app: JupyterFrontEnd, completionManager: ICompletionProviderManager, settingRegistry: ISettingRegistry, - variableManager: IVariableManager + variableManager: IVariableManager, ) => { if (typeof completionManager.registerInlineProvider === 'undefined') { // Gracefully short-circuit on JupyterLab 4.0 and Notebook 7.0 @@ -92,57 +92,41 @@ export const completionPlugin: JupyterFrontEndPlugin = { }; if (!providers['mito-ai']['enabled']) { + + /* The first time the user installs Mito AI, we take a few actions*/ + + // 1. Dispaly welcome notification Notification.info( - 'Thanks for installing the Mito AI extension. Do you want to enable the Mito AI inline completer?', + 'Mito AI is now enabled!', { - autoClose: false, - actions: [ - { - label: 'Enable', - displayType: 'accent', - callback: async () => { - if ( - providers['@jupyterlab/inline-completer:history']?.[ - 'enabled' - ] !== false - ) { - providers['@jupyterlab/inline-completer:history'][ - 'enabled' - ] = false; - } - providers['mito-ai']['enabled'] = true; - await settingRegistry.set( - JUPYTERLAB_INLINE_COMPLETER_ID, - 'providers', - providers - ); - - // For some reason, it seems that unless the Tab shortcut is registered first, - // Jupyter does not accept it. So we try removing the existing shortcut. - shortcuts = shortcuts.filter((shortcut: {command: string}) => shortcut.command !== 'inline-completer:accept'); - shortcuts.push({ - command: 'inline-completer:accept', - keys: ['Tab'], - selector: '.jp-mod-inline-completer-active' - }); - await settingRegistry.set( - JUPYTERLAB_SHORTCUTS_ID, - 'shortcuts', - shortcuts - ); - updateConfig(); - } - }, - { - label: 'Not now', - callback: () => { - updateConfig(); - } - } - ] + autoClose: 10000 } ); - } else { + + // 2. Disable the default inline completer + if (providers['@jupyterlab/inline-completer:history']?.['enabled'] !== false) { + providers['@jupyterlab/inline-completer:history']['enabled'] = false; + } + + // 3. Enable the Mito AI inline completer + providers['mito-ai']['enabled'] = true; + await settingRegistry.set(JUPYTERLAB_INLINE_COMPLETER_ID, 'providers', providers); + + // 4. Set Tab as the accept button for autocomplete. + // For some reason, it seems that unless the Tab shortcut is registered first, + // Jupyter does not accept it. So we try removing the existing shortcut. + shortcuts = shortcuts.filter((shortcut: {command: string}) => shortcut.command !== 'inline-completer:accept'); + shortcuts.push({ + command: 'inline-completer:accept', + keys: ['Tab'], + selector: '.jp-mod-inline-completer-active' + }); + await settingRegistry.set( + JUPYTERLAB_SHORTCUTS_ID, + 'shortcuts', + shortcuts + ); + updateConfig(); } }; From ba5ababd2e79158bbd55fd89e1cbf6876d8ee197 Mon Sep 17 00:00:00 2001 From: Aaron Diamond-Reivich Date: Wed, 29 Jan 2025 17:01:44 -0500 Subject: [PATCH 2/2] tests: remove enable pretest hook --- tests/mitoai_ui_tests/basicInlineComplete.spec.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/mitoai_ui_tests/basicInlineComplete.spec.ts b/tests/mitoai_ui_tests/basicInlineComplete.spec.ts index cd97dfab5..5768563c8 100644 --- a/tests/mitoai_ui_tests/basicInlineComplete.spec.ts +++ b/tests/mitoai_ui_tests/basicInlineComplete.spec.ts @@ -16,12 +16,6 @@ import { const GHOST_SELECTOR = ".jp-GhostText"; const THRESHOLD_IN_MS = 5000; -// Before each test, enable inline completion -test.beforeEach(async ({ page }) => { - await page.locator('button:has-text("Enable")').click(); -}); - - test.describe("inline completion integration test", () => { test('Inline completion', async ({ page }) => {