@marimo-team/islands 0.26.1-dev20 → 0.26.1-dev25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/dist/{ConnectedDataExplorerComponent-CR9WyiEc.js → ConnectedDataExplorerComponent-jtTaDisw.js} +16 -16
  2. package/dist/{ErrorBoundary-Cx-CwafE.js → ErrorBoundary-Bs2ehxEI.js} +6 -6
  3. package/dist/{abnfDiagram-VCTEODGH-DGAbsdXT.js → abnfDiagram-VCTEODGH-cUj3Gnnh.js} +2 -2
  4. package/dist/{any-language-editor-DzGF1ll-.js → any-language-editor-BHgkY7jY.js} +2 -2
  5. package/dist/{architectureDiagram-5GKGNRK7-D4DnIo7R.js → architectureDiagram-5GKGNRK7-CIAZgn9d.js} +1 -1
  6. package/dist/{assertNever-CqwxSD_2.js → assertNever-BHnIohkX.js} +13 -13
  7. package/dist/{chat-ui-qZdDDrzU.js → chat-ui-DOvIzlMA.js} +46 -46
  8. package/dist/{check-D9vf6LYF.js → check-LtjuWmNn.js} +1 -1
  9. package/dist/{chunk-IMKFNOWR-Bc_i6jWx.js → chunk-IMKFNOWR-CB9N3qYR.js} +1 -1
  10. package/dist/{chunk-SHT3W25Y-CGML5pnF.js → chunk-SHT3W25Y-D9njV7TI.js} +1 -1
  11. package/dist/{chunk-SVP7TREG-ZpeFKfFT.js → chunk-SVP7TREG-CUCE0BFm.js} +1 -1
  12. package/dist/{chunk-TICWLB2K-C6cLmcg8.js → chunk-TICWLB2K-iQB6ttkI.js} +1 -1
  13. package/dist/{classDiagram-ZZMXUADV--q40NTXr.js → classDiagram-ZZMXUADV-BI1VBNIo.js} +2 -2
  14. package/dist/{classDiagram-v2-VYDZK3BY-Dt_Pp94L.js → classDiagram-v2-VYDZK3BY-BYL3asWh.js} +2 -2
  15. package/dist/{code-visibility-CVfXV6fG.js → code-visibility-BnMkbydx.js} +19 -19
  16. package/dist/{common-BXRJCkJO.js → common-CQur5dRA.js} +156 -156
  17. package/dist/{config-B8JCQMby.js → config-DL9e-OWE.js} +3 -3
  18. package/dist/{copy-icon-BLig0ZKb.js → copy-icon-rYV2znAe.js} +2 -2
  19. package/dist/{createReducer-BIUQ3TbG.js → createReducer-BdiSrxHu.js} +5 -5
  20. package/dist/{cynefinDiagram-5FMLGOSQ-2FtF_-cc.js → cynefinDiagram-5FMLGOSQ-DpGtYvnZ.js} +1 -1
  21. package/dist/{dagre-GXQ25YYZ-Cymu2SPS.js → dagre-GXQ25YYZ-B5GDC2kN.js} +1 -1
  22. package/dist/{data-grid-overlay-editor-Mbtx3F9C.js → data-grid-overlay-editor-BXEY35Xl.js} +1 -1
  23. package/dist/{diagram-S7CK7UJ4-OwDa8kAa.js → diagram-S7CK7UJ4-B2T25t1t.js} +1 -1
  24. package/dist/{diagram-UQ7AKVKN-CzRDwZwd.js → diagram-UQ7AKVKN-Dy3B5L_z.js} +1 -1
  25. package/dist/{diagram-VX7I27RA-XRIcgMDs.js → diagram-VX7I27RA-tOptWvNh.js} +1 -1
  26. package/dist/{diagram-Z3DM3KII-DdRDYAs6.js → diagram-Z3DM3KII-DsgZAokO.js} +1 -1
  27. package/dist/{dialog-DGh2HNAO.js → dialog-vs6x3On9.js} +19 -19
  28. package/dist/{dropdown-menu-ChH3oiqI.js → dropdown-menu-DYN2RV5d.js} +193 -193
  29. package/dist/{ebnfDiagram-PWID7BFC-CZMNMGNP.js → ebnfDiagram-PWID7BFC-CGWECzS1.js} +2 -2
  30. package/dist/{erDiagram-RLTQ6QDP-ByxHAN4b.js → erDiagram-RLTQ6QDP-CZLi87y3.js} +1 -1
  31. package/dist/{error-banner-BvRaQnGH.js → error-banner-D-AC7pQx.js} +70 -70
  32. package/dist/{error-entries-DhI0hGvj.js → error-entries-CncQR572.js} +443 -436
  33. package/dist/{feedback-button-zx4NcNDn.js → feedback-button-BAOp7zqu.js} +120 -120
  34. package/dist/{flowDiagram-HODETNUW-BQpzWx5O.js → flowDiagram-HODETNUW-CS86WYbX.js} +2 -2
  35. package/dist/{formats-BxP8k8Un.js → formats-BUFLQJXY.js} +1 -1
  36. package/dist/{glide-data-editor-CvezoJKg.js → glide-data-editor-Ce94qTW7.js} +11 -11
  37. package/dist/{glide-utils-bKdvDwwo.js → glide-utils-CZ-O-CB_.js} +2 -2
  38. package/dist/{globals-CQuPaxzy.js → globals-Uqg4j5z5.js} +3 -3
  39. package/dist/{html-to-image-B803aaWE.js → html-to-image-BU7H-AM1.js} +4323 -4318
  40. package/dist/{infoDiagram-27XIBGKW-C9EWHkak.js → infoDiagram-27XIBGKW-C9JBFfpC.js} +1 -1
  41. package/dist/{ishikawaDiagram-5VMMS53U-D67SGFvp.js → ishikawaDiagram-5VMMS53U-Eh3iuw2D.js} +1 -1
  42. package/dist/{kanban-definition-UXKFOSKX-CTMTiazR.js → kanban-definition-UXKFOSKX-DYtuVwYD.js} +1 -1
  43. package/dist/main.js +401 -400
  44. package/dist/{mermaid-DE_tvTGF.js → mermaid--k1o49nH.js} +34 -34
  45. package/dist/{mindmap-definition-YA3MSWOX-LzNgDy8O.js → mindmap-definition-YA3MSWOX-Dn1Cnqys.js} +1 -1
  46. package/dist/{number-overlay-editor-DxM7vsCk.js → number-overlay-editor-Br_Vp3Ws.js} +1 -1
  47. package/dist/{pegDiagram-XKGWAZYB-DFMS6feI.js → pegDiagram-XKGWAZYB-DiY7rITR.js} +2 -2
  48. package/dist/{pencil-CHkdsX07.js → pencil-AWgwbH4D.js} +1 -1
  49. package/dist/{pieDiagram-E7YTZNPT-C0MSBop-.js → pieDiagram-E7YTZNPT-BL6InbDs.js} +1 -1
  50. package/dist/{process-output-CnCLfvnL.js → process-output-xJm8T5-E.js} +4 -4
  51. package/dist/{railroadDiagram-O6MQD6OU-mbdav2pV.js → railroadDiagram-O6MQD6OU-DterenMu.js} +2 -2
  52. package/dist/{requirementDiagram-BXWQKSXE-C1HNBBO6.js → requirementDiagram-BXWQKSXE-Vb5_9LHC.js} +1 -1
  53. package/dist/{reveal-component-BefmhjJF.js → reveal-component-B7TgfbYJ.js} +1008 -1008
  54. package/dist/{select-CvorIE3l.js → select-CKLRKIzB.js} +298 -298
  55. package/dist/{sequenceDiagram-WJ2MYXX4-D6gBHifq.js → sequenceDiagram-WJ2MYXX4-BWsq8hMt.js} +1 -1
  56. package/dist/{spec-ayzaXGVq.js → spec-C4uOz0Em.js} +4 -4
  57. package/dist/{stateDiagram-D77RDMKH-Bx-fTtRZ.js → stateDiagram-D77RDMKH-nfKKy6aQ.js} +2 -2
  58. package/dist/{stateDiagram-v2-MP3YSRHH-Cec8T2yO.js → stateDiagram-v2-MP3YSRHH-DMUHA_9A.js} +2 -2
  59. package/dist/{static-state-CqwW3B_X.js → static-state-DZ1nSa6e.js} +9 -9
  60. package/dist/{swimlanes-42K2YHIH-C2bAgnov.js → swimlanes-42K2YHIH-N4qHIMoc.js} +1 -1
  61. package/dist/{swimlanesDiagram-VR7AAH4N-CzeG-Mnb.js → swimlanesDiagram-VR7AAH4N-DQpDDjQb.js} +2 -2
  62. package/dist/{timeline-definition-24CTP7MA-DTJ0Rx8X.js → timeline-definition-24CTP7MA-Od8dY9F5.js} +1 -1
  63. package/dist/{toast-6V8Og7d5.js → toast-bhZHUEal.js} +187 -187
  64. package/dist/{tooltip-D0h-ZJ6j.js → tooltip-DSWC_Td_.js} +40 -40
  65. package/dist/{use-restore-focus-BFvwj2Hj.js → use-restore-focus-ocw7t85i.js} +1371 -1373
  66. package/dist/{useDateFormatter-D6o9PsWt.js → useDateFormatter-BiDS8uXQ.js} +2 -2
  67. package/dist/{useDeepCompareMemoize-D-Pbv7dN.js → useDeepCompareMemoize-BsaXfZ8C.js} +1 -1
  68. package/dist/{useLifecycle-CE0yGTMF.js → useLifecycle-CCV7yZ-v.js} +1 -1
  69. package/dist/{vega-component-DTf7GHQe.js → vega-component-DpTyTrz3.js} +6 -6
  70. package/dist/{vennDiagram-4TSXK5OY-lIM3SAjl.js → vennDiagram-4TSXK5OY-Di3T2YMb.js} +1 -1
  71. package/dist/{wardleyDiagram-VM6X3IG4-Bw_t7uvA.js → wardleyDiagram-VM6X3IG4-CKOF5DTi.js} +1 -1
  72. package/dist/{xychartDiagram-S5SC5T6Z-BXwkLYKj.js → xychartDiagram-S5SC5T6Z-GYLPWSeb.js} +1 -1
  73. package/package.json +1 -1
  74. package/src/__mocks__/executions.ts +27 -5
  75. package/src/__tests__/branded.ts +4 -0
  76. package/src/__tests__/notebook-analysis.ts +48 -0
  77. package/src/components/editor/ai/__tests__/completion-utils.test.ts +28 -61
  78. package/src/components/editor/cell/__tests__/useRunCells.test.tsx +2 -2
  79. package/src/components/editor/navigation/__tests__/navigation.test.ts +0 -4
  80. package/src/components/tracing/tracing-keyboard.test.tsx +4 -3
  81. package/src/core/cells/__tests__/add-missing-import.test.ts +14 -9
  82. package/src/core/cells/__tests__/pending-delete-service.test.tsx +4 -11
  83. package/src/core/cells/__tests__/runs.test.ts +11 -11
  84. package/src/core/cells/add-missing-import.ts +2 -3
  85. package/src/core/cells/runs.ts +6 -4
  86. package/src/core/cells/session.ts +4 -1
  87. package/src/core/codemirror/code-lens/__tests__/entities.test.ts +7 -11
  88. package/src/core/codemirror/code-lens/__tests__/extension.test.ts +8 -13
  89. package/src/core/codemirror/code-lens/__tests__/perf.test.ts +7 -9
  90. package/src/core/codemirror/copilot/__tests__/getCodes.test.ts +9 -13
  91. package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +16 -35
  92. package/src/core/codemirror/language/embedded/__tests__/embedded-python.test.ts +2 -18
  93. package/src/core/codemirror/reactive-references/__tests__/extension.test.ts +8 -14
  94. package/src/core/datasets/__tests__/data-source.test.ts +15 -17
  95. package/src/core/datasets/data-source-connections.ts +8 -11
  96. package/src/core/datasets/state.ts +7 -12
  97. package/src/core/executions/__tests__/atoms.test.ts +2 -2
  98. package/src/core/executions/__tests__/freshness.test.ts +10 -5
  99. package/src/core/executions/__tests__/interrupt.test.ts +3 -1
  100. package/src/core/executions/__tests__/output-lifecycle.test.ts +3 -3
  101. package/src/core/executions/__tests__/output.test.ts +2 -2
  102. package/src/core/executions/__tests__/run.test.ts +2 -2
  103. package/src/core/executions/__tests__/select.test.ts +10 -10
  104. package/src/core/executions/atoms.ts +2 -1
  105. package/src/core/executions/freshness.ts +2 -2
  106. package/src/core/islands/bootstrap.ts +0 -2
  107. package/src/core/notebook/replica/__tests__/executions.test.ts +13 -9
  108. package/src/core/notebook/replica/__tests__/replica.test.ts +7 -2
  109. package/src/core/notebook/replica/replica.ts +11 -2
  110. package/src/core/notebook/replica/resources/executions.ts +29 -20
  111. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +192 -1
  112. package/src/core/session/useNotebookSession.tsx +37 -37
  113. package/src/core/storage/__tests__/state.test.ts +6 -9
  114. package/src/core/storage/state.ts +5 -8
  115. package/src/core/transports/__tests__/static.test.ts +2 -1
  116. package/src/core/variables/state.ts +73 -68
  117. package/src/core/variables/types.ts +2 -2
  118. package/src/core/wasm/bridge.ts +5 -4
  119. package/src/core/variables/__tests__/state.test.ts +0 -148
