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: support better file completion (#4182)
Myles Scolnick54e1ecc564ac
diff --git a/frontend/package.json b/frontend/package.jsonindex 1e9883e8e6..114fff3db0 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -42,7 +42,7 @@"@lezer/python": "^1.1.16","@marimo-team/codemirror-ai": "^0.1.9","@marimo-team/marimo-api": "file:../openapi",- "@marimo-team/codemirror-languageserver": "^1.14.0",+ "@marimo-team/codemirror-languageserver": "^1.14.1","@marimo-team/react-slotz": "^0.1.8","@open-rpc/client-js": "^1.8.1","@paralleldrive/cuid2": "^2.2.2",diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yamlindex 6d64397802..091426d4ca 100644--- a/frontend/pnpm-lock.yaml+++ b/frontend/pnpm-lock.yaml@@ -103,8 +103,8 @@ importers:specifier: ^0.1.9version: 0.1.9(@codemirror/[email protected])(@codemirror/[email protected])'@marimo-team/codemirror-languageserver':- specifier: ^1.14.0- version: 1.14.0(@codemirror/[email protected])(@codemirror/[email protected])+ specifier: ^1.14.1+ version: 1.14.1(@codemirror/[email protected])(@codemirror/[email protected])'@marimo-team/marimo-api':specifier: file:../openapiversion: file:../openapi@@ -1546,8 +1546,8 @@ packages:'@codemirror/state': ^6'@codemirror/view': ^6- '@marimo-team/[email protected]':- resolution: {integrity: sha512-5x3FaopUPaq7tDMEf3VPBkh3CsxA1KfV0554JmvOHwzv0aJ3FIbvWDAnnyi3TZZicmhoJUdyigMHOxtz0GIZKg==}+ '@marimo-team/[email protected]':+ resolution: {integrity: sha512-Dvt06J0FdPmulsy7HPg3AORc6edBtfxqST5L3Y5TOPrgXrIpE+3kOrs9+mWKTRG5jGJ7wgxGh9+TRFgsOoTxlQ==}peerDependencies:'@codemirror/state': ^6'@codemirror/view': ^6@@ -10225,7 +10225,7 @@ snapshots:'@codemirror/state': 6.5.2'@codemirror/view': 6.36.4dependencies:'@codemirror/autocomplete': 6.18.6'@codemirror/lint': 6.8.4diff --git a/frontend/src/core/codemirror/language/python.ts b/frontend/src/core/codemirror/language/python.tsindex 19b8463957..6eb9ae482f 100644--- a/frontend/src/core/codemirror/language/python.ts+++ b/frontend/src/core/codemirror/language/python.ts@@ -170,6 +170,9 @@ export class PythonLanguageAdapter implements LanguageAdapter {allowHTMLContent: true,hoverConfig: hoverOptions,completionConfig: autocompleteOptions,+ // Match completions before the cursor is at the end of a word,+ // after a dot, after a slash, after a comma.+ completionMatchBefore: /(\w+|\w+\.|\/|,)$/,onGoToDefinition: (result) => {Logger.debug("onGoToDefinition", result);if (client.documentUri === result.uri) {diff --git a/frontend/src/core/codemirror/lsp/notebook-lsp.ts b/frontend/src/core/codemirror/lsp/notebook-lsp.tsindex 2be32160b2..81cf0134e2 100644--- a/frontend/src/core/codemirror/lsp/notebook-lsp.ts+++ b/frontend/src/core/codemirror/lsp/notebook-lsp.ts@@ -86,6 +86,51 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {});}+ async textDocumentSignatureHelp(+ params: LSP.SignatureHelpParams,+ ): Promise<LSP.SignatureHelp | null> {+ // TODO: not implemented yet+ // It currently doesn't provide too much value over the autocomplete+ // and blocks the completion list when it is open.+ const disabledSignatureHelp = true;+ if (disabledSignatureHelp) {+ return null;+ }++ const cellDocumentUri = params.textDocument.uri;+ if (!CellDocumentUri.is(cellDocumentUri)) {+ Logger.warn("Invalid cell document URI", cellDocumentUri);+ return null;+ }++ const cellId = CellDocumentUri.parse(cellDocumentUri);+ const versionInfo = [...this.versionToCellNumberAndVersion.values()].find(+ (info) => info.cellDocumentUri === cellDocumentUri,+ );++ if (!versionInfo) {+ Logger.warn("No lens found for cell", cellId);+ return null;+ }++ const { lens } = versionInfo;+ const transformedPosition = lens.transformPosition(params.position, cellId);++ const response = await this.client.textDocumentSignatureHelp({+ ...params,+ textDocument: {+ uri: this.documentUri,+ },+ position: transformedPosition,+ });++ if (!response) {+ return null;+ }++ return response;+ }+textDocumentCodeAction(params: LSP.CodeActionParams,): Promise<Array<LSP.Command | LSP.CodeAction> | null> {diff --git a/frontend/src/css/app/codemirror-completions.css b/frontend/src/css/app/codemirror-completions.cssindex 8334efd2da..cfc1a0a0f3 100644--- a/frontend/src/css/app/codemirror-completions.css+++ b/frontend/src/css/app/codemirror-completions.css@@ -18,7 +18,9 @@/* Autocomplete list items */.cm-tooltip-autocomplete > ul > li {padding: 0;+ padding-right: 6px;height: 18px;+ min-width: 60px;@apply flex items-center gap-2 cursor-pointer;}@@ -47,11 +49,20 @@font-weight: bold;opacity: 0.9;padding: 0 1px;+ /* Default colors */+ color: var(--gray-11);+ background-color: var(--gray-3);+@apply flex items-center justify-center font-medium;++ /* Default styling for completion icons */+ &::after {+ content: "•"; /* Default bullet point for unknown types */+ }}.cm-completionIcon-variable {- color: var(--blue-10);+ color: var(--blue-11);background-color: var(--blue-3);&::after {@@ -123,7 +134,7 @@}.cm-completionIcon-reference {- color: var(--gray-10);+ color: var(--gray-11);background-color: var(--gray-3);&::after {@@ -131,6 +142,15 @@}}+ .cm-completionIcon-file {+ color: var(--crimson-11);+ background-color: var(--crimson-3);++ &::after {+ content: "𝌆"; /* File symbol for files */+ }+ }+/* Completion info tooltip */.cm-completionInfo {@apply max-w-md border-l border-border;@@ -191,3 +211,19 @@border-top-right-radius: 0;}}++.cm-signature-help {+ @apply bg-popover shadow-md border border-border rounded-md text-sm;++ .cm-signature {+ @apply text-xs;+ }++ .cm-signature-parameter {+ @apply text-xs;+ }++ .cm-signature-docs {+ @apply text-xs;+ }+}diff --git a/frontend/src/css/globals.css b/frontend/src/css/globals.cssindex 6536380f57..87e6b5145d 100644--- a/frontend/src/css/globals.css+++ b/frontend/src/css/globals.css@@ -26,6 +26,8 @@@import url("@radix-ui/colors/purple-dark.css");@import url("@radix-ui/colors/green.css");@import url("@radix-ui/colors/green-dark.css");+@import url("@radix-ui/colors/crimson.css");+@import url("@radix-ui/colors/crimson-dark.css");@tailwind base;@tailwind components;