@marimo-team/islands 0.23.14-dev38 → 0.23.14-dev43

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.
@@ -9,7 +9,7 @@ import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
9
9
  import { lt as kioskModeAtom, pt as outputIsStale } from "./html-to-image-DLSOS-bE.js";
10
10
  import "./chunk-5FQGJX7Z-BbqSm5gU.js";
11
11
  import { u as createLucideIcon } from "./dist--2Bqjvs0.js";
12
- import { a as DEFAULT_SLIDE_TYPE, c as Slide, ct as PanelGroup, i as DEFAULT_DECK_TRANSITION, lt as PanelResizeHandle, on as EyeOff, s as SlideSidebar, sn as Expand, st as Panel, t as useNotebookCodeAvailable, un as Code } from "./code-visibility-mXuKNkTw.js";
12
+ import { a as DEFAULT_SLIDE_TYPE, c as Slide, ct as PanelGroup, i as DEFAULT_DECK_TRANSITION, lt as PanelResizeHandle, on as EyeOff, s as SlideSidebar, sn as Expand, st as Panel, t as useNotebookCodeAvailable, un as Code } from "./code-visibility-BCkKHNom.js";
13
13
  import { X as useDebouncedCallback } from "./input-BSdZp5Ng.js";
14
14
  import "./toDate-D1Z7ZXWh.js";
15
15
  import "./react-dom-BTJzcVJ9.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.23.14-dev38",
3
+ "version": "0.23.14-dev43",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -23,7 +23,7 @@ import { toast } from "@/components/ui/use-toast";
23
23
  import { useCellData, useCellRuntime } from "@/core/cells/cells";
24
24
  import { CellOutputId } from "@/core/cells/ids";
25
25
  import { isOutputEmpty } from "@/core/cells/outputs";
26
- import { goToDefinitionAtCursorPosition } from "@/core/codemirror/go-to-definition/utils";
26
+ import { goToDefinitionWithLspFallback } from "@/core/codemirror/go-to-definition/utils";
27
27
  import { sendToPanelManager } from "@/core/vscode/vscode-bindings";
28
28
  import { copyImageToClipboard, copyToClipboard } from "@/utils/copy";
29
29
  import { getImageExtension } from "@/utils/filenames";
@@ -170,7 +170,7 @@ export const CellActionsContextMenu = ({
170
170
  // Only suppress focus restoration when we actually navigated;
171
171
  // otherwise let Radix return focus to the trigger cell.
172
172
  suppressCloseAutoFocus.current =
173
- goToDefinitionAtCursorPosition(editorView);
173
+ goToDefinitionWithLspFallback(editorView);
174
174
  }
175
175
  },
176
176
  },
@@ -76,7 +76,7 @@ export const ReadonlyCode = memo(
76
76
  language = "python",
77
77
  ...rest
78
78
  } = props;
79
- const [hideCode, setHideCode] = useState(initiallyHideCode);
79
+ const [hideCode, setHideCode] = useState(!!initiallyHideCode);
80
80
 
