Skip to content

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.

fix: show sql snippet cells as sql instead of python (#10050)

qorex#devcd203bbdac9c
diff --git a/frontend/src/components/editor/chrome/panels/__tests__/snippet-display.test.ts b/frontend/src/components/editor/chrome/panels/__tests__/snippet-display.test.ts
new file mode 100644
index 0000000000..eb8f6b2fb2
--- /dev/null
+++ b/frontend/src/components/editor/chrome/panels/__tests__/snippet-display.test.ts
@@ -0,0 +1,22 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { describe, expect, it } from "vitest";
+import { getSnippetDisplay } from "../snippet-display";
+
+describe("getSnippetDisplay", () => {
+ it("shows sql cells as the sql query", () => {
+ const { language, value } = getSnippetDisplay(
+ 'df = mo.sql("""SELECT * FROM users LIMIT 5""")',
+ );
+ expect(language).toBe("sql");
+ expect(value).toBe("SELECT * FROM users LIMIT 5");
+ });
+
+ it("keeps plain python cells as python", () => {
+ const code = "x = 1 + 2\nprint(x)";
+ expect(getSnippetDisplay(code)).toEqual({
+ language: "python",
+ value: code,
+ });
+ });
+});
diff --git a/frontend/src/components/editor/chrome/panels/snippet-display.ts b/frontend/src/components/editor/chrome/panels/snippet-display.ts
new file mode 100644
index 0000000000..8702d4e238
--- /dev/null
+++ b/frontend/src/components/editor/chrome/panels/snippet-display.ts
@@ -0,0 +1,27 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { SQLParser } from "@marimo-team/smart-cells";
+
+export type SnippetLanguage = "python" | "sql";
+
+export interface SnippetDisplay {
+ language: SnippetLanguage;
+ value: string;
+}
+
+const sqlParser = new SQLParser();
+
+/**
+ * Decide how a snippet's code should be shown in the panel.
+ *
+ * SQL cells are stored as python `mo.sql(...)`. Unwrap the inner query and
+ * highlight it as SQL, matching how the cell renders once the snippet is
+ * inserted. Everything else stays python.
+ */
+export function getSnippetDisplay(code: string): SnippetDisplay {
+ if (sqlParser.isSupported(code)) {
+ const { code: query } = sqlParser.transformIn(code);
+ return { language: "sql", value: query };
+ }
+ return { language: "python", value: code };
+}
diff --git a/frontend/src/components/editor/chrome/panels/snippets-panel.tsx b/frontend/src/components/editor/chrome/panels/snippets-panel.tsx
index 088c6a25b1..adf05ca58d 100644
--- a/frontend/src/components/editor/chrome/panels/snippets-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/snippets-panel.tsx
@@ -31,6 +31,7 @@ import { cn } from "@/utils/cn";
import { HideInKioskMode } from "../../kiosk-mode";
import { ContributeSnippetButton } from "../components/contribute-snippet-button";
import { usePanelOrientation, usePanelSection } from "./panel-context";
+import { getSnippetDisplay } from "./snippet-display";
const extensions = [EditorView.lineWrapping];
@@ -187,6 +188,8 @@ const SnippetViewer: React.FC<{ snippet: Snippet; onClose: () => void }> = ({
return null;
}
+ const { language, value } = getSnippetDisplay(code);
+
return (
<div
className="relative hover-actions-parent pr-2"
@@ -210,10 +213,10 @@ const SnippetViewer: React.FC<{ snippet: Snippet; onClose: () => void }> = ({
<LazyAnyLanguageCodeMirror
key={`${snippet.title}-${id}`}
theme={theme === "dark" ? "dark" : "light"}
- language="python"
+ language={language}
className="cm border rounded overflow-hidden"
extensions={extensions}
- value={code}
+ value={value}
readOnly={true}
/>
</Suspense>