@@ -1,13 +1,12 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { describe, expect, it } from "vitest";
4
- import { cellId } from "@/__tests__/branded";
4
+ import { cellId, runId } from "@/__tests__/branded";
5
5
  import type { ExecutionOutput as Execution } from "@marimo-team/client/protocol";
6
6
  import {
7
7
  exportedForTesting,
8
8
  MAX_CODE_LENGTH,
9
9
  MAX_RUNS,
10
- type RunId,
11
10
  type RunsState,
12
11
  } from "../runs";
13
12
 
@@ -15,7 +14,7 @@ const { reducer, initialState, isPureMarkdown } = exportedForTesting;
15
14
 
16
15
  const queued = {
17
16
  id: "e1",
18
- run_id: "r1",
17
+ run_id: runId("r1"),
19
18
  runtime_id: "runtime",
20
19
  caused_by_id: null,
21
20
  cell_id: cellId("cell"),
@@ -45,7 +44,6 @@ describe("execution traces", () => {
45
44
  status: "completed",
46
45
  outcome: { kind: "cancelled" },
47
46
  } satisfies Execution["state"];
48
- const runId = "r1" as RunId;
49
47
  const running = observe(observe(initialState()), {
50
48
  state: { started_at, status: "running" },
51
49
  });
@@ -53,7 +51,9 @@ describe("execution traces", () => {
53
51
  observe(running, { state: completed }),
54
52
  observe(initialState(), { state: completed }),
55
53
  ]) {
56
- expect(state.runMap.get(runId)?.cellRuns.get(cellId("cell"))).toEqual({
54
+ expect(
55
+ state.runMap.get(queued.run_id)?.cellRuns.get(cellId("cell")),
56
+ ).toEqual({
57
57
  cellId: "cell",
58
58
  executionId: "e1",
59
59
  code: "print(1)",
@@ -66,7 +66,7 @@ describe("execution traces", () => {
66
66
  observe(running, {
67
67
  state: { ...completed, outcome: { kind: "succeeded" } },
68
68
  })
69
- .runMap.get(runId)
69
+ .runMap.get(queued.run_id)
70
70
  ?.cellRuns.get(cellId("cell"))?.status,
71
71
  ).toBe("success");
72
72
  });
@@ -89,7 +89,7 @@ describe("execution traces", () => {
89
89
  },
90
90
  });
91
91
  expect(
92
- state.runMap.get("r1" as RunId)?.cellRuns.get(cellId("cell"))?.status,
92
+ state.runMap.get(queued.run_id)?.cellRuns.get(cellId("cell"))?.status,
93
93
  ).toBe("skipped");
94
94
  },
95
95
  );
@@ -109,7 +109,7 @@ describe("execution traces", () => {
109
109
  },
110
110
  });
111
111
  expect(
112
- next.runMap.get("r1" as RunId)?.cellRuns.get(cellId("cell"))?.code,
112
+ next.runMap.get(queued.run_id)?.cellRuns.get(cellId("cell"))?.code,
113
113
  ).toBe(preview);
114
114
  }
115
115
  });
