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
parse docstrings as markdown in autocomplete (#199)
Akshay Agrawala95692759468
diff --git a/frontend/src/css/Cell.css b/frontend/src/css/Cell.cssindex 1ae1e7abbe..765f719e9d 100644--- a/frontend/src/css/Cell.css+++ b/frontend/src/css/Cell.css@@ -236,83 +236,6 @@border-radius: 2px;}-.cm .cm-gutters {- @apply bg-background;-- /* Style line numbers. */- font-size: 0.75rem;- color: var(--gray-10);-}--.dark .cm .cm-gutters {- background-color: transparent;-}--.cm-scroller {- overflow: auto;-}--/* Code completion pop-up. */-.cm .cm-tooltip {- font-family: var(--monospace-font);- font-size: 0.875rem;- border: none;- box-shadow: var(--light-shadow);- border-radius: 4px 0 4px 4px;-- @apply bg-popover;-}--.cm .cm-tooltip-autocomplete ul li[aria-selected] {- background: #1177ccb0;-}--.dark .cm .cm-tooltip-autocomplete ul li[aria-selected] {- background: #1177cc80;-}--/* Code completion pop-up for docstrings, type-hints and completion info. */-.cm .cm-tooltip.cm-completionInfo {- max-height: 800px;- overflow: auto;-- /* Respect newlines. */- white-space: pre-wrap;-- /* Codemirror generates an inline style for these properties,- * so we have to override them with !important. */- top: 0 !important;-- /* Completion Info shows up to the right of another menu item. */- border-radius: 0 4px 4px;- padding: 0.625rem 0.875rem;-}--.cm .cm-tooltip.cm-completionInfo pre {- margin: 0;- white-space: pre-wrap;-}--.cm .cm-completionIcon-function::after {- content: "λ";-}--.cm .cm-completionIcon-class::after {- content: "τ";-}--.cm .cm-completionIcon-module::after {- content: "μ";-}--.cm .cm-completionIcon-statement::after {- content: "χ";-}--.cm .cm-completionIcon-keyword::after {- content: "κ";-}-/* ------------------------------ Output Areas ------------------------------ */.output-area,diff --git a/frontend/src/css/codemirror.css b/frontend/src/css/codemirror.cssindex 9c04311213..6003447f55 100644--- a/frontend/src/css/codemirror.css+++ b/frontend/src/css/codemirror.css@@ -8,3 +8,118 @@.dark .cm-selectionBackground {background-color: #4d4d4d !important;}++.cm .cm-gutters {+ @apply bg-background;++ /* Style line numbers. */+ font-size: 0.75rem;+ color: var(--gray-10);+}++.dark .cm .cm-gutters {+ background-color: transparent;+}++.cm-scroller {+ overflow: auto;+}++/* Code completion pop-up. */+.cm .cm-tooltip {+ font-family: var(--monospace-font);+ font-size: 0.875rem;+ border: none;+ box-shadow: var(--light-shadow);+ border-radius: 4px 0 4px 4px;++ @apply bg-popover;+}++.cm .cm-tooltip-autocomplete ul li[aria-selected] {+ background: #1177ccb0;+}++.dark .cm .cm-tooltip-autocomplete ul li[aria-selected] {+ background: #1177cc80;+}++/* Code completion pop-up for docstrings, type-hints and completion info. */+.cm .cm-tooltip.cm-completionInfo {+ max-height: 800px;+ overflow: auto;++ /* Respect newlines. */+ white-space: pre-wrap;++ /* Codemirror generates an inline style for these properties,+ * so we have to override them with !important. */+ top: 0 !important;++ /* Completion Info shows up to the right of another menu item. */+ border-radius: 0 4px 4px;+ padding: 0.625rem 0.875rem;+}++.cm .cm-tooltip.cm-completionInfo ul {+ white-space: normal;+ display: block;+ list-style-type: disc;+ margin-block-start: 0;+ margin-block-end: 0;+ margin-inline-start: 0;+ margin-inline-end: 0;+ padding-inline-start: 40px;+}++.cm .cm-tooltip.cm-completionInfo ol {+ /* provide by the browser, but removed from 'reset' */+ white-space: normal;+ display: block;+ list-style-type: decimal;+ margin-block-start: 0;+ margin-block-end: 0;+ margin-inline-start: 0;+ margin-inline-end: 0;+ padding-inline-start: 40px;+}++.cm .cm-tooltip.cm-completionInfo li {+ /* provided by the browser, but removed from 'reset' */+ white-space: normal;+ display: list-item;+ text-align: -webkit-match-parent;+}++.cm .cm-tooltip.cm-completionInfo blockquote {+ display: contents;+ margin-block-start: 0;+ margin-block-end: 0;+ margin-inline-start: 0;+ margin-inline-end: 0;+}++.cm .cm-tooltip.cm-completionInfo pre {+ margin: 0;+ white-space: pre-wrap;+}++.cm .cm-completionIcon-function::after {+ content: "λ";+}++.cm .cm-completionIcon-class::after {+ content: "τ";+}++.cm .cm-completionIcon-module::after {+ content: "μ";+}++.cm .cm-completionIcon-statement::after {+ content: "χ";+}++.cm .cm-completionIcon-keyword::after {+ content: "κ";+}diff --git a/marimo/_runtime/complete.py b/marimo/_runtime/complete.pyindex 2c6437be6c..76dc7f09f9 100644--- a/marimo/_runtime/complete.py+++ b/marimo/_runtime/complete.py@@ -1,7 +1,6 @@# Copyright 2023 Marimo. All rights reserved.from __future__ import annotations-import htmlimport queuefrom typing import cast@@ -77,7 +76,9 @@ def _get_docstring(completion: jedi.api.classes.BaseName) -> str:).textif body:- body = "<pre>" + html.escape(body) + "</pre>"+ # aggressively treat docstrings as markdown. this does mostly okay for+ # most docstrings, and makes marimo docstrings much easier to read.+ body = _md(body, apply_markdown_class=False).textif signature_text and body:docstring = signature_text + "\n\n" + body@@ -98,7 +99,10 @@ def _get_docstring(completion: jedi.api.classes.BaseName) -> str:init_docstring = subname.docstring(raw=True)if init_docstring:init_docstring = (- "__init__ docstring:\n\n" + init_docstring+ "__init__ docstring:\n\n"+ + _md(+ init_docstring, apply_markdown_class=False+ ).text)if docstring and init_docstring:docstring += "\n\n" + init_docstring