A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
improvement: hide inline completion when not focused, add Esc hotkey (#4248)
Myles Scolnickc85747ccb679
diff --git a/frontend/package.json b/frontend/package.jsonindex 2b2b48044e..c89fe45d9e 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -40,7 +40,7 @@"@lezer/highlight": "^1.2.1","@lezer/lr": "^1.4.2","@lezer/python": "^1.1.16",- "@marimo-team/codemirror-ai": "^0.1.9",+ "@marimo-team/codemirror-ai": "^0.1.11","@marimo-team/codemirror-languageserver": "^1.15.0","@marimo-team/marimo-api": "file:../openapi","@marimo-team/react-slotz": "^0.1.8",@@ -96,7 +96,6 @@"class-variance-authority": "^0.7.1","clsx": "^2.1.1","cmdk": "^1.0.4",- "codemirror-extension-inline-suggestion": "^0.0.3","compassql": "^0.21.2","cssnano": "^7.0.6","date-fns": "^4.1.0",@@ -242,8 +241,7 @@"packageManager": "[email protected]","pnpm": {"patchedDependencies": {- "react-plotly.js": "patches/react-plotly.js.patch",- "codemirror-extension-inline-suggestion": "patches/codemirror-extension-inline-suggestion.patch"+ "react-plotly.js": "patches/react-plotly.js.patch"}}}diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yamlindex 0b02d55030..f53e1ab38b 100644--- a/frontend/pnpm-lock.yaml+++ b/frontend/pnpm-lock.yaml@@ -7,9 +7,6 @@ settings:pnpmfileChecksum: eqzj7c6t3bs5v7xcjer2wfwkp4patchedDependencies:- codemirror-extension-inline-suggestion:- hash: khbxbgrsjmwb5ecklr5ujxzp5i- path: patches/codemirror-extension-inline-suggestion.patchreact-plotly.js:hash: bpeex744nmt6722etqry6essaqpath: patches/react-plotly.js.patch@@ -100,8 +97,8 @@ importers:specifier: ^1.1.16version: 1.1.16'@marimo-team/codemirror-ai':- specifier: ^0.1.9- version: 0.1.9(@codemirror/[email protected])(@codemirror/[email protected])+ specifier: ^0.1.11+ version: 0.1.11(@codemirror/[email protected])(@codemirror/[email protected])'@marimo-team/codemirror-languageserver':specifier: ^1.15.0version: 1.15.0(@codemirror/[email protected])(@codemirror/[email protected])@@ -267,9 +264,6 @@ importers:cmdk:specifier: ^1.0.4version: 1.0.4(@types/[email protected](@types/[email protected]))(@types/[email protected])([email protected]([email protected]))([email protected])- codemirror-extension-inline-suggestion:- specifier: ^0.0.3- version: 0.0.3(patch_hash=khbxbgrsjmwb5ecklr5ujxzp5i)(@codemirror/[email protected])(@codemirror/[email protected])compassql:specifier: ^0.21.2version: 0.21.2([email protected])@@ -1572,8 +1566,8 @@ packages:'@marijn/[email protected]':resolution: {integrity: sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==}- '@marimo-team/[email protected]':- resolution: {integrity: sha512-Ti6KzKfwvceHuSSUoWyoALawALq/ftNUaxvLIfzsU0vwtNa23Et95btAisGLBCPQ0YxBPEPSI3anYY/o7T4cMQ==}+ '@marimo-team/[email protected]':+ resolution: {integrity: sha512-EGFdLmJP5i4fV0Mec0V48Wlav7bvzbC+GWPmOmYmX49v1LLo1ie1x4CcbcM4IC3baH8MP3AdGvzD/7fSXBoupg==}peerDependencies:'@codemirror/state': ^6'@codemirror/view': ^6@@ -4476,12 +4470,6 @@ packages:resolution: {integrity: sha512-RpAVKQA5T63xEj6/giIbUEtZwJ4UFIc3ZtvEkiaUERylqe8xb5IvqcgOurZLahv93CLKfxcw5YI+DZcUBRyLXA==}engines: {node: '>=0.10.0'}- resolution: {integrity: sha512-IgNoyK7d4HJicqZMYMC1RgHlpR1pnSEgDHATKIuQrqW68o5QmD8IFZ26M/8UXNI+Usb00Vu4q0EtzMdm92pOAg==}- peerDependencies:- '@codemirror/state': ^6.2.0- '@codemirror/view': ^6.7.2-resolution: {integrity: sha512-Taw/2gPCyNArQJCxIP/HSUif+3zrvD+6Ugt7KJZ2dUKou/8r3ZhcfG8krNTZfV2iu8AuGnymKuo7bLPFyqsh/A==}@@ -10366,7 +10354,7 @@ snapshots:'@marijn/[email protected]': {}dependencies:'@codemirror/state': 6.5.2'@codemirror/view': 6.36.4@@ -14046,11 +14034,6 @@ snapshots:- [email protected](patch_hash=khbxbgrsjmwb5ecklr5ujxzp5i)(@codemirror/[email protected])(@codemirror/[email protected]):- dependencies:- '@codemirror/state': 6.5.2- '@codemirror/view': 6.36.4-dependencies:'@codemirror/language': 6.11.0diff --git a/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snap b/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snapindex a39d346ebd..5686d4da12 100644--- a/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snap+++ b/frontend/src/core/codemirror/__tests__/__snapshots__/setup.test.ts.snap@@ -71,13 +71,13 @@ exports[`snapshot all duplicate keymaps > default keymaps 2`] = `},{"key": "Escape",- "preventDefault": true,- "run": "run",+ "preventDefault": false,+ "run": "closeFindReplacePanel",},{"key": "Escape",- "preventDefault": false,- "run": "closeFindReplacePanel",+ "preventDefault": true,+ "run": "run",},],"PageDown": [diff --git a/frontend/src/core/codemirror/copilot/extension.ts b/frontend/src/core/codemirror/copilot/extension.tsindex 5b4693036f..cdc5f20d03 100644--- a/frontend/src/core/codemirror/copilot/extension.ts+++ b/frontend/src/core/codemirror/copilot/extension.ts@@ -11,7 +11,7 @@ import {copilotServer,getCopilotClient,} from "./client";-import { inlineSuggestion } from "codemirror-extension-inline-suggestion";+import { inlineCompletion } from "@marimo-team/codemirror-ai";import {copilotPlugin as codeiumCopilotPlugin,Language,@@ -28,9 +28,20 @@ import { Logger } from "@/utils/Logger";import { languageAdapterState } from "../language/extension";import { API } from "@/core/network/api";import type { AiInlineCompletionRequest } from "@/core/kernel/messages";+import type { EditorView } from "@codemirror/view";const copilotCompartment = new Compartment();+const commonInlineCompletionConfig = {+ delay: 500, // default is 500ms+ includeKeymap: true,+ events: {+ // Only show suggestions when the editor is focused+ shouldShowSuggestion: (view: EditorView) => view.hasFocus,+ beforeSuggestionFetch: (view: EditorView) => view.hasFocus,+ },+};+export const copilotBundle = (config: CompletionConfig): Extension => {if (process.env.NODE_ENV === "test") {return [];@@ -60,8 +71,8 @@ export const copilotBundle = (config: CompletionConfig): Extension => {if (config.copilot === "github") {extensions.push(- inlineSuggestion({- delay: 500, // default is 500ms+ inlineCompletion({+ ...commonInlineCompletionConfig,fetchFn: async (state) => {if (!isCopilotEnabled()) {return "";@@ -96,8 +107,8 @@ export const copilotBundle = (config: CompletionConfig): Extension => {if (config.copilot === "custom") {extensions.push(- inlineSuggestion({- delay: 500,+ inlineCompletion({+ ...commonInlineCompletionConfig,fetchFn: async (state) => {if (state.doc.length === 0) {return "";diff --git a/frontend/src/core/codemirror/keymaps/keymaps.ts b/frontend/src/core/codemirror/keymaps/keymaps.tsindex b3512391a7..b90b25dbd5 100644--- a/frontend/src/core/codemirror/keymaps/keymaps.ts+++ b/frontend/src/core/codemirror/keymaps/keymaps.ts@@ -16,16 +16,19 @@ export function keymapBundle(config: KeymapConfig): Extension[] {case "default":return [keymap.of(defaultKeymap),- keymap.of([- {- key: "Escape",- preventDefault: true,- run: (cm) => {- cm.contentDOM.blur();- return true;+ // Should be the last thing to close when Escape is pressed+ Prec.low(+ keymap.of([+ {+ key: "Escape",+ preventDefault: true,+ run: (cm) => {+ cm.contentDOM.blur();+ return true;+ },},- },- ]),+ ]),+ ),];case "vim":return [