@@ -119,13 +119,13 @@ describe("execution traces", () => {
119
119
  for (let i = 0; i <= MAX_RUNS; i++) {
120
120
  state = observe(
121
121
  state,
122
- { run_id: String(i) },
122
+ { run_id: runId(String(i)) },
123
123
  "x".repeat(MAX_CODE_LENGTH + 1),
124
124
  );
125
125
  }
126
126
  expect(state.runMap.size).toBe(MAX_RUNS);
127
127
  expect(state.runIds[0]).toBe(String(MAX_RUNS));
128
- expect(state.runMap.has("0" as RunId)).toBe(false);
128
+ expect(state.runMap.has(runId("0"))).toBe(false);
129
129
  expect(
130
130
  state.runMap.get(state.runIds[0])?.cellRuns.get(cellId("cell"))?.code
131
131
  .length,
@@ -148,7 +148,7 @@ describe("execution traces", () => {
148
148
  expect(observe(initial, {}, markdown)).toBe(initial);
149
149
  expect(
150
150
  observe(observe(initial), { cell_id: cellId("md") }, markdown).runMap.get(
151
- "r1" as RunId,
151
+ queued.run_id,
152
152
  )?.cellRuns.size,
153
153
  ).toBe(2);
154
154
  });
@@ -3,6 +3,7 @@
3
3
  import { runCells } from "../executions";
4
4
  import { store } from "../state/jotai";
5
5
  import { variablesAtom } from "../variables/state";
6
+ import type { VariableName } from "../variables/types";
6
7
  import { notebookAtom } from "./cells";
7
8
  import type { CreateCell, CreateCellOptions } from "./actions";
8
9
  import { CellId } from "./ids";
@@ -23,10 +24,8 @@ export function maybeAddMissingImport({
23
24
  onAddImport: (importStatement: string) => void;
24
25
  appStore?: typeof store;
25
26
  }): boolean {
26
- // If variableName is already in the variables state,
27
- // then the import is not missing (or the name has been taken).
28
27
  const variables = appStore.get(variablesAtom);
29
- if (variableName in variables) {
28
+ if (variables[variableName as VariableName]?.declaredBy.length) {
30
29
  return false;
31
30
  }
32
31
 
@@ -1,10 +1,12 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
  import { createReducerAndAtoms } from "@/utils/createReducer";
3
- import type { TypedString } from "@/utils/typed";
4
- import type { ExecutionOutput as Execution } from "@marimo-team/client/protocol";
3
+ import type {
4
+ ExecutionOutput as Execution,
5
+ RunId,
6
+ } from "@marimo-team/client/protocol";
5
7
  import { completedAt, startedAt } from "@/core/notebook/replica";
6
8
  import type { CellId } from "./ids";
7
- export type RunId = TypedString<"RunId">;
9
+ export type { RunId };
8
10
 
9
11
  export interface CellRun {
10
12
  cellId: CellId;
@@ -75,7 +77,7 @@ const {
75
77
  if (record.run_id === null || record.cell_id === null) {
76
78
  return state;
77
79
  }
78
- const runId = record.run_id as RunId;
80
+ const runId = record.run_id;
79
81
  const cellId = record.cell_id;
80
82
  const previous = state.runMap.get(runId);
81
83
  if (previous === undefined && code !== undefined && isPureMarkdown(code)) {
@@ -16,6 +16,9 @@ import { type CellRuntimeState, createCellRuntimeState } from "./types";
16
16
 
17
17
  /** The identity of a snapshot the page carries. A host's own stream replaces it. */
18
18
  export const EMBEDDED = "embedded";
19
+ // SAFETY: This snapshot assigns one synthetic run ID to all its restored
20
+ // executions. The fixed suffix satisfies RunId's nonempty-string requirement.
21
+ const EMBEDDED_RUN_ID = `${EMBEDDED}:run` as Protocol.RunId;
19
22
 
20
23
  // Constants
21
24
  const DEFAULT_TIMESTAMP = 0;
@@ -261,7 +264,7 @@ function resultRecord(
261
264
  return {
262
265
  execution: {
263
266
  id,
264
- run_id: `${EMBEDDED}:run`,
267
+ run_id: EMBEDDED_RUN_ID,
265
268
  runtime_id: EMBEDDED,
266
269
  caused_by_id: null,
267
270
  cell_id: cell.id,
@@ -1,6 +1,10 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { beforeEach, describe, expect, it, vi } from "vitest";
4
+ import {
5
+ type AnalysisCells,
6
+ setNotebookAnalysis,
7
+ } from "@/__tests__/notebook-analysis";
4
8
  import { cellId, variableName } from "@/__tests__/branded";
5
9
  import {
6
10
  type DataSourceConnection,
@@ -13,8 +17,6 @@ import type { DataTable } from "@/core/kernel/messages";
13
17
  import { store } from "@/core/state/jotai";
14
18
  import { storageAtom } from "@/core/storage/state";
15
19
  import type { StorageNamespace } from "@/core/storage/types";
16
- import { variablesAtom } from "@/core/variables/state";
17
- import type { Variables } from "@/core/variables/types";
18
20
  import { Logger } from "@/utils/Logger";
19
21
  import { getLensEntities } from "../entities";
20
22
 
@@ -52,7 +54,7 @@ function seedStore(opts: {
52
54
  tables?: DataTable[];
53
55
  namespaces?: StorageNamespace[];
54
56
  connections?: DataSourceConnection[];
55
- variables?: Variables;
57
+ cells?: AnalysisCells;
56
58
  }) {
57
59
  store.set(datasetsAtom, {
58
60
  tables: opts.tables ?? [],
@@ -69,7 +71,7 @@ function seedStore(opts: {
69
71
  latestEngineSelected: DUCKDB_ENGINE,
70
72
  connectionsMap: new Map((opts.connections ?? []).map((c) => [c.name, c])),
71
73
  });
72
- store.set(variablesAtom, opts.variables ?? {});
74
+ setNotebookAnalysis(store, opts.cells ?? {});
73
75
  }
74
76
 
75
77
  describe("getLensEntities", () => {
@@ -107,13 +109,7 @@ describe("getLensEntities", () => {
107
109
  it("excludes entities declared by a different cell", () => {
108
110
  seedStore({
109
111
  tables: [table("df")],
110
- variables: {
111
- [variableName("df")]: {
112
- name: variableName("df"),
113
- declaredBy: [OTHER_CELL],
114
- usedBy: [],
115
- },
116
- },
112
+ cells: { [OTHER_CELL]: { defs: ["df"] } },
117
113
  });
118
114
 
119
115
  expect(getLensEntities(CELL)).toEqual(new Map());
@@ -4,6 +4,10 @@ import { python } from "@codemirror/lang-python";
4
4
  import { EditorState } from "@codemirror/state";
5
5
  import { EditorView } from "@codemirror/view";
6
6
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
7
+ import {
8
+ type AnalysisCells,
9
+ setNotebookAnalysis,
10
+ } from "@/__tests__/notebook-analysis";
7
11
  import { cellId, variableName } from "@/__tests__/branded";
8
12
  import { languageAdapterState } from "@/core/codemirror/language/extension";
9
13
  import { LanguageAdapters } from "@/core/codemirror/language/LanguageAdapters";
@@ -20,8 +24,6 @@ import type { DataTable } from "@/core/kernel/messages";
20
24
  import { store } from "@/core/state/jotai";
21
25
  import { storageAtom } from "@/core/storage/state";
22
26
  import type { StorageNamespace } from "@/core/storage/types";
23
- import { variablesAtom } from "@/core/variables/state";
24
- import type { Variables } from "@/core/variables/types";
25
27
  import { openLensTarget } from "../actions";
26
28
  import {
27
29
  CODE_LENS_HOVER_DELAY_MS,
@@ -77,7 +79,7 @@ function seedStore(opts: {
77
79
  tables?: DataTable[];
78
80
  namespaces?: StorageNamespace[];
79
81
  connections?: DataSourceConnection[];
80
- variables?: Variables;
82
+ cells?: AnalysisCells;
81
83
  }) {
82
84
  store.set(datasetsAtom, {
83
85
  tables: opts.tables ?? [],
@@ -99,7 +101,7 @@ function seedStore(opts: {
99
101
  ]),
100
102
  ),
101
103
  });
102
- store.set(variablesAtom, opts.variables ?? {});
104
+ setNotebookAnalysis(store, opts.cells ?? {});
103
105
  }
104
106
 
105
107
  describe("codeLensBundle", () => {
@@ -155,7 +157,7 @@ describe("codeLensBundle", () => {
155
157
  seedStore({ tables: withLens ? [DF_TABLE] : [] });
156
158
  const v = await mount("df = load()");
157
159
  const dispatch = vi.spyOn(v, "dispatch");
158
- store.set(variablesAtom, {});
160
+ setNotebookAnalysis(store, {});
159
161
  vi.advanceTimersByTime(300);
160
162
  await Promise.resolve();
161
163
  expect(dispatch).not.toHaveBeenCalled();
@@ -410,16 +412,9 @@ describe("codeLensBundle", () => {
410
412
  });
411
413
 
412
414
  it("only decorates the declaring cell", async () => {
413
- const dfName = variableName("df");
414
415
  seedStore({
415
416
  tables: [DF_TABLE],
416
- variables: {
417
- [dfName]: {
418
- name: dfName,
419
- declaredBy: [cellId("other-cell")],
420
- usedBy: [cellId("cell1")],
421
- },
422
- },
417
+ cells: { "other-cell": { defs: ["df"] }, cell1: { refs: ["df"] } },
423
418
  });
424
419
  const v = await mount("df = load()");
425
420
 
@@ -8,6 +8,10 @@
8
8
  import { python } from "@codemirror/lang-python";
9
9
  import { EditorState } from "@codemirror/state";
10
10
  import { describe, expect, it } from "vitest";
11
+ import {
12
+ type AnalysisCells,
13
+ setNotebookAnalysis,
14
+ } from "@/__tests__/notebook-analysis";
11
15
  import { cellId, variableName } from "@/__tests__/branded";
12
16
  import type { CellId } from "@/core/cells/ids";
13
17
  import { dataSourceConnectionsAtom } from "@/core/datasets/data-source-connections";
@@ -17,8 +21,6 @@ import type { QualifiedColumn } from "@/core/datasets/types";
17
21
  import type { DataTable } from "@/core/kernel/messages";
18
22
  import { store } from "@/core/state/jotai";
19
23
  import { storageAtom } from "@/core/storage/state";
20
- import { variablesAtom } from "@/core/variables/state";
21
- import type { Variables } from "@/core/variables/types";
22
24
  import { findCacheSites, findDeclarationSites } from "../analyzer";
23
25
  import { getLensEntities } from "../entities";
24
26
 
@@ -32,7 +34,7 @@ describe("code-lens performance", () => {
32
34
  const CELL_COUNT = 1000;
33
35
 
34
36
  const tables: DataTable[] = [];
35
- const variables: Variables = {};
37
+ const cells: AnalysisCells = {};
36
38
  for (let i = 0; i < DATASOURCE_COUNT; i++) {
37
39
  const name = variableName(`table_${i}`);
38
40
  tables.push({
@@ -45,11 +47,7 @@ describe("code-lens performance", () => {
45
47
  variable_name: name,
46
48
  });
47
49
  // Every datasource is owned by a distinct cell, like a real notebook.
48
- variables[name] = {
49
- name,
50
- declaredBy: [cellId(`owner-${i}`)],
51
- usedBy: [],
52
- };
50
+ cells[`owner-${i}`] = { defs: [name] };
53
51
  }
54
52
  store.set(datasetsAtom, {
55
53
  tables,
@@ -66,7 +64,7 @@ describe("code-lens performance", () => {
66
64
  latestEngineSelected: DUCKDB_ENGINE,
67
65
  connectionsMap: new Map(),
68
66
  });
69
- store.set(variablesAtom, variables);
67
+ setNotebookAnalysis(store, cells);
70
68
 
71
69
  const cellIds: CellId[] = Array.from({ length: CELL_COUNT }, (_, i) =>
72
70
  cellId(`cell-${i}`),
@@ -5,12 +5,12 @@ import { defaultUserConfig } from "@/core/config/config-schema";
5
5
  import { EditorState } from "@codemirror/state";
6
6
  import { EditorView } from "@codemirror/view";
7
7
  import { describe, expect, it } from "vitest";
8
+ import { setNotebookAnalysis } from "@/__tests__/notebook-analysis";
8
9
  import { cellId, variableName } from "@/__tests__/branded";
9
10
  import { initialNotebookState, notebookAtom } from "@/core/cells/cells";
10
11
  import { createCell } from "@/core/cells/types";
11
12
  import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
12
13
  import { store } from "@/core/state/jotai";
13
- import { variablesAtom } from "@/core/variables/state";
14
14
  import { cellConfigExtension } from "../../config/extension";
15
15
  import { adaptiveLanguageConfiguration } from "../../language/extension";
16
16
  import {
@@ -204,12 +204,10 @@ describe("getCodes", () => {
204
204
  [Cells.cell3]: { current: mockEditorViews[2] },
205
205
  },
206
206
  });
207
- store.set(variablesAtom, {
208
- [Variables.var1]: {
209
- name: Variables.var1,
210
- declaredBy: [Cells.cell1],
211
- usedBy: [Cells.cell2, Cells.cell3],
212
- },
207
+ setNotebookAnalysis(store, {
208
+ [Cells.cell1]: { defs: [Variables.var1] },
209
+ [Cells.cell2]: { refs: [Variables.var1] },
210
+ [Cells.cell3]: { refs: [Variables.var1] },
213
211
  });
214
212
  const result = getCodes(otherCode);
215
213
  expect(result).toEqual("import os\nx = 1\ny = x + 1\nprint('Hello World')");
@@ -258,12 +256,10 @@ describe("topologicalCodesAtom", () => {
258
256
  [Cells.cell3]: createCell({ id: Cells.cell3, code: "y = x + 1" }),
259
257
  },
260
258
  });
261
- store.set(variablesAtom, {
262
- [Variables.var1]: {
263
- name: Variables.var1,
264
- declaredBy: [Cells.cell1],
265
- usedBy: [Cells.cell2, Cells.cell3],
266
- },
259
+ setNotebookAnalysis(store, {
260
+ [Cells.cell1]: { defs: [Variables.var1] },
261
+ [Cells.cell2]: { refs: [Variables.var1] },
262
+ [Cells.cell3]: { refs: [Variables.var1] },
267
263
  });
268
264
 
269
265
  const { cellIds, codes } = store.get(topologicalCodesAtom);
@@ -4,12 +4,13 @@ import { python } from "@codemirror/lang-python";
4
4
  import { EditorState } from "@codemirror/state";
5
5
  import { EditorView, keymap } from "@codemirror/view";
6
6
  import { afterEach, describe, expect, test, vi } from "vitest";
7
- import { cellId, variableName } from "@/__tests__/branded";
7
+ import { setNotebookAnalysis } from "@/__tests__/notebook-analysis";
8
+ import { cellId } from "@/__tests__/branded";
8
9
  import type { CellHandle } from "@/components/editor/notebook-cell";
9
10
  import { initialNotebookState, notebookAtom } from "@/core/cells/cells";
10
11
  import { editorMountScheduler } from "@/core/codemirror/editor-mount-scheduler";
12
+ import { activeNotebookReplicaAtom } from "@/core/session/active-notebook";
11
13
  import { store } from "@/core/state/jotai";
12
- import { variablesAtom } from "@/core/variables/state";
13
14
  import {
14
15
  goToDefinitionAtCursorPosition,
15
16
  goToDefinitionWithLspFallback,
@@ -41,7 +42,7 @@ afterEach(() => {
41
42
  }
42
43
 
43
44
  store.set(notebookAtom, initialNotebookState());
44
- store.set(variablesAtom, {});
45
+ store.set(activeNotebookReplicaAtom, null);
45
46
  });
46
47
 
47
48
  describe("goToDefinitionAtCursorPosition", () => {
@@ -64,14 +65,9 @@ describe("goToDefinitionAtCursorPosition", () => {
64
65
  };
65
66
 
66
67
  store.set(notebookAtom, notebook);
67
- store.set(variablesAtom, {
68
- [variableName("a")]: {
69
- dataType: "int",
70
- declaredBy: [definingCell],
71
- name: variableName("a"),
72
- usedBy: [usageCell],
73
- value: "10",
74
- },
68
+ setNotebookAnalysis(store, {
69
+ [definingCell]: { defs: ["a"] },
70
+ [usageCell]: { refs: ["a"] },
75
71
  });
76
72
 
77
73
  const result = goToDefinitionAtCursorPosition(usageView);
@@ -106,14 +102,9 @@ def test():
106
102
  };
107
103
 
108
104
  store.set(notebookAtom, notebook);
109
- store.set(variablesAtom, {
110
- [variableName("a")]: {
111
- dataType: "int",
112
- declaredBy: [globalCell],
113
- name: variableName("a"),
114
- usedBy: [localCell],
115
- value: "10",
116
- },
105
+ setNotebookAnalysis(store, {
106
+ [globalCell]: { defs: ["a"] },
107
+ [localCell]: { refs: ["a"] },
117
108
  });
118
109
 
119
110
  const result = goToDefinitionAtCursorPosition(localView);
@@ -167,14 +158,9 @@ print(mymodule)`;
167
158
  } as never;
168
159
 
169
160
  store.set(notebookAtom, notebook);
170
- store.set(variablesAtom, {
171
- [variableName("mymodule")]: {
172
- dataType: "int",
173
- declaredBy: [moduleCell],
174
- name: variableName("mymodule"),
175
- usedBy: [usageCell],
176
- value: "100",
177
- },
161
+ setNotebookAnalysis(store, {
162
+ [moduleCell]: { defs: ["mymodule"] },
163
+ [usageCell]: { refs: ["mymodule"] },
178
164
  });
179
165
 
180
166
  const result = goToDefinitionAtCursorPosition(usageView);
@@ -214,14 +200,9 @@ print(mymodule)`;
214
200
  };
215
201
 
216
202
  store.set(notebookAtom, notebook);
217
- store.set(variablesAtom, {
218
- [variableName("a")]: {
219
- dataType: "int",
220
- declaredBy: [definingCell],
221
- name: variableName("a"),
222
- usedBy: [usageCell],
223
- value: "10",
224
- },
203
+ setNotebookAnalysis(store, {
204
+ [definingCell]: { defs: ["a"] },
205
+ [usageCell]: { refs: ["a"] },
225
206
  });
226
207
 
227
208
  const result = goToDefinitionAtCursorPosition(usageView);
@@ -8,9 +8,8 @@ import { EditorState } from "@codemirror/state";
8
8
  import { classHighlighter, highlightTree } from "@lezer/highlight";
9
9
  import { parser as markdownParser } from "@lezer/markdown";
10
10
  import { beforeEach, describe, expect, it, vi } from "vitest";
11
- import { cellId, variableName } from "@/__tests__/branded";
11
+ import { setNotebookAnalysis } from "@/__tests__/notebook-analysis";
12
12
  import { store } from "@/core/state/jotai";
13
- import { variablesAtom } from "@/core/variables/state";
14
13
  import { parsePython, variableCompletionSource } from "../embedded-python";
15
14
  import { parseLatex } from "../latex";
16
15
 
@@ -158,22 +157,7 @@ describe("parsePython", () => {
158
157
 
159
158
  describe("variableCompletionSource", () => {
160
159
  beforeEach(() => {
161
- const mockCellId = cellId("cell-1");
162
- const mockVariables = {
163
- [variableName("var1")]: {
164
- name: variableName("var1"),
165
- dataType: "int",
166
- declaredBy: [mockCellId],
167
- usedBy: [mockCellId],
168
- },
169
- [variableName("var2")]: {
170
- name: variableName("var2"),
171
- dataType: "str",
172
- declaredBy: [mockCellId],
173
- usedBy: [mockCellId],
174
- },
175
- };
176
- store.set(variablesAtom, mockVariables);
160
+ setNotebookAnalysis(store, { c1: { defs: ["var1", "var2"] } });
177
161
  });
178
162
 
179
163
  it("should provide completions inside {} block", () => {
@@ -3,9 +3,10 @@ import { python } from "@codemirror/lang-python";
3
3
  import { EditorState } from "@codemirror/state";
4
4
  import { EditorView } from "@codemirror/view";
5
5
  import { afterEach, expect, it, vi } from "vitest";
6
- import { cellId, variableName } from "@/__tests__/branded";
6
+ import { setNotebookAnalysis } from "@/__tests__/notebook-analysis";
7
+ import { cellId } from "@/__tests__/branded";
8
+ import { activeNotebookReplicaAtom } from "@/core/session/active-notebook";
7
9
  import { store } from "@/core/state/jotai";
8
- import { variablesAtom } from "@/core/variables/state";
9
10
  import {
10
11
  reactiveReferencesBundle,
11
12
  reactiveReferencesField,
@@ -15,12 +16,11 @@ let view: EditorView;
15
16
  afterEach(() => {
16
17
  view?.destroy();
17
18
  vi.useRealTimers();
18
- store.set(variablesAtom, {});
19
+ store.set(activeNotebookReplicaAtom, null);
19
20
  });
20
21
 
21
22
  it("skips unchanged ranges, updates edited ranges, and clears removed references", async () => {
22
23
  vi.useFakeTimers();
23
- store.set(variablesAtom, {});
24
24
  view = new EditorView({
25
25
  state: EditorState.create({
26
26
  doc: "value",
@@ -35,26 +35,20 @@ it("skips unchanged ranges, updates edited ranges, and clears removed references
35
35
  };
36
36
  await flush();
37
37
  expect(dispatch).not.toHaveBeenCalled();
38
- const variables = {
39
- [variableName("value")]: {
40
- name: variableName("value"),
41
- declaredBy: [cellId("cell2")],
42
- usedBy: [cellId("cell1")],
43
- },
44
- };
45
- store.set(variablesAtom, variables);
38
+ const cells = { cell2: { defs: ["value"] }, cell1: { refs: ["value"] } };
39
+ setNotebookAnalysis(store, cells);
46
40
  await flush();
47
41
  expect(view.state.field(reactiveReferencesField).ranges).toEqual([
48
42
  { from: 0, to: 5, variableName: "value" },
49
43
  ]);
50
44
  dispatch.mockClear();
51
- store.set(variablesAtom, { ...variables });
45
+ setNotebookAnalysis(store, cells);
52
46
  await flush();
53
47
  expect(dispatch).not.toHaveBeenCalled();
54
48
  view.dispatch({ changes: { from: 0, insert: " " } });
55
49
  await flush();
56
50
  expect(view.state.field(reactiveReferencesField).ranges[0].from).toBe(1);
57
- store.set(variablesAtom, {});
51
+ setNotebookAnalysis(store, {});
58
52
  await flush();
59
53
  expect(view.state.field(reactiveReferencesField).ranges).toEqual([]);
60
54
  });
@@ -1,9 +1,7 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
  import { beforeEach, describe, expect, it } from "vitest";
3
- import { variableName } from "@/__tests__/branded";
4
3
  import type { DatabaseSchema, DataTable } from "@/core/kernel/messages";
5
4
  import { store } from "@/core/state/jotai";
6
- import type { VariableName } from "@/core/variables/types";
7
5
  import {
8
6
  allTablesAtom,
9
7
  type DataSourceConnection,
@@ -147,11 +145,10 @@ describe("data source connections", () => {
147
145
  });
148
146
 
149
147
  describe("filtering data sources", () => {
150
- // helper function to filter data sources by variable names
151
- function filterDataSources(payload: VariableName[]) {
148
+ function removeConnections(names: string[]) {
152
149
  return reducer(baseState, {
153
- type: "filterDataSourcesFromVariables",
154
- payload: payload,
150
+ type: "removeConnectionsForVariables",
151
+ payload: new Set(names),
155
152
  });
156
153
  }
157
154
 
@@ -179,16 +176,20 @@ describe("filtering data sources", () => {
179
176
  expect(baseState.connectionsMap.size).toBe(defaultConnSize + 2); // 2 + 2 (default) connections
180
177
  });
181
178
 
182
- it("keeps only internal engines when no variables", () => {
183
- const filtered = filterDataSources([]);
179
+ it("keeps internal engines when bindings are removed", () => {
180
+ const filtered = removeConnections([
181
+ "conn1",
182
+ "conn2",
183
+ ...INTERNAL_SQL_ENGINES,
184
+ ]);
184
185
  expect(filtered.connectionsMap.size).toBe(defaultConnSize);
185
186
  for (const engine of INTERNAL_SQL_ENGINES) {
186
187
  expect(filtered.connectionsMap.has(engine)).toBe(true);
187
188
  }
188
189
  });
189
190
 
190
- it("keeps matching variables and internal engines", () => {
191
- const filtered = filterDataSources([variableName("conn1")]);
191
+ it("keeps connections whose binding is still live", () => {
192
+ const filtered = removeConnections(["conn2"]);
192
193
  expect(filtered.connectionsMap.size).toBe(defaultConnSize + 1);
193
194
  expect(filtered.connectionsMap.has("conn1" as ConnectionName)).toBe(true);
194
195
  for (const engine of INTERNAL_SQL_ENGINES) {
@@ -196,16 +197,13 @@ describe("filtering data sources", () => {
196
197
  }
197
198
  });
198
199
 
199
- it("filters out non-matching variables", () => {
200
- const filtered = filterDataSources([variableName("non_existent")]);
201
- expect(filtered.connectionsMap.size).toBe(defaultConnSize);
200
+ it("ignores removal of an unknown binding", () => {
201
+ const filtered = removeConnections(["non_existent"]);
202
+ expect(filtered.connectionsMap.size).toBe(defaultConnSize + 2);
202
203
  });
203
204
 
204
205
  it("handles mix of matching and non-matching variables", () => {
205
- const filtered = filterDataSources([
206
- variableName("conn1"),
207
- variableName("non_existent"),
208
- ]);
206
+ const filtered = removeConnections(["conn2", "non_existent"]);
209
207
  expect(filtered.connectionsMap.size).toBe(defaultConnSize + 1);
210
208
  expect(filtered.connectionsMap.has("conn1" as ConnectionName)).toBe(true);
211
209
  for (const engine of INTERNAL_SQL_ENGINES) {
@@ -11,7 +11,6 @@ import type {
11
11
  DataTable,
12
12
  } from "../kernel/messages";
13
13
  import { store } from "../state/jotai";
14
- import type { VariableName } from "../variables/types";
15
14
  import {
16
15
  type ConnectionName,
17
16
  DEFAULT_DUCKDB_DATABASE,
@@ -148,21 +147,19 @@ const {
148
147
  };
149
148
  },
150
149
 
151
- // Keep internal engines and any connections that are used by variables
152
- filterDataSourcesFromVariables: (
150
+ removeConnectionsForVariables: (
153
151
  state: DataSourceState,
154
- variableNames: VariableName[],
152
+ removed: ReadonlySet<string>,
155
153
  ) => {
156
154
  const { latestEngineSelected, connectionsMap } = state;
157
- const names = new Set(variableNames);
158
155
  const newMap = new Map(
159
- [...connectionsMap].filter(([name]) => {
160
- if (INTERNAL_SQL_ENGINES.has(name)) {
161
- return true;
162
- }
163
- return names.has(name as unknown as VariableName);
164
- }),
156
+ [...connectionsMap].filter(
157
+ ([name]) => INTERNAL_SQL_ENGINES.has(name) || !removed.has(name),
158
+ ),
165
159
  );
160
+ if (newMap.size === connectionsMap.size) {
161
+ return state;
162
+ }
166
163
  return {
167
164
  // Allow automatic selection again when the selected connection disappears.
168
165
  latestEngineSelected: