@marimo-team/islands 0.23.14-dev2 → 0.23.14-dev23
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/{ConnectedDataExplorerComponent-Du3_nUzI.js → ConnectedDataExplorerComponent-DXBx_nQg.js} +4 -4
- package/dist/{chat-ui-CsPewo4h.js → chat-ui-CO8WuXGb.js} +3243 -3039
- package/dist/{code-visibility-CRYdBxcA.js → code-visibility-B3ntFQLc.js} +1115 -917
- package/dist/{formats-d6MhLuQ9.js → formats-WsOgyW_K.js} +1 -1
- package/dist/{glide-data-editor-DkzAInWG.js → glide-data-editor-qpmKyAPn.js} +2 -2
- package/dist/{html-to-image-DXwLcQ6l.js → html-to-image-DLSOS-bE.js} +2351 -2282
- package/dist/{input-CbEz_aj_.js → input-BSdZp5Ng.js} +1 -1
- package/dist/main.js +1139 -1071
- package/dist/{mermaid-CJW9vIyO.js → mermaid-D-HYBMEV.js} +2 -2
- package/dist/{process-output-C6_e1pT_.js → process-output-B9ysqk1y.js} +1 -1
- package/dist/{reveal-component-CbqUMhp8.js → reveal-component-C8j14RKU.js} +16 -16
- package/dist/{spec-Bv-XlYiv.js → spec-CnTgI25l.js} +1 -1
- package/dist/{toDate-D-l5s8nn.js → toDate-D1Z7ZXWh.js} +1 -1
- package/dist/{useAsyncData-1Dhzjfwf.js → useAsyncData-BMc8itk2.js} +1 -1
- package/dist/{useDeepCompareMemoize-CDWT3BDz.js → useDeepCompareMemoize-ZwmDBRDY.js} +1 -1
- package/dist/{useLifecycle-AHlswLw-.js → useLifecycle-CxffarYV.js} +1 -1
- package/dist/{useTheme-BrYvK-_A.js → useTheme-yGsGEk82.js} +26 -24
- package/dist/{vega-component-Pk6lyc_a.js → vega-component-BFJTyykA.js} +5 -5
- package/package.json +2 -2
- package/src/components/chat/acp/agent-panel.tsx +35 -1
- package/src/components/chat/chat-panel.tsx +68 -29
- package/src/components/data-table/__tests__/column-explorer.test.tsx +25 -0
- package/src/components/data-table/__tests__/column-visibility-dropdown.test.tsx +60 -3
- package/src/components/data-table/column-explorer-panel/column-explorer.tsx +33 -12
- package/src/components/data-table/column-visibility-dropdown.tsx +15 -0
- package/src/components/editor/actions/useNotebookActions.tsx +2 -2
- package/src/components/editor/chrome/panels/snippets-panel.tsx +5 -2
- package/src/components/editor/chrome/wrapper/__tests__/useOpenAiAssistant.test.ts +36 -0
- package/src/components/editor/chrome/wrapper/footer-items/pyodide-status.tsx +6 -36
- package/src/components/editor/chrome/wrapper/useAiPanel.ts +3 -1
- package/src/components/editor/chrome/wrapper/useOpenAiAssistant.ts +88 -0
- package/src/components/editor/code/readonly-python-code.tsx +16 -2
- package/src/components/editor/errors/__tests__/auto-fix.test.ts +23 -0
- package/src/components/editor/errors/auto-fix.tsx +88 -34
- package/src/components/editor/errors/fix-mode.ts +1 -1
- package/src/components/editor/output/MarimoTracebackOutput.tsx +10 -1
- package/src/components/editor/output/__tests__/traceback.test.tsx +14 -6
- package/src/components/editor/renderers/vertical-layout/vertical-layout.tsx +6 -2
- package/src/components/lifecycle/ProgressiveBoundary.tsx +42 -0
- package/src/components/lifecycle/RuntimeStatusBadge.tsx +59 -0
- package/src/components/lifecycle/__tests__/ProgressiveBoundary.test.tsx +147 -0
- package/src/components/lifecycle/__tests__/RuntimeStatusBadge.test.tsx +72 -0
- package/src/components/slides/slide-cell-view.tsx +7 -6
- package/src/core/ai/config.ts +2 -2
- package/src/core/ai/context/__tests__/registry.test.ts +133 -3
- package/src/core/ai/context/providers/__tests__/datasource.test.ts +3 -1
- package/src/core/ai/context/providers/__tests__/error.test.ts +200 -15
- package/src/core/ai/context/providers/datasource.ts +27 -2
- package/src/core/ai/context/providers/error.ts +226 -36
- package/src/core/ai/context/registry.ts +77 -43
- package/src/core/ai/state.ts +11 -0
- package/src/core/cells/__tests__/readonly-code-display.test.ts +46 -0
- package/src/core/cells/readonly-code-display.ts +35 -0
- package/src/core/codemirror/__tests__/setup.test.ts +33 -1
- package/src/core/codemirror/ai/resources.ts +15 -10
- package/src/core/codemirror/cells/extensions.ts +1 -4
- package/src/core/codemirror/completion/__tests__/signature-hint.test.ts +94 -0
- package/src/core/codemirror/completion/completer.ts +12 -1
- package/src/core/codemirror/completion/signature-hint.ts +68 -0
- package/src/core/codemirror/language/languages/python.ts +10 -4
- package/src/core/codemirror/utils.ts +15 -0
- package/src/core/edit-app.tsx +8 -5
- package/src/core/errors/errors.ts +2 -1
- package/src/core/lifecycle/__tests__/render-policy.test.ts +247 -0
- package/src/core/lifecycle/render-policy.ts +125 -0
- package/src/core/mime.ts +11 -4
- package/src/core/run-app.tsx +27 -23
- package/src/core/runtime/__tests__/adapter.test.ts +160 -0
- package/src/core/runtime/adapter.ts +182 -0
- package/src/core/wasm/PyodideLoader.tsx +20 -62
- package/src/core/wasm/bridge.ts +9 -4
- package/src/core/wasm/state.ts +8 -19
- package/src/core/wasm/store.ts +1 -1
- package/src/hooks/__tests__/useDelayElapsed.test.tsx +55 -0
- package/src/hooks/useDelayElapsed.ts +27 -0
- package/src/core/ai/context/providers/__tests__/__snapshots__/error.test.ts.snap +0 -3
- package/src/core/wasm/__tests__/PyodideLoader.test.ts +0 -72
- package/src/core/wasm/__tests__/state.test.ts +0 -124
- /package/dist/{files → export_demos}/wasm-intro.py +0 -0
|
@@ -9,11 +9,19 @@ import { MultiMap } from "@/utils/multi-map";
|
|
|
9
9
|
import type { TypedString } from "@/utils/typed";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Unique identifier for a context item in the format "type
|
|
12
|
+
* Unique identifier for a context item in the format "type://id"
|
|
13
13
|
* e.g., "variable://my_var", "data://users", "file://config.py"
|
|
14
14
|
*/
|
|
15
15
|
export type ContextLocatorId = TypedString<"ContextLocatorId">;
|
|
16
16
|
|
|
17
|
+
function parseContextType(uri: ContextLocatorId): string | undefined {
|
|
18
|
+
const separator = uri.indexOf("://");
|
|
19
|
+
if (separator === -1) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return uri.slice(0, separator);
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
/**
|
|
18
26
|
* Base interface for context items that can be mentioned in AI prompts
|
|
19
27
|
*/
|
|
@@ -142,40 +150,80 @@ export class AIContextRegistry<T extends AIContextItem> {
|
|
|
142
150
|
);
|
|
143
151
|
}
|
|
144
152
|
|
|
153
|
+
private findProviderForUri(
|
|
154
|
+
uri: ContextLocatorId,
|
|
155
|
+
): AIContextProvider | undefined {
|
|
156
|
+
const type = parseContextType(uri);
|
|
157
|
+
if (!type) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
return [...this.providers].find(
|
|
161
|
+
(provider) =>
|
|
162
|
+
provider.contextType === type &&
|
|
163
|
+
provider.getItems().some((item) => item.uri === uri),
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
145
167
|
/**
|
|
146
|
-
*
|
|
168
|
+
* Resolve only the requested context items, querying each matching provider
|
|
147
169
|
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
170
|
+
resolveItems(contextIds: ContextLocatorId[]): T[] {
|
|
171
|
+
if (contextIds.length === 0) {
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const idsByType = new MultiMap<string, ContextLocatorId>();
|
|
176
|
+
for (const contextId of contextIds) {
|
|
177
|
+
const type = parseContextType(contextId);
|
|
178
|
+
if (type) {
|
|
179
|
+
idsByType.add(type, contextId);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const itemsById = new Map<ContextLocatorId, T>();
|
|
184
|
+
for (const [type, ids] of idsByType.entries()) {
|
|
185
|
+
const providers = [...this.providers].filter(
|
|
186
|
+
(provider) => provider.contextType === type,
|
|
187
|
+
);
|
|
188
|
+
for (const provider of providers) {
|
|
189
|
+
const itemsByUri = new Map<ContextLocatorId, T>(
|
|
190
|
+
provider
|
|
191
|
+
.getItems()
|
|
192
|
+
.map((item) => [item.uri as ContextLocatorId, item as T]),
|
|
193
|
+
);
|
|
194
|
+
for (const id of ids) {
|
|
195
|
+
const item = itemsByUri.get(id);
|
|
196
|
+
if (item) {
|
|
197
|
+
itemsById.set(id, item);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
153
202
|
|
|
203
|
+
// Preserve the order in which the ids were requested, so formatted context
|
|
204
|
+
// matches the order the user mentioned them in the prompt.
|
|
205
|
+
const results: T[] = [];
|
|
154
206
|
for (const contextId of contextIds) {
|
|
155
|
-
const item =
|
|
207
|
+
const item = itemsById.get(contextId);
|
|
156
208
|
if (item) {
|
|
157
|
-
|
|
209
|
+
results.push(item);
|
|
158
210
|
}
|
|
159
211
|
}
|
|
212
|
+
return results;
|
|
213
|
+
}
|
|
160
214
|
|
|
161
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Get context information for mentioned items
|
|
217
|
+
*/
|
|
218
|
+
getContextInfo(contextIds: ContextLocatorId[]): T[] {
|
|
219
|
+
return this.resolveItems(contextIds);
|
|
162
220
|
}
|
|
163
221
|
|
|
164
222
|
/**
|
|
165
223
|
* Format context for AI prompt inclusion
|
|
166
224
|
*/
|
|
167
225
|
formatContextForAI(contextIds: ContextLocatorId[]): string {
|
|
168
|
-
const
|
|
169
|
-
this.getAllItems().map((item) => [item.uri as ContextLocatorId, item]),
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
const contextInfo: T[] = [];
|
|
173
|
-
for (const contextId of contextIds) {
|
|
174
|
-
const item = allItems.get(contextId);
|
|
175
|
-
if (item) {
|
|
176
|
-
contextInfo.push(item);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
226
|
+
const contextInfo = this.resolveItems(contextIds);
|
|
179
227
|
|
|
180
228
|
if (contextInfo.length === 0) {
|
|
181
229
|
return "";
|
|
@@ -183,7 +231,7 @@ export class AIContextRegistry<T extends AIContextItem> {
|
|
|
183
231
|
|
|
184
232
|
return contextInfo
|
|
185
233
|
.map((item) => {
|
|
186
|
-
const provider = this.
|
|
234
|
+
const provider = this.findProviderForUri(item.uri as ContextLocatorId);
|
|
187
235
|
return provider?.formatContext(item) || "";
|
|
188
236
|
})
|
|
189
237
|
.join("\n\n");
|
|
@@ -195,36 +243,22 @@ export class AIContextRegistry<T extends AIContextItem> {
|
|
|
195
243
|
async getAttachmentsForContext(
|
|
196
244
|
contextIds: ContextLocatorId[],
|
|
197
245
|
): Promise<FileUIPart[]> {
|
|
198
|
-
const
|
|
199
|
-
this.getAllItems().map((item) => [item.uri as ContextLocatorId, item]),
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
const contextInfo: T[] = [];
|
|
203
|
-
for (const contextId of contextIds) {
|
|
204
|
-
const item = allItems.get(contextId);
|
|
205
|
-
if (item) {
|
|
206
|
-
contextInfo.push(item);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
246
|
+
const contextInfo = this.resolveItems(contextIds);
|
|
209
247
|
|
|
210
248
|
if (contextInfo.length === 0) {
|
|
211
249
|
return [];
|
|
212
250
|
}
|
|
213
251
|
|
|
214
|
-
|
|
215
|
-
const itemsByProvider = new MultiMap<string, T>();
|
|
252
|
+
const itemsByProvider = new MultiMap<AIContextProvider, T>();
|
|
216
253
|
for (const item of contextInfo) {
|
|
217
|
-
const
|
|
218
|
-
|
|
254
|
+
const provider = this.findProviderForUri(item.uri as ContextLocatorId);
|
|
255
|
+
if (provider) {
|
|
256
|
+
itemsByProvider.add(provider, item);
|
|
257
|
+
}
|
|
219
258
|
}
|
|
220
259
|
|
|
221
|
-
// Collect attachments from all providers
|
|
222
260
|
const attachmentPromises = [...itemsByProvider.entries()].map(
|
|
223
|
-
async ([
|
|
224
|
-
const provider = this.getProvider(providerType);
|
|
225
|
-
if (!provider) {
|
|
226
|
-
return [];
|
|
227
|
-
}
|
|
261
|
+
async ([provider, items]) => {
|
|
228
262
|
try {
|
|
229
263
|
return await provider.getAttachments(items);
|
|
230
264
|
} catch (error) {
|
package/src/core/ai/state.ts
CHANGED
|
@@ -21,6 +21,17 @@ export interface AiCompletionCell {
|
|
|
21
21
|
|
|
22
22
|
export const aiCompletionCellAtom = atom<AiCompletionCell | null>(null);
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* A prompt queued to be delivered to the AI assistant panel.
|
|
26
|
+
* The active panel consumes this on mount/when ready, then clears it.
|
|
27
|
+
*/
|
|
28
|
+
export interface PendingAiPrompt {
|
|
29
|
+
prompt: string;
|
|
30
|
+
submit: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const pendingAiPromptAtom = atom<PendingAiPrompt | null>(null);
|
|
34
|
+
|
|
24
35
|
const INCLUDE_OTHER_CELLS_KEY = "marimo:ai:includeOtherCells";
|
|
25
36
|
export const includeOtherCellsAtom = atomWithStorage<boolean>(
|
|
26
37
|
INCLUDE_OTHER_CELLS_KEY,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { getReadonlyCodeDisplay } from "../readonly-code-display";
|
|
5
|
+
|
|
6
|
+
describe("getReadonlyCodeDisplay", () => {
|
|
7
|
+
it("unwraps SQL cells to their inner query and marks them as sql", () => {
|
|
8
|
+
const result = getReadonlyCodeDisplay(
|
|
9
|
+
'my_table = mo.sql("""SELECT 1 AS id""")',
|
|
10
|
+
);
|
|
11
|
+
expect(result.language).toBe("sql");
|
|
12
|
+
expect(result.code).toBe("SELECT 1 AS id");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("unwraps f-string SQL cells", () => {
|
|
16
|
+
const result = getReadonlyCodeDisplay(
|
|
17
|
+
'my_table = mo.sql(f"""SELECT 1 AS id""")',
|
|
18
|
+
);
|
|
19
|
+
expect(result.language).toBe("sql");
|
|
20
|
+
expect(result.code).toBe("SELECT 1 AS id");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("leaves plain Python cells untouched", () => {
|
|
24
|
+
const code = "x = 1 + 2\nprint(x)";
|
|
25
|
+
const result = getReadonlyCodeDisplay(code);
|
|
26
|
+
expect(result.language).toBe("python");
|
|
27
|
+
expect(result.code).toBe(code);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("unwraps markdown cells to their inner content", () => {
|
|
31
|
+
const result = getReadonlyCodeDisplay('mo.md("""## Heading""")');
|
|
32
|
+
expect(result.language).toBe("markdown");
|
|
33
|
+
expect(result.code).toBe("## Heading");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("treats empty or whitespace-only code as python", () => {
|
|
37
|
+
expect(getReadonlyCodeDisplay("")).toEqual({
|
|
38
|
+
code: "",
|
|
39
|
+
language: "python",
|
|
40
|
+
});
|
|
41
|
+
expect(getReadonlyCodeDisplay(" \n\t ")).toEqual({
|
|
42
|
+
code: " \n\t ",
|
|
43
|
+
language: "python",
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { MarkdownParser, SQLParser } from "@marimo-team/smart-cells";
|
|
4
|
+
import type { LanguageAdapterType } from "@/core/codemirror/language/types";
|
|
5
|
+
|
|
6
|
+
export interface ReadonlyCodeDisplay {
|
|
7
|
+
code: string;
|
|
8
|
+
language: LanguageAdapterType;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const markdownParser = new MarkdownParser();
|
|
12
|
+
const sqlParser = new SQLParser();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Unwrap SQL and markdown cells so read-only views show inner content with the
|
|
16
|
+
* correct syntax highlighting instead of the raw Python wrapper.
|
|
17
|
+
*/
|
|
18
|
+
export function getReadonlyCodeDisplay(code: string): ReadonlyCodeDisplay {
|
|
19
|
+
const trimmed = code.trim();
|
|
20
|
+
if (!trimmed) {
|
|
21
|
+
return { code, language: "python" };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (markdownParser.isSupported(trimmed)) {
|
|
25
|
+
return {
|
|
26
|
+
code: markdownParser.transformIn(trimmed).code,
|
|
27
|
+
language: "markdown",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (sqlParser.isSupported(trimmed)) {
|
|
32
|
+
return { code: sqlParser.transformIn(trimmed).code, language: "sql" };
|
|
33
|
+
}
|
|
34
|
+
return { code, language: "python" };
|
|
35
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
|
|
3
3
|
import { EditorState, type Extension } from "@codemirror/state";
|
|
4
|
-
import { keymap } from "@codemirror/view";
|
|
4
|
+
import { EditorView, keymap } from "@codemirror/view";
|
|
5
5
|
import { describe, expect, test, vi } from "vitest";
|
|
6
6
|
import { cellId } from "@/__tests__/branded";
|
|
7
7
|
import { OverridingHotkeyProvider } from "@/core/hotkeys/hotkeys";
|
|
@@ -163,6 +163,38 @@ test("auto_close_pairs: false removes closeBrackets keymaps", () => {
|
|
|
163
163
|
expect(hasBracketPairHandler(withoutAutoClose)).toBe(false);
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
+
test("go to definition falls through to lower-priority LSP keymap", () => {
|
|
167
|
+
const lspGoToDefinition = vi.fn(() => true);
|
|
168
|
+
const goToDefinitionKey = getOpts().hotkeys.getHotkey(
|
|
169
|
+
"cell.goToDefinition",
|
|
170
|
+
).key;
|
|
171
|
+
|
|
172
|
+
const view = new EditorView({
|
|
173
|
+
state: EditorState.create({
|
|
174
|
+
doc: "parser.add_argument('--foo')",
|
|
175
|
+
selection: { anchor: "parser.".length },
|
|
176
|
+
extensions: [
|
|
177
|
+
...setup(),
|
|
178
|
+
keymap.of([{ key: goToDefinitionKey, run: lspGoToDefinition }]),
|
|
179
|
+
],
|
|
180
|
+
}),
|
|
181
|
+
parent: document.body,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
const event = new KeyboardEvent("keydown", {
|
|
186
|
+
key: goToDefinitionKey,
|
|
187
|
+
bubbles: true,
|
|
188
|
+
cancelable: true,
|
|
189
|
+
});
|
|
190
|
+
view.contentDOM.dispatchEvent(event);
|
|
191
|
+
|
|
192
|
+
expect(lspGoToDefinition).toHaveBeenCalledOnce();
|
|
193
|
+
} finally {
|
|
194
|
+
view.destroy();
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
166
198
|
test("placeholder adds another extension", () => {
|
|
167
199
|
const opts = getOpts();
|
|
168
200
|
const withAI = new PythonLanguageAdapter()
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
resourceDecorations,
|
|
12
12
|
resourceInputFilter,
|
|
13
13
|
resourcesField,
|
|
14
|
+
resourceSync,
|
|
14
15
|
resourceTheme,
|
|
15
16
|
} from "@marimo-team/codemirror-mcp";
|
|
16
17
|
import {
|
|
@@ -38,25 +39,28 @@ const NONE_RESOURCE_FORMAT_COMPLETION = {
|
|
|
38
39
|
},
|
|
39
40
|
};
|
|
40
41
|
|
|
42
|
+
function getRegistryResources(store: JotaiStore): Resource[] {
|
|
43
|
+
const registry = getAIContextRegistry(store);
|
|
44
|
+
const resources = registry.getAllItems();
|
|
45
|
+
if (resources.length === 0) {
|
|
46
|
+
return NONE_RESOURCE;
|
|
47
|
+
}
|
|
48
|
+
return resources;
|
|
49
|
+
}
|
|
50
|
+
|
|
41
51
|
export function resourceExtension(opts: {
|
|
42
52
|
language: Language;
|
|
43
53
|
store: JotaiStore;
|
|
44
54
|
onAddFiles?: (files: File[]) => void;
|
|
45
55
|
}): Extension[] {
|
|
46
56
|
const { language, store, onAddFiles } = opts;
|
|
57
|
+
const getResources = () => getRegistryResources(store);
|
|
47
58
|
|
|
48
59
|
return [
|
|
49
60
|
language.data.of({
|
|
50
61
|
// Resource completion for static resources (variables, tables, etc.)
|
|
51
62
|
autocomplete: resourceCompletion(
|
|
52
|
-
async (): Promise<Resource[]> =>
|
|
53
|
-
const registry = getAIContextRegistry(store);
|
|
54
|
-
const resources = registry.getAllItems();
|
|
55
|
-
if (resources.length === 0) {
|
|
56
|
-
return NONE_RESOURCE;
|
|
57
|
-
}
|
|
58
|
-
return resources;
|
|
59
|
-
},
|
|
63
|
+
async (): Promise<Resource[]> => getResources(),
|
|
60
64
|
(resource) => {
|
|
61
65
|
if (resource.type === NONE_RESOURCE_TYPE) {
|
|
62
66
|
return NONE_RESOURCE_FORMAT_COMPLETION;
|
|
@@ -92,9 +96,10 @@ export function resourceExtension(opts: {
|
|
|
92
96
|
: []),
|
|
93
97
|
resourceDecorations,
|
|
94
98
|
resourceInputFilter,
|
|
99
|
+
// Resolve @-mention chips for programmatic prefills.
|
|
100
|
+
resourceSync(getResources, { logger: Logger }),
|
|
95
101
|
resourcesField.init(() => {
|
|
96
|
-
const
|
|
97
|
-
const resources = registry.getAllItems();
|
|
102
|
+
const resources = getRegistryResources(store);
|
|
98
103
|
return new Map(resources.map((resource) => [resource.uri, resource]));
|
|
99
104
|
}),
|
|
100
105
|
resourceTheme,
|
|
@@ -106,11 +106,8 @@ function cellKeymaps({
|
|
|
106
106
|
keybindings.push(
|
|
107
107
|
{
|
|
108
108
|
key: hotkeys.getHotkey("cell.goToDefinition").key,
|
|
109
|
-
preventDefault: true,
|
|
110
|
-
stopPropagation: true,
|
|
111
109
|
run: (ev) => {
|
|
112
|
-
goToDefinitionAtCursorPosition(ev);
|
|
113
|
-
return true;
|
|
110
|
+
return goToDefinitionAtCursorPosition(ev);
|
|
114
111
|
},
|
|
115
112
|
},
|
|
116
113
|
{
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import { EditorState } from "@codemirror/state";
|
|
4
|
+
import { EditorView, type Tooltip } from "@codemirror/view";
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import {
|
|
7
|
+
asSignatureHint,
|
|
8
|
+
setSignatureHintEffect,
|
|
9
|
+
signatureHintField,
|
|
10
|
+
} from "../signature-hint";
|
|
11
|
+
|
|
12
|
+
function fakeTooltip(pos: number): Tooltip {
|
|
13
|
+
return {
|
|
14
|
+
pos,
|
|
15
|
+
above: true,
|
|
16
|
+
create: () => ({ dom: document.createElement("div") }),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function stateWithHint(doc: string, pos: number): EditorState {
|
|
21
|
+
const state = EditorState.create({
|
|
22
|
+
doc,
|
|
23
|
+
extensions: [signatureHintField],
|
|
24
|
+
});
|
|
25
|
+
return state.update({ effects: setSignatureHintEffect.of(fakeTooltip(pos)) })
|
|
26
|
+
.state;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("signatureHintField", () => {
|
|
30
|
+
it("starts empty", () => {
|
|
31
|
+
const state = EditorState.create({ extensions: [signatureHintField] });
|
|
32
|
+
expect(state.field(signatureHintField)).toBeNull();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("shows a tooltip when the effect is dispatched", () => {
|
|
36
|
+
const state = stateWithHint("plt.plot(", 9);
|
|
37
|
+
expect(state.field(signatureHintField)?.pos).toBe(9);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("clears the tooltip when the effect dispatches null", () => {
|
|
41
|
+
let state = stateWithHint("plt.plot(", 9);
|
|
42
|
+
state = state.update({
|
|
43
|
+
effects: setSignatureHintEffect.of(null),
|
|
44
|
+
}).state;
|
|
45
|
+
expect(state.field(signatureHintField)).toBeNull();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("dismisses the tooltip on a selection-only change", () => {
|
|
49
|
+
let state = stateWithHint("plt.plot(x)", 9);
|
|
50
|
+
state = state.update({ selection: { anchor: 0 } }).state;
|
|
51
|
+
expect(state.field(signatureHintField)).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("keeps and re-anchors the tooltip across edits", () => {
|
|
55
|
+
let state = stateWithHint("plt.plot(", 9);
|
|
56
|
+
// Insert before the tooltip position; it should shift to stay anchored.
|
|
57
|
+
state = state.update({ changes: { from: 0, insert: "xy" } }).state;
|
|
58
|
+
expect(state.field(signatureHintField)?.pos).toBe(11);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("asSignatureHint", () => {
|
|
63
|
+
it("nests the content so descendant styling applies", () => {
|
|
64
|
+
const content = document.createElement("span");
|
|
65
|
+
content.classList.add("mo-cm-tooltip", "docs-documentation");
|
|
66
|
+
const base: Tooltip = {
|
|
67
|
+
pos: 0,
|
|
68
|
+
create: () => ({ dom: content, resize: false }),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const view = new EditorView({ state: EditorState.create({}) });
|
|
72
|
+
const { dom } = asSignatureHint(base).create(view);
|
|
73
|
+
|
|
74
|
+
// Outer wrapper carries the tooltip sizing class...
|
|
75
|
+
expect(dom.classList.contains("mo-cm-tooltip")).toBe(true);
|
|
76
|
+
// ...and the documentation content is a descendant (not the same node),
|
|
77
|
+
// so `.cm-tooltip .docs-documentation` padding/font rules match.
|
|
78
|
+
expect(dom).not.toBe(content);
|
|
79
|
+
expect(dom.querySelector(".docs-documentation")).toBe(content);
|
|
80
|
+
|
|
81
|
+
view.destroy();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("preserves other tooltip fields", () => {
|
|
85
|
+
const base: Tooltip = {
|
|
86
|
+
pos: 5,
|
|
87
|
+
above: true,
|
|
88
|
+
create: () => ({ dom: document.createElement("span"), resize: false }),
|
|
89
|
+
};
|
|
90
|
+
const wrapped = asSignatureHint(base);
|
|
91
|
+
expect(wrapped.pos).toBe(5);
|
|
92
|
+
expect(wrapped.above).toBe(true);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -9,6 +9,7 @@ import { documentationAtom } from "@/core/documentation/state";
|
|
|
9
9
|
import { store } from "@/core/state/jotai";
|
|
10
10
|
import { Logger } from "../../../utils/Logger";
|
|
11
11
|
import { AUTOCOMPLETER, Autocompleter } from "./Autocompleter";
|
|
12
|
+
import { asSignatureHint, setSignatureHintEffect } from "./signature-hint";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Completion source for Python, using Jedi.
|
|
@@ -36,10 +37,12 @@ export const pythonCompletionSource: CompletionSource = async (
|
|
|
36
37
|
cellId: cellId,
|
|
37
38
|
});
|
|
38
39
|
if (!result) {
|
|
40
|
+
context.view?.dispatch({ effects: setSignatureHintEffect.of(null) });
|
|
39
41
|
return null;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
// If it is a tooltip, show it as a
|
|
44
|
+
// If it is a tooltip (e.g. a signature after `(` or `,`), show it as a
|
|
45
|
+
// Tooltip instead of a completion.
|
|
43
46
|
const tooltip = Autocompleter.asHoverTooltip({
|
|
44
47
|
position: context.pos,
|
|
45
48
|
message: result,
|
|
@@ -50,6 +53,14 @@ export const pythonCompletionSource: CompletionSource = async (
|
|
|
50
53
|
documentation: tooltip.html ?? null,
|
|
51
54
|
});
|
|
52
55
|
}
|
|
56
|
+
// Surface the signature as a floating hint near the cursor (the LSP path has
|
|
57
|
+
// its own signature help), and clear any stale hint when we instead have a
|
|
58
|
+
// real completion list.
|
|
59
|
+
context.view?.dispatch({
|
|
60
|
+
effects: setSignatureHintEffect.of(
|
|
61
|
+
tooltip ? asSignatureHint(tooltip) : null,
|
|
62
|
+
),
|
|
63
|
+
});
|
|
53
64
|
if (tooltip) {
|
|
54
65
|
return null;
|
|
55
66
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import { StateEffect, StateField } from "@codemirror/state";
|
|
3
|
+
import { showTooltip, type Tooltip } from "@codemirror/view";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Effect to set (or clear, with `null`) the floating signature hint.
|
|
7
|
+
*/
|
|
8
|
+
export const setSignatureHintEffect = StateEffect.define<Tooltip | null>();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wrap a tooltip so it renders like the completion popup's info box.
|
|
12
|
+
*
|
|
13
|
+
* CodeMirror adds `cm-tooltip` directly to the DOM node returned by `create`,
|
|
14
|
+
* so the documentation content ends up on the same element as `cm-tooltip`.
|
|
15
|
+
* Our styling for padding/font (`.cm-tooltip .docs-documentation`) is a
|
|
16
|
+
* descendant selector, so we nest the content one level deeper to make it
|
|
17
|
+
* apply — mirroring how CodeMirror nests completion info inside its own
|
|
18
|
+
* wrapper. The outer `mo-cm-tooltip` class picks up the shared tooltip sizing.
|
|
19
|
+
*/
|
|
20
|
+
export function asSignatureHint(tooltip: Tooltip): Tooltip {
|
|
21
|
+
return {
|
|
22
|
+
...tooltip,
|
|
23
|
+
create: (view) => {
|
|
24
|
+
const { dom: content, ...rest } = tooltip.create(view);
|
|
25
|
+
const dom = document.createElement("div");
|
|
26
|
+
dom.classList.add("mo-cm-tooltip");
|
|
27
|
+
dom.append(content);
|
|
28
|
+
return { ...rest, dom };
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Holds the floating "signature hint" shown after typing `(` or `,` inside a
|
|
35
|
+
* call on the non-LSP (Jedi) completion path.
|
|
36
|
+
*
|
|
37
|
+
* The LSP path has its own signature help; this fills the gap for users
|
|
38
|
+
* without a language server. The completion source (`pythonCompletionSource`)
|
|
39
|
+
* drives it: it dispatches `setSignatureHintEffect` with the tooltip when the
|
|
40
|
+
* backend returns a signature and with `null` otherwise. The hint is also
|
|
41
|
+
* cleared when the cursor moves via a selection-only change (e.g. clicking
|
|
42
|
+
* away or arrowing out of the call), and kept anchored across edits so it
|
|
43
|
+
* doesn't flicker while a fresh result is in flight.
|
|
44
|
+
*/
|
|
45
|
+
export const signatureHintField = StateField.define<Tooltip | null>({
|
|
46
|
+
create: () => null,
|
|
47
|
+
update(tooltip, tr) {
|
|
48
|
+
for (const effect of tr.effects) {
|
|
49
|
+
if (effect.is(setSignatureHintEffect)) {
|
|
50
|
+
return effect.value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!tooltip) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
// Cursor moved without editing (click / arrow key): dismiss the hint.
|
|
57
|
+
if (tr.selection && !tr.docChanged) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
// Keep the hint anchored across edits; the completion source refreshes or
|
|
61
|
+
// clears it as new results arrive.
|
|
62
|
+
if (tr.docChanged) {
|
|
63
|
+
return { ...tooltip, pos: tr.changes.mapPos(tooltip.pos) };
|
|
64
|
+
}
|
|
65
|
+
return tooltip;
|
|
66
|
+
},
|
|
67
|
+
provide: (field) => showTooltip.from(field),
|
|
68
|
+
});
|
|
@@ -31,6 +31,7 @@ import { Logger } from "@/utils/Logger";
|
|
|
31
31
|
import { once } from "@/utils/once";
|
|
32
32
|
import { cellActionsState } from "../../cells/state";
|
|
33
33
|
import { pythonCompletionSource } from "../../completion/completer";
|
|
34
|
+
import { signatureHintField } from "../../completion/signature-hint";
|
|
34
35
|
import type { PlaceholderType } from "../../config/types";
|
|
35
36
|
import { FederatedLanguageServerClient } from "../../lsp/federated-lsp";
|
|
36
37
|
import { createLspMarkdownRenderer } from "../../lsp/markdown-renderer";
|
|
@@ -376,10 +377,15 @@ export class PythonLanguageAdapter implements LanguageAdapter<{}> {
|
|
|
376
377
|
];
|
|
377
378
|
}
|
|
378
379
|
|
|
379
|
-
return
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
380
|
+
return [
|
|
381
|
+
autocompletion({
|
|
382
|
+
...autocompleteOptions,
|
|
383
|
+
override: [pythonCompletionSource],
|
|
384
|
+
}),
|
|
385
|
+
// The Jedi path has no built-in signature help; show a floating hint
|
|
386
|
+
// fed by `pythonCompletionSource` (the LSP path handles this itself).
|
|
387
|
+
signatureHintField,
|
|
388
|
+
];
|
|
383
389
|
};
|
|
384
390
|
|
|
385
391
|
return [
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { EditorState, Transaction } from "@codemirror/state";
|
|
3
3
|
import type { EditorView, ViewUpdate } from "@codemirror/view";
|
|
4
4
|
import { getCM } from "@replit/codemirror-vim";
|
|
5
|
+
import type { ReactCodeMirrorRef } from "@uiw/react-codemirror";
|
|
5
6
|
|
|
6
7
|
export function isAtStartOfEditor(ev: { state: EditorState }) {
|
|
7
8
|
const main = ev.state.selection.main;
|
|
@@ -37,6 +38,20 @@ export function moveToEndOfEditor(ev: EditorView | undefined) {
|
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
/** We delay the focus and move to end of the editor until React has rendered the prefilled value. */
|
|
42
|
+
export function focusInputAndMoveToEnd(
|
|
43
|
+
ref: React.RefObject<ReactCodeMirrorRef | null>,
|
|
44
|
+
) {
|
|
45
|
+
requestAnimationFrame(() => {
|
|
46
|
+
const view = ref.current?.view;
|
|
47
|
+
if (!view) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
view.focus();
|
|
51
|
+
moveToEndOfEditor(view);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
export function isInVimMode(ev: EditorView): boolean {
|
|
41
56
|
return getCM(ev)?.state.vim != null;
|
|
42
57
|
}
|