@marimo-team/frontend 0.23.7-dev50 → 0.23.7-dev51
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.
- package/dist/assets/{CellStatus-DIS3iCFo.js → CellStatus-DXNmZJpi.js} +1 -1
- package/dist/assets/{JsonOutput-eeHUhz4_.js → JsonOutput-Dxol3ZtH.js} +1 -1
- package/dist/assets/{MarimoErrorOutput-C_s2Utqa.js → MarimoErrorOutput-YGhIA85d.js} +1 -1
- package/dist/assets/{RenderHTML-GX_O9tyW.js → RenderHTML-Dz1OIbOh.js} +1 -1
- package/dist/assets/{add-cell-with-ai-BMODIFpo.js → add-cell-with-ai-hIPYl46r.js} +1 -1
- package/dist/assets/{add-connection-dialog-Dzd39V2c.js → add-connection-dialog-CMR-c9XE.js} +1 -1
- package/dist/assets/{agent-panel-BAN4LsQS.js → agent-panel-DnBAoLsM.js} +1 -1
- package/dist/assets/{ai-model-dropdown-CFx7zgXS.js → ai-model-dropdown-zvokTxf_.js} +1 -1
- package/dist/assets/{app-config-button-XMCeCwhm.js → app-config-button-BjFAqaTN.js} +1 -1
- package/dist/assets/{cell-editor-Cts6KKBo.js → cell-editor-Dak_jwhB.js} +1 -1
- package/dist/assets/{cell-link-DqucEHxF.js → cell-link-pRI-YfIp.js} +1 -1
- package/dist/assets/{cells-CJWUXz1v.js → cells-DbE28H1u.js} +74 -74
- package/dist/assets/{chat-display-D3hLpbGd.js → chat-display-D_nDPZek.js} +1 -1
- package/dist/assets/{chat-panel-y8jUpvvS.js → chat-panel-BktSpl2P.js} +1 -1
- package/dist/assets/{chat-ui-B6oULfnR.js → chat-ui-C0_KcXrv.js} +1 -1
- package/dist/assets/{column-preview-qXG5O_LC.js → column-preview-CNeXQtKn.js} +1 -1
- package/dist/assets/{command-palette-CE-WHL_Z.js → command-palette-CcjZs_TG.js} +1 -1
- package/dist/assets/{common-Dfc8zq5C.js → common-CWRr25jC.js} +1 -1
- package/dist/assets/{components-BxcnsrL3.js → components-Cj3Al1Y6.js} +1 -1
- package/dist/assets/{components-OEABNydc.js → components-DUd0ki0p.js} +1 -1
- package/dist/assets/{datasource-DTg26i09.js → datasource-Prn_GWOB.js} +1 -1
- package/dist/assets/{dependency-graph-panel-DIEzM3vx.js → dependency-graph-panel-DUUCij85.js} +1 -1
- package/dist/assets/{documentation-panel-CL8DLWB8.js → documentation-panel-CB8xalFX.js} +1 -1
- package/dist/assets/{download-DHh51UwN.js → download-DEJbA1IY.js} +1 -1
- package/dist/assets/{edit-page-txENC58E.js → edit-page-C7oPi1s6.js} +3 -3
- package/dist/assets/{error-panel-C1f6E7YQ.js → error-panel-DG6AtqLR.js} +1 -1
- package/dist/assets/{file-explorer-panel-CjpptQL3.js → file-explorer-panel-BaQVOljq.js} +1 -1
- package/dist/assets/{file-icons-BQOxwp7s.js → file-icons-BjTIuMQg.js} +1 -1
- package/dist/assets/{floating-outline-n07aHtSF.js → floating-outline-uy6dAsIe.js} +1 -1
- package/dist/assets/{focus-CmJ1iwZ3.js → focus-0RBjdtZw.js} +1 -1
- package/dist/assets/{form-CHy-k6AI.js → form-DNa2VnwU.js} +1 -1
- package/dist/assets/{home-page-vf_qM8OB.js → home-page-BSuXANlw.js} +1 -1
- package/dist/assets/{hooks-BFV8DhjR.js → hooks-B7pYZHjF.js} +1 -1
- package/dist/assets/{html-to-image-CS4X2edG.js → html-to-image-CIu-0LbU.js} +1 -1
- package/dist/assets/{index-DTnzKdRs.js → index-uDKD04Qe.js} +4 -4
- package/dist/assets/{kiosk-mode-tMe1OphD.js → kiosk-mode-Ch75k65P.js} +1 -1
- package/dist/assets/{layout-BzITvb58.js → layout-DFhJt7oJ.js} +3 -3
- package/dist/assets/{logs-panel-Dxu-x-VS.js → logs-panel-DR-1BC0S.js} +1 -1
- package/dist/assets/{markdown-renderer-C_hNGAKl.js → markdown-renderer-DGqYztXR.js} +1 -1
- package/dist/assets/{name-cell-input-C3bm2h5H.js → name-cell-input-DwfyLq31.js} +1 -1
- package/dist/assets/{outline-panel-YJ_yN1ON.js → outline-panel-CWunrooQ.js} +1 -1
- package/dist/assets/{packages-panel-DEssvZRX.js → packages-panel-BdcXUFQJ.js} +1 -1
- package/dist/assets/{panels-DcLJ_sFr.js → panels-CJ1t18_z.js} +1 -1
- package/dist/assets/{process-output-G4hcUe0V.js → process-output-CS4QGJvL.js} +1 -1
- package/dist/assets/{radio-group-DkplF0z9.js → radio-group-BS2PIEzV.js} +1 -1
- package/dist/assets/{readonly-python-code-CiB7SZvF.js → readonly-python-code-C5JNX2fu.js} +1 -1
- package/dist/assets/{reveal-component-TQNx-CFf.js → reveal-component-PiSHIrbA.js} +1 -1
- package/dist/assets/{run-page-W5ATFp1J.js → run-page-BovrPK0f.js} +1 -1
- package/dist/assets/{scratchpad-panel-B9b6gk7y.js → scratchpad-panel-CAWFveBD.js} +1 -1
- package/dist/assets/{session-panel-Br71eft2.js → session-panel-BR9h5w96.js} +1 -1
- package/dist/assets/{snippets-panel-CU32gjAk.js → snippets-panel-Y2etH9Qg.js} +1 -1
- package/dist/assets/{state-QBvZnVYO.js → state-1SbOXCLX.js} +1 -1
- package/dist/assets/{state-DQ_uHgcD.js → state-Fa6RzVTL.js} +1 -1
- package/dist/assets/{textarea-WSbqzqT1.js → textarea-wgoQLrBS.js} +1 -1
- package/dist/assets/{tracing-CckKQ3eq.js → tracing-C9PZ0Pr1.js} +1 -1
- package/dist/assets/{tracing-panel-ML726M-W.js → tracing-panel-C20Rk6hU.js} +2 -2
- package/dist/assets/{useCellActionButton-BR00pdte.js → useCellActionButton-D_-iAhme.js} +1 -1
- package/dist/assets/{useDeleteCell-C-ffkF5n.js → useDeleteCell-41mvwiyA.js} +1 -1
- package/dist/assets/{useDependencyPanelTab-CjRA2E1n.js → useDependencyPanelTab-ELdrL73c.js} +1 -1
- package/dist/assets/{useNotebookActions-BJ2NNEh5.js → useNotebookActions-CgN-58GN.js} +1 -1
- package/dist/assets/{useRunCells-DX2yB43w.js → useRunCells-CfHlqXY6.js} +1 -1
- package/dist/assets/{useSplitCell-B9NiIxqj.js → useSplitCell-gHtyz873.js} +1 -1
- package/dist/index.html +22 -22
- package/package.json +1 -1
- package/src/core/codemirror/go-to-definition/__tests__/commands.test.ts +152 -0
- package/src/core/codemirror/go-to-definition/__tests__/utils.test.ts +99 -0
- package/src/core/codemirror/go-to-definition/commands.ts +382 -22
- package/src/core/codemirror/go-to-definition/utils.ts +23 -5
package/dist/index.html
CHANGED
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
<marimo-server-token data-token="{{ server_token }}" hidden></marimo-server-token>
|
|
67
67
|
<!-- /TODO -->
|
|
68
68
|
<title>{{ title }}</title>
|
|
69
|
-
<script type="module" crossorigin src="./assets/index-
|
|
69
|
+
<script type="module" crossorigin src="./assets/index-uDKD04Qe.js"></script>
|
|
70
70
|
<link rel="modulepreload" crossorigin href="./assets/preload-helper-DdZsAcJe.js">
|
|
71
71
|
<link rel="modulepreload" crossorigin href="./assets/chunk-LvLJmgfZ.js">
|
|
72
72
|
<link rel="modulepreload" crossorigin href="./assets/react-Bj1aDYRI.js">
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
<link rel="modulepreload" crossorigin href="./assets/debounce-DhnxH9Rh.js">
|
|
134
134
|
<link rel="modulepreload" crossorigin href="./assets/database-zap-kIkTfzTX.js">
|
|
135
135
|
<link rel="modulepreload" crossorigin href="./assets/main-B0OX4z33.js">
|
|
136
|
-
<link rel="modulepreload" crossorigin href="./assets/cells-
|
|
136
|
+
<link rel="modulepreload" crossorigin href="./assets/cells-DbE28H1u.js">
|
|
137
137
|
<link rel="modulepreload" crossorigin href="./assets/ErrorBoundary-DyYDV0HI.js">
|
|
138
138
|
<link rel="modulepreload" crossorigin href="./assets/kbd-BJB2rf7K.js">
|
|
139
139
|
<link rel="modulepreload" crossorigin href="./assets/useInstallPackage-hKfTes-m.js">
|
|
@@ -147,34 +147,34 @@
|
|
|
147
147
|
<link rel="modulepreload" crossorigin href="./assets/usePress-jH2RfcUG.js">
|
|
148
148
|
<link rel="modulepreload" crossorigin href="./assets/input-CVE-gIjt.js">
|
|
149
149
|
<link rel="modulepreload" crossorigin href="./assets/ImperativeModal-DEC1mXgV.js">
|
|
150
|
-
<link rel="modulepreload" crossorigin href="./assets/cell-link-
|
|
150
|
+
<link rel="modulepreload" crossorigin href="./assets/cell-link-pRI-YfIp.js">
|
|
151
151
|
<link rel="modulepreload" crossorigin href="./assets/multi-map-CUuNtzHt.js">
|
|
152
152
|
<link rel="modulepreload" crossorigin href="./assets/alert-DrHguQlr.js">
|
|
153
153
|
<link rel="modulepreload" crossorigin href="./assets/chevron-right-CG5QYXYk.js">
|
|
154
154
|
<link rel="modulepreload" crossorigin href="./assets/dropdown-menu-CR7cnzLX.js">
|
|
155
155
|
<link rel="modulepreload" crossorigin href="./assets/links-B8WzCnbo.js">
|
|
156
|
-
<link rel="modulepreload" crossorigin href="./assets/useRunCells-
|
|
156
|
+
<link rel="modulepreload" crossorigin href="./assets/useRunCells-CfHlqXY6.js">
|
|
157
157
|
<link rel="modulepreload" crossorigin href="./assets/copy-Ch48HVPK.js">
|
|
158
158
|
<link rel="modulepreload" crossorigin href="./assets/copy-BwrPA9zQ.js">
|
|
159
159
|
<link rel="modulepreload" crossorigin href="./assets/copy-icon-BdZPgXgo.js">
|
|
160
|
-
<link rel="modulepreload" crossorigin href="./assets/RenderHTML-
|
|
161
|
-
<link rel="modulepreload" crossorigin href="./assets/datasource-
|
|
162
|
-
<link rel="modulepreload" crossorigin href="./assets/state-
|
|
160
|
+
<link rel="modulepreload" crossorigin href="./assets/RenderHTML-Dz1OIbOh.js">
|
|
161
|
+
<link rel="modulepreload" crossorigin href="./assets/datasource-Prn_GWOB.js">
|
|
162
|
+
<link rel="modulepreload" crossorigin href="./assets/state-1SbOXCLX.js">
|
|
163
163
|
<link rel="modulepreload" crossorigin href="./assets/package-B8oXOUM-.js">
|
|
164
164
|
<link rel="modulepreload" crossorigin href="./assets/sparkles-CC9Bko6a.js">
|
|
165
|
-
<link rel="modulepreload" crossorigin href="./assets/MarimoErrorOutput-
|
|
165
|
+
<link rel="modulepreload" crossorigin href="./assets/MarimoErrorOutput-YGhIA85d.js">
|
|
166
166
|
<link rel="modulepreload" crossorigin href="./assets/spinner-UuZAUjoP.js">
|
|
167
|
-
<link rel="modulepreload" crossorigin href="./assets/html-to-image-
|
|
168
|
-
<link rel="modulepreload" crossorigin href="./assets/focus-
|
|
167
|
+
<link rel="modulepreload" crossorigin href="./assets/html-to-image-CIu-0LbU.js">
|
|
168
|
+
<link rel="modulepreload" crossorigin href="./assets/focus-0RBjdtZw.js">
|
|
169
169
|
<link rel="modulepreload" crossorigin href="./assets/useAsyncData-C5i0IRVM.js">
|
|
170
170
|
<link rel="modulepreload" crossorigin href="./assets/LazyAnyLanguageCodeMirror-B2pl_WA3.js">
|
|
171
171
|
<link rel="modulepreload" crossorigin href="./assets/micromark-factory-space-P--XWZhg.js">
|
|
172
172
|
<link rel="modulepreload" crossorigin href="./assets/chunk-5FQGJX7Z-DILIU9Rm.js">
|
|
173
|
-
<link rel="modulepreload" crossorigin href="./assets/markdown-renderer-
|
|
173
|
+
<link rel="modulepreload" crossorigin href="./assets/markdown-renderer-DGqYztXR.js">
|
|
174
174
|
<link rel="modulepreload" crossorigin href="./assets/command-2NPJCYDa.js">
|
|
175
175
|
<link rel="modulepreload" crossorigin href="./assets/popover-Bz_0Vkyf.js">
|
|
176
176
|
<link rel="modulepreload" crossorigin href="./assets/errors-iwK4b4VF.js">
|
|
177
|
-
<link rel="modulepreload" crossorigin href="./assets/download-
|
|
177
|
+
<link rel="modulepreload" crossorigin href="./assets/download-DEJbA1IY.js">
|
|
178
178
|
<link rel="modulepreload" crossorigin href="./assets/table-DUSsaCYD.js">
|
|
179
179
|
<link rel="modulepreload" crossorigin href="./assets/useIframeCapabilities-DPVTppnD.js">
|
|
180
180
|
<link rel="modulepreload" crossorigin href="./assets/error-banner-CLO6LFll.js">
|
|
@@ -193,27 +193,27 @@
|
|
|
193
193
|
<link rel="modulepreload" crossorigin href="./assets/message-circle-1YLdnr8A.js">
|
|
194
194
|
<link rel="modulepreload" crossorigin href="./assets/trash-2-BJLYnZpG.js">
|
|
195
195
|
<link rel="modulepreload" crossorigin href="./assets/react-resizable-panels.browser.esm-CgWOEYeG.js">
|
|
196
|
-
<link rel="modulepreload" crossorigin href="./assets/JsonOutput-
|
|
196
|
+
<link rel="modulepreload" crossorigin href="./assets/JsonOutput-Dxol3ZtH.js">
|
|
197
197
|
<link rel="modulepreload" crossorigin href="./assets/chart-no-axes-column-nqk474t8.js">
|
|
198
198
|
<link rel="modulepreload" crossorigin href="./assets/square-function-blYaQso8.js">
|
|
199
199
|
<link rel="modulepreload" crossorigin href="./assets/spec-D1ptWKg6.js">
|
|
200
200
|
<link rel="modulepreload" crossorigin href="./assets/ellipsis-vertical-CkwWkOQL.js">
|
|
201
201
|
<link rel="modulepreload" crossorigin href="./assets/refresh-cw-a_9k9BK7.js">
|
|
202
202
|
<link rel="modulepreload" crossorigin href="./assets/tree-actions-D9i3o3Zk.js">
|
|
203
|
-
<link rel="modulepreload" crossorigin href="./assets/components-
|
|
204
|
-
<link rel="modulepreload" crossorigin href="./assets/column-preview-
|
|
203
|
+
<link rel="modulepreload" crossorigin href="./assets/components-Cj3Al1Y6.js">
|
|
204
|
+
<link rel="modulepreload" crossorigin href="./assets/column-preview-CNeXQtKn.js">
|
|
205
205
|
<link rel="modulepreload" crossorigin href="./assets/icons-Ol38nIbL.js">
|
|
206
|
-
<link rel="modulepreload" crossorigin href="./assets/radio-group-
|
|
207
|
-
<link rel="modulepreload" crossorigin href="./assets/floating-outline-
|
|
206
|
+
<link rel="modulepreload" crossorigin href="./assets/radio-group-BS2PIEzV.js">
|
|
207
|
+
<link rel="modulepreload" crossorigin href="./assets/floating-outline-uy6dAsIe.js">
|
|
208
208
|
<link rel="modulepreload" crossorigin href="./assets/objectWithoutPropertiesLoose-DoKw85w0.js">
|
|
209
209
|
<link rel="modulepreload" crossorigin href="./assets/esm-DLYpPRvw.js">
|
|
210
210
|
<link rel="modulepreload" crossorigin href="./assets/eye-off-BT-KOYV5.js">
|
|
211
211
|
<link rel="modulepreload" crossorigin href="./assets/plus-CxkHs8QM.js">
|
|
212
|
-
<link rel="modulepreload" crossorigin href="./assets/readonly-python-code-
|
|
212
|
+
<link rel="modulepreload" crossorigin href="./assets/readonly-python-code-C5JNX2fu.js">
|
|
213
213
|
<link rel="modulepreload" crossorigin href="./assets/file-headphone-B3fuktN0.js">
|
|
214
214
|
<link rel="modulepreload" crossorigin href="./assets/file-HTLbeC2b.js">
|
|
215
215
|
<link rel="modulepreload" crossorigin href="./assets/image-BIibSXT6.js">
|
|
216
|
-
<link rel="modulepreload" crossorigin href="./assets/file-icons-
|
|
216
|
+
<link rel="modulepreload" crossorigin href="./assets/file-icons-BjTIuMQg.js">
|
|
217
217
|
<link rel="modulepreload" crossorigin href="./assets/switch-CTn-kJzM.js">
|
|
218
218
|
<link rel="modulepreload" crossorigin href="./assets/events-CBm-hwqS.js">
|
|
219
219
|
<link rel="modulepreload" crossorigin href="./assets/globals-DI5QlXvl.js">
|
|
@@ -222,11 +222,11 @@
|
|
|
222
222
|
<link rel="modulepreload" crossorigin href="./assets/memoize-Tp7rARFe.js">
|
|
223
223
|
<link rel="modulepreload" crossorigin href="./assets/get-C-qh_et5.js">
|
|
224
224
|
<link rel="modulepreload" crossorigin href="./assets/_baseSet-CxV9N1bc.js">
|
|
225
|
-
<link rel="modulepreload" crossorigin href="./assets/state-
|
|
225
|
+
<link rel="modulepreload" crossorigin href="./assets/state-Fa6RzVTL.js">
|
|
226
226
|
<link rel="modulepreload" crossorigin href="./assets/label-xHqFtfdz.js">
|
|
227
|
-
<link rel="modulepreload" crossorigin href="./assets/textarea-
|
|
227
|
+
<link rel="modulepreload" crossorigin href="./assets/textarea-wgoQLrBS.js">
|
|
228
228
|
<link rel="modulepreload" crossorigin href="./assets/refresh-ccw-DLc784Sj.js">
|
|
229
|
-
<link rel="modulepreload" crossorigin href="./assets/form-
|
|
229
|
+
<link rel="modulepreload" crossorigin href="./assets/form-DNa2VnwU.js">
|
|
230
230
|
<link rel="modulepreload" crossorigin href="./assets/renderShortcut-D7FYCtYQ.js">
|
|
231
231
|
<link rel="modulepreload" crossorigin href="./assets/field-CQGpbXj3.js">
|
|
232
232
|
<link rel="modulepreload" crossorigin href="./assets/RSPContexts-Bk1r00gJ.js">
|
package/package.json
CHANGED
|
@@ -101,6 +101,158 @@ print(x)`);
|
|
|
101
101
|
`);
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
+
test("selects the nearest in-scope local definition", async () => {
|
|
105
|
+
const code = `\
|
|
106
|
+
a = 10
|
|
107
|
+
|
|
108
|
+
def my_func():
|
|
109
|
+
a = 20
|
|
110
|
+
print(a)`;
|
|
111
|
+
view = createEditor(code);
|
|
112
|
+
const result = goToVariableDefinition(view, "a", code.lastIndexOf("a"));
|
|
113
|
+
|
|
114
|
+
expect(result).toBe(true);
|
|
115
|
+
await tick();
|
|
116
|
+
expect(renderEditorView(view)).toMatchInlineSnapshot(`
|
|
117
|
+
"
|
|
118
|
+
a = 10
|
|
119
|
+
|
|
120
|
+
def my_func():
|
|
121
|
+
a = 20
|
|
122
|
+
^
|
|
123
|
+
print(a)
|
|
124
|
+
"
|
|
125
|
+
`);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("selects the nearest in-scope parameter definition", async () => {
|
|
129
|
+
const code = `\
|
|
130
|
+
a = 10
|
|
131
|
+
|
|
132
|
+
def my_func(a):
|
|
133
|
+
print(a)`;
|
|
134
|
+
view = createEditor(code);
|
|
135
|
+
const result = goToVariableDefinition(view, "a", code.lastIndexOf("a"));
|
|
136
|
+
|
|
137
|
+
expect(result).toBe(true);
|
|
138
|
+
await tick();
|
|
139
|
+
expect(renderEditorView(view)).toMatchInlineSnapshot(`
|
|
140
|
+
"
|
|
141
|
+
a = 10
|
|
142
|
+
|
|
143
|
+
def my_func(a):
|
|
144
|
+
^
|
|
145
|
+
print(a)
|
|
146
|
+
"
|
|
147
|
+
`);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("selects the comprehension target inside a set comprehension", async () => {
|
|
151
|
+
const code = `\
|
|
152
|
+
x = 100
|
|
153
|
+
s = {x for x in range(10)}`;
|
|
154
|
+
view = createEditor(code);
|
|
155
|
+
// Go-to-definition on the `x` before `for` (the expression part of the
|
|
156
|
+
// comprehension).
|
|
157
|
+
const usagePosition = code.indexOf("{x") + 1;
|
|
158
|
+
const result = goToVariableDefinition(view, "x", usagePosition);
|
|
159
|
+
|
|
160
|
+
expect(result).toBe(true);
|
|
161
|
+
await tick();
|
|
162
|
+
// Should jump to the comprehension target `x` (after `for`), not the
|
|
163
|
+
// outer `x = 100`. The Lezer Python grammar emits
|
|
164
|
+
// `SetComprehensionExpression`, and we now correctly match it in
|
|
165
|
+
// SCOPE_CREATING_NODES, so the comprehension creates a scope and the
|
|
166
|
+
// for-target is collected correctly.
|
|
167
|
+
expect(renderEditorView(view)).toMatchInlineSnapshot(`
|
|
168
|
+
"
|
|
169
|
+
x = 100
|
|
170
|
+
s = {x for x in range(10)}
|
|
171
|
+
^
|
|
172
|
+
"
|
|
173
|
+
`);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("selects the comprehension target inside a dict comprehension", async () => {
|
|
177
|
+
const code = `\
|
|
178
|
+
x = 100
|
|
179
|
+
d = {x: x for x in range(10)}`;
|
|
180
|
+
view = createEditor(code);
|
|
181
|
+
const usagePosition = code.indexOf("{x") + 1;
|
|
182
|
+
const result = goToVariableDefinition(view, "x", usagePosition);
|
|
183
|
+
|
|
184
|
+
expect(result).toBe(true);
|
|
185
|
+
await tick();
|
|
186
|
+
// Positive control: `DictionaryComprehensionExpression` matches the grammar
|
|
187
|
+
// and is in SCOPE_CREATING_NODES, so this should jump to the comprehension
|
|
188
|
+
// target `x` (after `for`).
|
|
189
|
+
expect(renderEditorView(view)).toMatchInlineSnapshot(`
|
|
190
|
+
"
|
|
191
|
+
x = 100
|
|
192
|
+
d = {x: x for x in range(10)}
|
|
193
|
+
^
|
|
194
|
+
"
|
|
195
|
+
`);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("skips enclosing class scope when resolving from inside a method", async () => {
|
|
199
|
+
const code = `\
|
|
200
|
+
x = 100
|
|
201
|
+
class Foo:
|
|
202
|
+
x = 10
|
|
203
|
+
def method(self):
|
|
204
|
+
return x`;
|
|
205
|
+
view = createEditor(code);
|
|
206
|
+
// Go-to-definition on the `x` inside `return x`.
|
|
207
|
+
const usagePosition = code.lastIndexOf("x");
|
|
208
|
+
const result = goToVariableDefinition(view, "x", usagePosition);
|
|
209
|
+
|
|
210
|
+
expect(result).toBe(true);
|
|
211
|
+
await tick();
|
|
212
|
+
// Should jump to `x = 100` at module scope. In Python, methods do NOT see
|
|
213
|
+
// their enclosing class body's names — class scopes are skipped in LEGB
|
|
214
|
+
// lookup once a function boundary has been crossed. We now correctly skip
|
|
215
|
+
// ClassDefinition in getScopeChain once a function boundary is crossed.
|
|
216
|
+
expect(renderEditorView(view)).toMatchInlineSnapshot(`
|
|
217
|
+
"
|
|
218
|
+
x = 100
|
|
219
|
+
^
|
|
220
|
+
class Foo:
|
|
221
|
+
x = 10
|
|
222
|
+
def method(self):
|
|
223
|
+
return x
|
|
224
|
+
"
|
|
225
|
+
`);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("resolves a global forward-reference from inside a function", async () => {
|
|
229
|
+
const code = `\
|
|
230
|
+
def foo():
|
|
231
|
+
return a
|
|
232
|
+
|
|
233
|
+
a = 10`;
|
|
234
|
+
view = createEditor(code);
|
|
235
|
+
// Go-to-definition on the `a` inside `return a`.
|
|
236
|
+
const usagePosition = code.indexOf("return a") + "return ".length;
|
|
237
|
+
const result = goToVariableDefinition(view, "a", usagePosition);
|
|
238
|
+
|
|
239
|
+
expect(result).toBe(true);
|
|
240
|
+
await tick();
|
|
241
|
+
// Should jump to `a = 10` at the bottom. Python allows forward references
|
|
242
|
+
// from within nested functions to module-level names. We now correctly omit
|
|
243
|
+
// "global" from POSITION_SENSITIVE_SCOPES, allowing forward references to
|
|
244
|
+
// global-level definitions declared after the usage position.
|
|
245
|
+
expect(renderEditorView(view)).toMatchInlineSnapshot(`
|
|
246
|
+
"
|
|
247
|
+
def foo():
|
|
248
|
+
return a
|
|
249
|
+
|
|
250
|
+
a = 10
|
|
251
|
+
^
|
|
252
|
+
"
|
|
253
|
+
`);
|
|
254
|
+
});
|
|
255
|
+
|
|
104
256
|
test("selects outer-scope function declaration", async () => {
|
|
105
257
|
view = createEditor(`\
|
|
106
258
|
def x():
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { python } from "@codemirror/lang-python";
|
|
4
|
+
import { EditorState } from "@codemirror/state";
|
|
5
|
+
import { EditorView } from "@codemirror/view";
|
|
6
|
+
import { afterEach, describe, expect, test } from "vitest";
|
|
7
|
+
import { cellId, variableName } from "@/__tests__/branded";
|
|
8
|
+
import { initialNotebookState, notebookAtom } from "@/core/cells/cells";
|
|
9
|
+
import { store } from "@/core/state/jotai";
|
|
10
|
+
import { variablesAtom } from "@/core/variables/state";
|
|
11
|
+
import { goToDefinitionAtCursorPosition } from "../utils";
|
|
12
|
+
|
|
13
|
+
async function tick(): Promise<void> {
|
|
14
|
+
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function createEditor(content: string, selection: number) {
|
|
18
|
+
const state = EditorState.create({
|
|
19
|
+
doc: content,
|
|
20
|
+
selection: { anchor: selection },
|
|
21
|
+
extensions: [python()],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return new EditorView({
|
|
25
|
+
state,
|
|
26
|
+
parent: document.body,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const views: EditorView[] = [];
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
for (const view of views.splice(0)) {
|
|
34
|
+
view.destroy();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
store.set(notebookAtom, initialNotebookState());
|
|
38
|
+
store.set(variablesAtom, {});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("goToDefinitionAtCursorPosition", () => {
|
|
42
|
+
test("prefers the current-cell local definition over a reactive global", async () => {
|
|
43
|
+
const globalCell = cellId("global-cell");
|
|
44
|
+
const localCell = cellId("local-cell");
|
|
45
|
+
const globalCode = `\
|
|
46
|
+
a = 10
|
|
47
|
+
print(a)`;
|
|
48
|
+
const localCode = `\
|
|
49
|
+
def test():
|
|
50
|
+
a = 20
|
|
51
|
+
print(a)`;
|
|
52
|
+
|
|
53
|
+
const globalView = createEditor(globalCode, globalCode.length);
|
|
54
|
+
const localView = createEditor(localCode, localCode.lastIndexOf("a"));
|
|
55
|
+
views.push(globalView, localView);
|
|
56
|
+
|
|
57
|
+
const notebook = initialNotebookState();
|
|
58
|
+
notebook.cellHandles[globalCell] = {
|
|
59
|
+
current: { editorView: globalView, editorViewOrNull: globalView },
|
|
60
|
+
};
|
|
61
|
+
notebook.cellHandles[localCell] = {
|
|
62
|
+
current: { editorView: localView, editorViewOrNull: localView },
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
store.set(notebookAtom, notebook);
|
|
66
|
+
store.set(variablesAtom, {
|
|
67
|
+
[variableName("a")]: {
|
|
68
|
+
dataType: "int",
|
|
69
|
+
declaredBy: [globalCell],
|
|
70
|
+
name: variableName("a"),
|
|
71
|
+
usedBy: [localCell],
|
|
72
|
+
value: "10",
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const result = goToDefinitionAtCursorPosition(localView);
|
|
77
|
+
|
|
78
|
+
expect(result).toBe(true);
|
|
79
|
+
await tick();
|
|
80
|
+
expect(localView.state.selection.main.head).toBe(
|
|
81
|
+
localCode.indexOf("a = 20"),
|
|
82
|
+
);
|
|
83
|
+
expect(globalView.state.selection.main.head).toBe(globalCode.length);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("keeps private variables within the current cell", async () => {
|
|
87
|
+
const code = `\
|
|
88
|
+
_x = 10
|
|
89
|
+
output = _x + 10`;
|
|
90
|
+
const view = createEditor(code, code.lastIndexOf("_x"));
|
|
91
|
+
views.push(view);
|
|
92
|
+
|
|
93
|
+
const result = goToDefinitionAtCursorPosition(view);
|
|
94
|
+
|
|
95
|
+
expect(result).toBe(true);
|
|
96
|
+
await tick();
|
|
97
|
+
expect(view.state.selection.main.head).toBe(code.indexOf("_x = 10"));
|
|
98
|
+
});
|
|
99
|
+
});
|