81
81
  const extensions = useMemo(
82
82
  () => [
@@ -99,8 +99,8 @@ export const ReadonlyCode = memo(
99
99
  {insertNewCell && <InsertNewCell code={code} />}
100
100
  {showHideCode && (
101
101
  <ToggleCodeButton
102
- hidden={hideCode ?? false}
103
- onClick={() => setHideCode(!hideCode)}
102
+ hidden={hideCode}
103
+ onClick={() => setHideCode((prev) => !prev)}
104
104
  />
105
105
  )}
106
106
  </div>
@@ -128,7 +128,13 @@ const CopyButton = (props: { text: string }) => {
128
128
 
129
129
  return (
130
130
  <Tooltip content="Copy code" usePortal={false}>
131
- <Button onClick={copy} size="xs" className="py-0" variant="secondary">
131
+ <Button
132
+ onClick={copy}
133
+ size="xs"
134
+ className="py-0"
135
+ variant="secondary"
136
+ aria-label="Copy code"
137
+ >
132
138
  <CopyIcon size={14} strokeWidth={1.5} />
133
139
  </Button>
134
140
  </Tooltip>
@@ -143,6 +149,7 @@ const ToggleCodeButton = (props: { hidden: boolean; onClick: () => void }) => {
143
149
  >
144
150
  <Button
145
151
  onClick={props.onClick}
152
+ aria-label={props.hidden ? "Show code" : "Hide code"}
146
153
  size="xs"
147
154
  className="py-0"
148
155
  variant="secondary"
@@ -171,6 +178,7 @@ const InsertNewCell = (props: { code: string }) => {
171
178
  size="xs"
172
179
  className="py-0"
173
180
  variant="secondary"
181
+ aria-label="Add code to notebook"
174
182
  >
175
183
  <PlusIcon size={14} strokeWidth={1.5} />
176
184
  </Button>
@@ -2,13 +2,17 @@
2
2
 
3
3
  import { python } from "@codemirror/lang-python";
4
4
  import { EditorState } from "@codemirror/state";
5
- import { EditorView } from "@codemirror/view";
6
- import { afterEach, describe, expect, test } from "vitest";
5
+ import { EditorView, keymap } from "@codemirror/view";
6
+ import { afterEach, describe, expect, test, vi } from "vitest";
7
7
  import { cellId, variableName } from "@/__tests__/branded";
8
8
  import { initialNotebookState, notebookAtom } from "@/core/cells/cells";
9
9
  import { store } from "@/core/state/jotai";
10
10
  import { variablesAtom } from "@/core/variables/state";
11
- import { goToDefinitionAtCursorPosition } from "../utils";
11
+ import {
12
+ goToDefinitionAtCursorPosition,
13
+ goToDefinitionWithLspFallback,
14
+ requestLspGoToDefinition,
15
+ } from "../utils";
12
16
 
13
17
  async function tick(): Promise<void> {
14
18
  await new Promise((resolve) => requestAnimationFrame(resolve));
@@ -181,3 +185,71 @@ print(mymodule)`;
181
185
  );
182
186
  });
183
187
  });
188
+
189
+ describe("goToDefinitionWithLspFallback", () => {
190
+ test("falls through to LSP when marimo cannot resolve the symbol", () => {
191
+ const lspGoToDefinition = vi.fn(() => true);
192
+ const view = new EditorView({
193
+ state: EditorState.create({
194
+ doc: "parser.add_argument('--foo')",
195
+ selection: { anchor: "parser.add_argument".indexOf("add_argument") },
196
+ extensions: [
197
+ python(),
198
+ keymap.of([{ key: "F12", run: lspGoToDefinition }]),
199
+ ],
200
+ }),
201
+ parent: document.body,
202
+ });
203
+ views.push(view);
204
+
205
+ const result = goToDefinitionWithLspFallback(view);
206
+
207
+ expect(result).toBe(true);
208
+ expect(lspGoToDefinition).toHaveBeenCalledOnce();
209
+ });
210
+
211
+ test("does not invoke LSP when marimo resolves the symbol", async () => {
212
+ const lspGoToDefinition = vi.fn(() => true);
213
+ const code = "a = 10\nprint(a)";
214
+ const view = new EditorView({
215
+ state: EditorState.create({
216
+ doc: code,
217
+ selection: { anchor: code.indexOf("a", 3) },
218
+ extensions: [
219
+ python(),
220
+ keymap.of([{ key: "F12", run: lspGoToDefinition }]),
221
+ ],
222
+ }),
223
+ parent: document.body,
224
+ });
225
+ views.push(view);
226
+
227
+ const result = goToDefinitionWithLspFallback(view);
228
+
229
+ expect(result).toBe(true);
230
+ expect(lspGoToDefinition).not.toHaveBeenCalled();
231
+ await tick();
232
+ expect(view.state.selection.main.head).toBe(0);
233
+ });
234
+
235
+ test("falls through with a modified shortcut like Ctrl-F12", () => {
236
+ const lspGoToDefinition = vi.fn(() => true);
237
+ const view = new EditorView({
238
+ state: EditorState.create({
239
+ doc: "parser.add_argument('--foo')",
240
+ selection: { anchor: "parser.add_argument".indexOf("add_argument") },
241
+ extensions: [
242
+ python(),
243
+ keymap.of([{ key: "Ctrl-F12", run: lspGoToDefinition }]),
244
+ ],
245
+ }),
246
+ parent: document.body,
247
+ });
248
+ views.push(view);
249
+
250
+ const result = requestLspGoToDefinition(view, "Ctrl-F12");
251
+
252
+ expect(result).toBe(true);
253
+ expect(lspGoToDefinition).toHaveBeenCalledOnce();
254
+ });
255
+ });
@@ -1,7 +1,7 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
  import { EditorView } from "@codemirror/view";
3
3
  import { createUnderlinePlugin, underlineField } from "./underline";
4
- import { goToDefinition } from "./utils";
4
+ import { goToDefinitionWithLspFallback } from "./utils";
5
5
 
6
6
  /**
7
7
  * Create a go-to-definition extension.
@@ -9,8 +9,8 @@ import { goToDefinition } from "./utils";
9
9
  export function goToDefinitionBundle() {
10
10
  return [
11
11
  underlineField,
12
- createUnderlinePlugin((view, variableName) => {
13
- goToDefinition(view, variableName);
12
+ createUnderlinePlugin((view) => {
13
+ goToDefinitionWithLspFallback(view);
14
14
  }),
15
15
  EditorView.baseTheme({
16
16
  ".underline": {
@@ -55,12 +55,9 @@ class MetaUnderlineVariablePlugin {
55
55
  private view: EditorView;
56
56
  private commandClickMode: boolean;
57
57
  private hoveredRange: { from: number; to: number; position: number } | null;
58
- private onClick: (view: EditorView, variableName: string) => void;
58
+ private onClick: (view: EditorView) => void;
59
59
 
60
- constructor(
61
- view: EditorView,
62
- onClick: (view: EditorView, variableName: string) => void,
63
- ) {
60
+ constructor(view: EditorView, onClick: (view: EditorView) => void) {
64
61
  this.view = view;
65
62
  this.commandClickMode = false;
66
63
  this.hoveredRange = null;
@@ -191,20 +188,16 @@ class MetaUnderlineVariablePlugin {
191
188
  // If we have a hovered range, go to it
192
189
  private click = (event: MouseEvent) => {
193
190
  if (this.hoveredRange) {
194
- const variableName = this.view.state.doc.sliceString(
195
- this.hoveredRange.from,
196
- this.hoveredRange.to,
197
- );
198
191
  event.preventDefault();
199
192
  event.stopPropagation();
200
- this.onClick(this.view, variableName);
201
- // Move the cursor to the clicked position
193
+ // Move the cursor before resolving so LSP uses the clicked position.
202
194
  this.view.dispatch({
203
195
  selection: {
204
196
  head: this.hoveredRange.position,
205
197
  anchor: this.hoveredRange.position,
206
198
  },
207
199
  });
200
+ this.onClick(this.view);
208
201
  }
209
202
  };
210
203
 
@@ -217,7 +210,5 @@ class MetaUnderlineVariablePlugin {
217
210
  }
218
211
  }
219
212
 
220
- export const createUnderlinePlugin = (
221
- onClick: (view: EditorView, variableName: string) => void,
222
- ) =>
213
+ export const createUnderlinePlugin = (onClick: (view: EditorView) => void) =>
223
214
  ViewPlugin.define((view) => new MetaUnderlineVariablePlugin(view, onClick));
@@ -2,8 +2,14 @@
2
2
 
3
3
  import { closeCompletion } from "@codemirror/autocomplete";
4
4
  import type { EditorState } from "@codemirror/state";
5
- import { closeHoverTooltips, type EditorView } from "@codemirror/view";
5
+ import {
6
+ closeHoverTooltips,
7
+ type EditorView,
8
+ type KeyBinding,
9
+ keymap,
10
+ } from "@codemirror/view";
6
11
  import type { CellId } from "@/core/cells/ids";
12
+ import { hotkeysAtom, platformAtom } from "../../config/config";
7
13
  import { notebookAtom } from "../../cells/cells";
8
14
  import { store } from "../../state/jotai";
9
15
  import { variablesAtom } from "../../variables/state";
@@ -11,6 +17,20 @@ import type { VariableName, Variables } from "../../variables/types";
11
17
  import { getPositionAtWordBounds } from "../completion/hints";
12
18
  import { goToLine, goToVariableDefinition } from "./commands";
13
19
 
20
+ function keymapBindingMatchesHotkey(
21
+ binding: KeyBinding,
22
+ hotkey: string,
23
+ ): boolean {
24
+ const platform = store.get(platformAtom);
25
+ const bindingKey =
26
+ platform === "mac"
27
+ ? (binding.mac ?? binding.key)
28
+ : platform === "windows"
29
+ ? (binding.win ?? binding.key)
30
+ : (binding.linux ?? binding.key);
31
+ return bindingKey === hotkey;
32
+ }
33
+
14
34
  /**
15
35
  * Get the word under the cursor.
16
36
  */
@@ -68,6 +88,34 @@ export function goToDefinitionAtCursorPosition(view: EditorView): boolean {
68
88
  return goToDefinition(view, word, position);
69
89
  }
70
90
 
91
+ /**
92
+ * Invoke the editor's go-to-definition keymap handlers for the configured
93
+ * hotkey. Matches CodeMirror key strings directly (including customized
94
+ * shortcuts like `Ctrl-F12`) instead of synthesizing keyboard events.
95
+ */
96
+ export function requestLspGoToDefinition(
97
+ view: EditorView,
98
+ hotkey = store.get(hotkeysAtom).getHotkey("cell.goToDefinition").key,
99
+ ): boolean {
100
+ for (const binding of view.state.facet(keymap).flat()) {
101
+ if (keymapBindingMatchesHotkey(binding, hotkey) && binding.run?.(view)) {
102
+ return true;
103
+ }
104
+ }
105
+ return false;
106
+ }
107
+
108
+ /**
109
+ * Go to the definition under the cursor, falling back to the language server
110
+ * when marimo cannot resolve the symbol (e.g. external library code).
111
+ */
112
+ export function goToDefinitionWithLspFallback(view: EditorView): boolean {
113
+ if (goToDefinitionAtCursorPosition(view)) {
114
+ return true;
115
+ }
116
+ return requestLspGoToDefinition(view);
117
+ }
118
+
71
119
  /**
72
120
  * Go to the definition of the variable under the cursor.
73
121
  * @param view The editor view at which the command was invoked.