@marimo-team/islands 0.26.1-dev21 → 0.26.1-dev27

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 (106) hide show
  1. package/dist/{ConnectedDataExplorerComponent-CR9WyiEc.js → ConnectedDataExplorerComponent-jtTaDisw.js} +16 -16
  2. package/dist/{ErrorBoundary-C5X_T831.js → ErrorBoundary-zpe6C93k.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-7FxdzbDq.js → code-visibility-BtvMUvQ6.js} +19 -19
  16. package/dist/{common-D-iTRwaQ.js → common-B46KECgx.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-DoWUW2oW.js → data-grid-overlay-editor-CLCJ44fs.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-OUiV15AL.js → feedback-button-CnyHlwaY.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-CFouYM6e.js → glide-data-editor-C3znsea0.js} +11 -11
  37. package/dist/{glide-utils-bKdvDwwo.js → glide-utils-CZ-O-CB_.js} +2 -2
  38. package/dist/{globals-B_U6Frqj.js → globals-DHoGn4Qt.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 +399 -398
  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-CiQQjf9m.js → number-overlay-editor-DwK5S3_f.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-B73BObRc.js → reveal-component-Dsp5kSt3.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 +25 -3
  75. package/src/__tests__/notebook-analysis.ts +48 -0
  76. package/src/components/editor/ai/__tests__/completion-utils.test.ts +28 -61
  77. package/src/components/editor/navigation/__tests__/navigation.test.ts +0 -4
  78. package/src/core/cells/__tests__/add-missing-import.test.ts +14 -9
  79. package/src/core/cells/__tests__/pending-delete-service.test.tsx +4 -11
  80. package/src/core/cells/add-missing-import.ts +2 -3
  81. package/src/core/codemirror/code-lens/__tests__/entities.test.ts +7 -11
  82. package/src/core/codemirror/code-lens/__tests__/extension.test.ts +8 -13
  83. package/src/core/codemirror/code-lens/__tests__/perf.test.ts +7 -9
  84. package/src/core/codemirror/copilot/__tests__/getCodes.test.ts +9 -13
  85. package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +16 -35
  86. package/src/core/codemirror/language/embedded/__tests__/embedded-python.test.ts +2 -18
  87. package/src/core/codemirror/reactive-references/__tests__/extension.test.ts +8 -14
  88. package/src/core/datasets/__tests__/data-source.test.ts +15 -17
  89. package/src/core/datasets/data-source-connections.ts +8 -11
  90. package/src/core/datasets/state.ts +7 -12
  91. package/src/core/executions/__tests__/freshness.test.ts +8 -3
  92. package/src/core/executions/__tests__/interrupt.test.ts +1 -0
  93. package/src/core/executions/__tests__/select.test.ts +1 -1
  94. package/src/core/executions/atoms.ts +1 -0
  95. package/src/core/executions/freshness.ts +2 -2
  96. package/src/core/islands/bootstrap.ts +0 -2
  97. package/src/core/notebook/replica/__tests__/executions.test.ts +4 -2
  98. package/src/core/notebook/replica/replica.ts +11 -2
  99. package/src/core/notebook/replica/resources/executions.ts +29 -20
  100. package/src/core/session/__tests__/useNotebookSession.hook.test.tsx +192 -1
  101. package/src/core/session/useNotebookSession.tsx +37 -37
  102. package/src/core/storage/__tests__/state.test.ts +6 -9
  103. package/src/core/storage/state.ts +5 -8
  104. package/src/core/variables/state.ts +73 -68
  105. package/src/core/variables/types.ts +2 -2
  106. package/src/core/variables/__tests__/state.test.ts +0 -148
@@ -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:
@@ -7,7 +7,6 @@ import type {
7
7
  NotificationMessageData,
8
8
  } from "../kernel/messages";
9
9
  import { getRequestClient } from "../network/requests";
10
- import type { VariableName } from "../variables/types";
11
10
  import type { DatasetsState } from "./types";
12
11
 
13
12
  function initialState(): DatasetsState {
@@ -75,17 +74,13 @@ const {
75
74
  tables: sortedTables,
76
75
  };
77
76
  },
78
- filterDatasetsFromVariables: (state, variableNames: VariableName[]) => {
79
- const names = new Set(variableNames);
80
- // Filter out tables that come from variables that are not in the list
81
- const tables = state.tables.filter((table) => {
82
- // If there's no variable name, it's not a variable and we should keep it
83
- if (!table.variable_name) {
84
- return true;
85
- }
86
- return names.has(table.variable_name);
87
- });
88
- return { ...state, tables };
77
+ removeDatasetsForVariables: (state, removed: ReadonlySet<string>) => {
78
+ const tables = state.tables.filter(
79
+ (table) =>
80
+ !(table.variable_name && removed.has(table.variable_name)) &&
81
+ !(table.engine && removed.has(table.engine)),
82
+ );
83
+ return tables.length === state.tables.length ? state : { ...state, tables };
89
84
  },
90
85
  toggleTable: (state, tableName: string) => {
91
86
  const expandedTables = new Set(state.expandedTables);
@@ -2,7 +2,7 @@
2
2
 
3
3
  import type * as Protocol from "@marimo-team/client/protocol";
4
4
  import { describe, expect, it } from "vitest";
5
- import type { Execution, Executions, Result } from "@/core/notebook/replica";
5
+ import type { Executions, Result } from "@/core/notebook/replica";
6
6
  import { type CellFreshnessInputs, freshnessOf } from "../freshness";
7
7
  import { cellId, runId } from "@/__tests__/branded";
8
8
 
@@ -90,7 +90,7 @@ function variable(
90
90
  function execution(
91
91
  rec: Protocol.ExecutionOutput,
92
92
  variables: Protocol.Variable[] = [],
93
- ): Execution {
93
+ ) {
94
94
  return {
95
95
  record: rec,
96
96
  output: null,
@@ -106,7 +106,7 @@ function inputs({
106
106
  results = executions.map((e) => e.record),
107
107
  }: {
108
108
  cells: Protocol.CellOutput[];
109
- executions: Execution[];
109
+ executions: ReturnType<typeof execution>[];
110
110
  /** Defaults to the executions on the stream. */
111
111
  results?: Protocol.ExecutionOutput[];
112
112
  }): CellFreshnessInputs {
@@ -114,6 +114,11 @@ function inputs({
114
114
  results: new Map(),
115
115
  scratch: null,
116
116
  runs: new Map(),
117
+ variables: new Map(
118
+ executions.flatMap((e) =>
119
+ e.record.cell_id === null ? [] : [[e.record.cell_id, e.variables]],
120
+ ),
121
+ ),
117
122
  executions: new Map(executions.map((e) => [e.record.id, e])),
118
123
  latest: new Map(
119
124
  executions.flatMap((e) =>
@@ -55,6 +55,7 @@ function setup(runs: Protocol.RunOutput[]) {
55
55
  }));
56
56
  store.set(replica.backendAtom, fakeBackend({ interrupt }));
57
57
  store.set(replica.executionsAtom, {
58
+ variables: new Map(),
58
59
  runs: new Map(runs.map((run) => [run.id, run])),
59
60
  executions: new Map(),
60
61
  latest: new Map(),
@@ -78,7 +78,6 @@ function execution(
78
78
  output: null,
79
79
  outputVersion: 0,
80
80
  items: new Map(),
81
- variables: new Map(),
82
81
  };
83
82
  }
84
83
 
@@ -130,6 +129,7 @@ function inputs({
130
129
  const stream: Executions = {
131
130
  scratch: null,
132
131
  results,
132
+ variables: new Map(),
133
133
  runs: new Map(runs.map((r) => [r.id, r])),
134
134
  executions: new Map(executions.map((e) => [e.record.id, e])),
135
135
  latest: new Map(
@@ -35,6 +35,7 @@ import { shown } from "@/core/notebook/replica";
35
35
  type Store = ReturnType<typeof createStore>;
36
36
 
37
37
  const NO_EXECUTIONS: Executions = {
38
+ variables: new Map(),
38
39
  runs: new Map(),
39
40
  executions: new Map(),
40
41
  latest: new Map(),
@@ -53,8 +53,8 @@ function boundVariables(
53
53
  executions: Executions,
54
54
  ): ReadonlyMap<string, Protocol.Variable[]> {
55
55
  const byName = new Map<string, Protocol.Variable[]>();
56
- for (const execution of executions.executions.values()) {
57
- for (const variable of execution.variables.values()) {
56
+ for (const bindings of executions.variables.values()) {
57
+ for (const variable of bindings.values()) {
58
58
  const bound = byName.get(variable.name);
59
59
  if (bound === undefined) {
60
60
  byName.set(variable.name, [variable]);
@@ -190,8 +190,6 @@ function handleNotification(
190
190
  case "pdb-output":
191
191
  case "breakpoints":
192
192
  case "active-line":
193
- case "variables":
194
- case "variable-values":
195
193
  case "data-column-preview":
196
194
  case "sql-table-preview":
197
195
  case "sql-table-list-preview":
@@ -77,7 +77,9 @@ describe("executions resource", () => {
77
77
  const done = replay(runCells, start);
78
78
  const e12 = resource(done).executions.get("e12");
79
79
  expect(e12?.record.state.status).toBe("completed");
80
- expect([...e12!.variables.values()].map((v) => v.name)).toEqual(["x"]);
80
+ expect(
81
+ [...resource(done).variables.get(C3)!.values()].map((v) => v.name),
82
+ ).toEqual(["x"]);
81
83
  expect(resource(done).executions.get("e13")?.record.state).toHaveProperty(
82
84
  "depends_on",
83
85
  {
@@ -153,7 +155,7 @@ describe("executions resource", () => {
153
155
  );
154
156
  const e12 = resource(cleared).executions.get("e12")!;
155
157
  expect(ids(e12)).toEqual([]);
156
- expect(e12.variables.size).toBe(0);
158
+ expect(resource(cleared).variables.has(C3)).toBe(false);
157
159
  expect(resource(cleared).latest.get(C3)).toBe("e12");
158
160
  });
159
161
 
@@ -287,12 +287,21 @@ export function createNotebookReplica(
287
287
  return {
288
288
  stream: next,
289
289
  retained: null,
290
- analyzed: analysisView(followed.analyzed, document.current, analysis),
290
+ analyzed: analysisView(
291
+ retained && retained.notebook?.id !== next.notebook?.id
292
+ ? null
293
+ : followed.analyzed,
294
+ document.current,
295
+ analysis,
296
+ ),
291
297
  };
292
298
  }
293
299
  return {
294
300
  stream: next,
295
- analyzed: null,
301
+ analyzed:
302
+ followed.analyzed?.freshness === "current"
303
+ ? { ...followed.analyzed, freshness: "stale" }
304
+ : followed.analyzed,
296
305
  retained: stream.phase === "snapshot" ? retained : stream,
297
306
  };
298
307
  });