@marimo-team/islands 0.25.2-dev99 → 0.25.3-dev10
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-BZmqc_F0.js → ConnectedDataExplorerComponent-CNMliVzw.js} +15 -15
- package/dist/{ErrorBoundary-CXkr_IcB.js → ErrorBoundary-BsqSMK9Y.js} +12 -12
- package/dist/{ImageComparisonComponent-Cpfz30OZ.js → ImageComparisonComponent-uU8FSKZE.js} +3 -3
- package/dist/{Plot-CTyjbQDT.js → Plot-DdYOe1UK.js} +2 -2
- package/dist/{abnfDiagram-VCTEODGH-C_Lmaa2j.js → abnfDiagram-VCTEODGH-D-Ez91gV.js} +3 -3
- package/dist/{any-language-editor-BFzqhOBR.js → any-language-editor-DZ_YTVus.js} +7 -7
- package/dist/{architectureDiagram-5GKGNRK7-BKMataHB.js → architectureDiagram-5GKGNRK7-CTpcNtO8.js} +5 -5
- package/dist/assets/__vite-browser-external-BXYkiFsk.js +1 -0
- package/dist/assets/worker-HPY9fbhz.js +114 -0
- package/dist/{blockDiagram-I7D4REHJ-BeHOjyDk.js → blockDiagram-I7D4REHJ-Cg25UrxT.js} +9 -9
- package/dist/{button-BtsM2UqM.js → button-CvjkwdSk.js} +5 -5
- package/dist/{c4Diagram-7LVT6UL2-Bao10t_O.js → c4Diagram-7LVT6UL2-BxFgrnNV.js} +7 -7
- package/dist/{capabilities-A5jrzjCJ.js → capabilities-CQ5IjhzL.js} +1 -1
- package/dist/{channel-BxCkvUgE.js → channel-CPObtJXj.js} +1 -1
- package/dist/{chat-ui-CwOWzoSO.js → chat-ui-0lKdOoQ3.js} +1588 -1396
- package/dist/{check-CNP79M3A.js → check-EDwSwP89.js} +1 -1
- package/dist/{chunk-4HAMMTFA-CH7Gpamd.js → chunk-4HAMMTFA-D4eFPyFh.js} +5 -5
- package/dist/{chunk-75Z2AOVW-AI7CvgKn.js → chunk-75Z2AOVW-D7gxIs2Q.js} +1 -1
- package/dist/{chunk-DU6HZSFF-BSvuTkX4.js → chunk-DU6HZSFF-BwiyaNpg.js} +1 -1
- package/dist/{chunk-F27PBJKO-CLshwT9T.js → chunk-F27PBJKO-ufseIn5y.js} +1 -1
- package/dist/{chunk-GMAD6QVW-wnHcn-lH.js → chunk-GMAD6QVW-BhaJx0X3.js} +3 -3
- package/dist/{chunk-GVQU2GXP-7O2p8hut.js → chunk-GVQU2GXP-Cwbt-lF0.js} +2 -2
- package/dist/{chunk-IMKFNOWR-Bu0Vh_Yi.js → chunk-IMKFNOWR-DGxi-zeo.js} +5 -5
- package/dist/{chunk-L3NEJ4N5-B9_Alrxb.js → chunk-L3NEJ4N5-n-zgIVSy.js} +5 -5
- package/dist/{chunk-OSK3NFVY-PeQPH2fD.js → chunk-OSK3NFVY-DXa-Cxbn.js} +6 -6
- package/dist/{chunk-P2QGCYS3-D9twiFuU.js → chunk-P2QGCYS3-B_Zd3-X0.js} +1 -1
- package/dist/{chunk-POPQ4Y6H-BUiNs18s.js → chunk-POPQ4Y6H-hYOXbYH_.js} +1 -1
- package/dist/{chunk-PWAF6VOD-D8S9NPCy.js → chunk-PWAF6VOD-CQw5qATZ.js} +1 -1
- package/dist/{chunk-SHT3W25Y-B2dyNZ31.js → chunk-SHT3W25Y-CV9J3rAB.js} +7 -7
- package/dist/{chunk-SVP7TREG-D7UPvB10.js → chunk-SVP7TREG-BL-9Fqgg.js} +2 -2
- package/dist/{chunk-TICWLB2K-BNaGoadd.js → chunk-TICWLB2K-Cu_XMjDM.js} +5 -5
- package/dist/{chunk-YOKDWASO-DrWbKnxA.js → chunk-YOKDWASO-DPZk8vhS.js} +6 -6
- package/dist/classDiagram-ZZMXUADV-BXXV13Hq.js +30 -0
- package/dist/classDiagram-v2-VYDZK3BY-B7FXJ1Cp.js +30 -0
- package/dist/{code-visibility-pPjYsRTH.js → code-visibility-CXQvUXHT.js} +18 -18
- package/dist/{common-CkvBp0B4.js → common-CuD-CAC-.js} +6128 -7136
- package/dist/{compiler-runtime-Cj8ZWiNS.js → compiler-runtime-CldRdSsv.js} +2 -2
- package/dist/{copy-icon-BY7jgcaV.js → copy-icon-Ft7t9bqz.js} +6 -6
- package/dist/{cynefinDiagram-5FMLGOSQ-CCDn4Z9e.js → cynefinDiagram-5FMLGOSQ-CH96rwba.js} +3 -3
- package/dist/{dagre-GXQ25YYZ-BJiUO_SV.js → dagre-GXQ25YYZ-BD3PmpFY.js} +10 -10
- package/dist/{data-grid-overlay-editor-L6ELxFAh.js → data-grid-overlay-editor-DgeyYmC1.js} +7 -7
- package/dist/{data-grid-types-BucVmDDp.js → data-grid-types-BH_r7g7l.js} +1 -1
- package/dist/{diagram-S7CK7UJ4-BZfxFNRR.js → diagram-S7CK7UJ4-BsSJJldB.js} +4 -4
- package/dist/{diagram-UQ7AKVKN-1xcsiIMg.js → diagram-UQ7AKVKN-muQtNZc4.js} +3 -3
- package/dist/{diagram-VSXAHHWV-DPAWJ9Nw.js → diagram-VSXAHHWV-BJWcVVJY.js} +2 -2
- package/dist/{diagram-VX7I27RA-DmRsnHYY.js → diagram-VX7I27RA-CdhuZAqR.js} +5 -5
- package/dist/{diagram-Z3DM3KII--b49ryKx.js → diagram-Z3DM3KII-BD8mXjOj.js} +3 -3
- package/dist/{dialog-CmExhUDI.js → dialog-CEBFZNyc.js} +6 -6
- package/dist/{dist-CcyKTBTF.js → dist-DpBpA_n1.js} +2 -2
- package/dist/{dropdown-menu-Cz4TdOJh.js → dropdown-menu-CP_qCYHC.js} +139 -139
- package/dist/{ebnfDiagram-PWID7BFC-rSwVyh4y.js → ebnfDiagram-PWID7BFC-BIN1sweE.js} +3 -3
- package/dist/{erDiagram-RLTQ6QDP-Bfd3iAoC.js → erDiagram-RLTQ6QDP-Ctp5cfoN.js} +12 -12
- package/dist/{error-banner-D30nA9nE.js → error-banner-D-WCIiMt.js} +16 -11
- package/dist/{cells-DZi0ioak.js → error-entries-DSvFWT_M.js} +6171 -5075
- package/dist/{esm-DAVrGVKP.js → esm-AMFssoNp.js} +4 -4
- package/dist/{feedback-button-D-pV0Qji.js → feedback-button-DZMj9PF3.js} +119 -120
- package/dist/flowDiagram-HODETNUW-3EfLrlFb.js +16 -0
- package/dist/{formats-DhhbdyAH.js → formats-CeOmU1MU.js} +6 -6
- package/dist/{ganttDiagram-EL5Y4UJY-B4m_YsKa.js → ganttDiagram-EL5Y4UJY-BQT16JSc.js} +2 -2
- package/dist/{gitGraphDiagram-WWUBYQGX-QRBbvWXh.js → gitGraphDiagram-WWUBYQGX-D5nSIzdE.js} +2 -2
- package/dist/{glide-data-editor-D6CfYwdr.js → glide-data-editor-g_L8FLAC.js} +60 -60
- package/dist/{glide-utils-BVJ4fkxX.js → glide-utils-DJyqh0EM.js} +4 -4
- package/dist/{globals-BwK9YGrX.js → globals-CYGlmBXb.js} +3 -3
- package/dist/{highlighted-body-KPVGNVTW-Ad3MKZ18.js → highlighted-body-KPVGNVTW-zwjq21tf.js} +4 -4
- package/dist/{html-to-image-Cn1_16-x.js → html-to-image-B8s5SgGm.js} +37 -37
- package/dist/{infoDiagram-27XIBGKW-DVQFYvhg.js → infoDiagram-27XIBGKW-DipQoHxl.js} +2 -2
- package/dist/{ishikawaDiagram-5VMMS53U-viPND-nm.js → ishikawaDiagram-5VMMS53U-DgFMjSGz.js} +3 -3
- package/dist/{journeyDiagram-3NMN7TZE-BeeJdJo3.js → journeyDiagram-3NMN7TZE-BaLqn-dZ.js} +2 -2
- package/dist/{jsx-runtime-DgDPJV9S.js → jsx-runtime-3BD1kT0s.js} +1 -1
- package/dist/{kanban-definition-UXKFOSKX-Dcl_ECO9.js → kanban-definition-UXKFOSKX-w1ACVjgl.js} +9 -9
- package/dist/{katex-BNCmKUol.js → katex-BIdZGsyO.js} +141 -116
- package/dist/{label-DQO1jFjf.js → label-BDKF3Afc.js} +10 -10
- package/dist/{loader-Cm-ATtou.js → loader-BQOfjTIJ.js} +1 -1
- package/dist/main.js +623 -590
- package/dist/{mermaid-BfhcnSj-.js → mermaid-CHo49Yv-.js} +56 -56
- package/dist/mermaid-HWGCJPDP-ByCsZnYF.js +2 -0
- package/dist/{mhchem-BEc7A1or.js → mhchem-CdWPJK6g.js} +1 -1
- package/dist/{mindmap-definition-YA3MSWOX-BdxxhF-5.js → mindmap-definition-YA3MSWOX-CrT0KSfX.js} +11 -11
- package/dist/{number-overlay-editor-tMylyldi.js → number-overlay-editor-9VRv-pdj.js} +5 -5
- package/dist/{pegDiagram-XKGWAZYB-Du5p2s0w.js → pegDiagram-XKGWAZYB-BqvywNJA.js} +3 -3
- package/dist/{pieDiagram-E7YTZNPT-DJg-SOIq.js → pieDiagram-E7YTZNPT-BfxJ_XCc.js} +3 -3
- package/dist/{process-output-CUG57KRp.js → process-output-CKRXyszb.js} +5 -5
- package/dist/{quadrantDiagram-AXDQQJYC-keLfFx9f.js → quadrantDiagram-AXDQQJYC-Ccw0xMjN.js} +1 -1
- package/dist/{railroadDiagram-O6MQD6OU-C0ojm-6_.js → railroadDiagram-O6MQD6OU-8vFLVTPu.js} +3 -3
- package/dist/{react-dom-BUgJ-ab_.js → react-dom-DUmH0GXv.js} +29 -21
- package/dist/{react-ofJbxM4x.js → react-sHtZdjeP.js} +103 -94
- package/dist/{react-vega-ewj7q_U5.js → react-vega-BED0DjiB.js} +3 -3
- package/dist/{requirementDiagram-BXWQKSXE-CNwNBmI3.js → requirementDiagram-BXWQKSXE-a_MxGvxe.js} +11 -11
- package/dist/{reveal-component-LXUMcqWX.js → reveal-component-C87mv9Mn.js} +906 -878
- package/dist/{sankeyDiagram-P5KCCOFB-Bh4EsJox.js → sankeyDiagram-P5KCCOFB-ELvOcnZH.js} +1 -1
- package/dist/{select-Bs-nmvm6.js → select-BButFi-d.js} +11 -11
- package/dist/{sequenceDiagram-WJ2MYXX4-DQaW5qBG.js → sequenceDiagram-WJ2MYXX4-CXFMnxGh.js} +4 -4
- package/dist/{spec-DVsoMvYT.js → spec-BwarBpUJ.js} +4 -4
- package/dist/{stateDiagram-D77RDMKH-BDa515QC.js → stateDiagram-D77RDMKH-DQeA_CwI.js} +13 -13
- package/dist/stateDiagram-v2-MP3YSRHH-BxxQucm1.js +30 -0
- package/dist/style.css +1 -1
- package/dist/{swimlanes-42K2YHIH-M4IdGi8J.js → swimlanes-42K2YHIH-Do6L-cYg.js} +10 -10
- package/dist/swimlanesDiagram-VR7AAH4N-DUzPvSVU.js +30 -0
- package/dist/{swiper-component-CpN-hewZ.js → swiper-component-DKntyn8p.js} +5 -5
- package/dist/{timeline-definition-24CTP7MA-DH-kvakg.js → timeline-definition-24CTP7MA-D3c46WM5.js} +3 -3
- package/dist/{toDate-vEi5kTfY.js → toDate-vIXljnsr.js} +43 -42
- package/dist/{toast-DfEpJedt.js → toast-B9UMEi8u.js} +9 -9
- package/dist/{tooltip-CuNWg2ay.js → tooltip-BO1REbqs.js} +7 -7
- package/dist/{use-restore-focus-kmgwrL8q.js → use-restore-focus-BEM7sFWl.js} +2042 -1827
- package/dist/{use-vega-container-remeasure-4DwJbPWu.js → use-vega-container-remeasure-Bz4PZMtt.js} +2 -2
- package/dist/{useAsyncData-rkAlR_vh.js → useAsyncData-Deh5kszT.js} +3 -3
- package/dist/{useDateFormatter-C-tz65rD.js → useDateFormatter-D8XruNGG.js} +4 -4
- package/dist/{useDeepCompareMemoize-BlHFBj5_.js → useDeepCompareMemoize-DXwzRINI.js} +2 -2
- package/dist/{useIframeCapabilities-C1Bt04Iz.js → useIframeCapabilities-DBETvvPl.js} +2 -2
- package/dist/{useLifecycle-B68iY077.js → useLifecycle-j7D9uD1o.js} +6 -6
- package/dist/{useTheme-BwSgeAFb.js → useTheme-CRnjkku0.js} +7 -7
- package/dist/{vega-component-C-bPttRN.js → vega-component-DTG6zxaY.js} +14 -14
- package/dist/{vega-embed-container-sSR5hAsy.js → vega-embed-container-BNHE18G9.js} +5 -5
- package/dist/{vennDiagram-4TSXK5OY-d5g7XeiI.js → vennDiagram-4TSXK5OY-BSZD8JcZ.js} +3 -3
- package/dist/{wardleyDiagram-VM6X3IG4-BfX3bSzR.js → wardleyDiagram-VM6X3IG4-48cUWkfA.js} +3 -3
- package/dist/{xychartDiagram-S5SC5T6Z-C1QsLZg7.js → xychartDiagram-S5SC5T6Z-CswYgYeu.js} +5 -5
- package/package.json +25 -22
- package/src/__tests__/fixtures/{pair-preview.ts → pair-config.ts} +3 -2
- package/src/__tests__/host-imports.test.ts +100 -0
- package/src/__tests__/mount.test.ts +8 -8
- package/src/components/data-table/__tests__/column_formatting.test.ts +30 -0
- package/src/components/data-table/__tests__/columns.test.tsx +70 -0
- package/src/components/data-table/__tests__/context-menu.test.ts +176 -0
- package/src/components/data-table/__tests__/date-filter-inputs.test.tsx +24 -1
- package/src/components/data-table/__tests__/export-actions.test.tsx +329 -6
- package/src/components/data-table/column-formatting/feature.ts +20 -1
- package/src/components/data-table/columns.tsx +25 -18
- package/src/components/data-table/context-menu.tsx +125 -26
- package/src/components/data-table/date-filter-inputs.tsx +15 -42
- package/src/components/data-table/export-actions.tsx +192 -116
- package/src/components/data-table/schemas.ts +14 -36
- package/src/components/data-table/utils.ts +18 -0
- package/src/components/editor/Output.tsx +9 -2
- package/src/components/editor/actions/__tests__/pair-with-agent-commands.test.ts +80 -252
- package/src/components/editor/actions/__tests__/pair-with-agent-modal.test.tsx +186 -34
- package/src/components/editor/actions/pair-with-agent-commands.ts +42 -51
- package/src/components/editor/actions/pair-with-agent-modal.tsx +96 -36
- package/src/components/editor/chrome/panels/error-panel.tsx +1 -0
- package/src/components/editor/chrome/wrapper/__tests__/attachment-status.test.tsx +372 -0
- package/src/components/editor/chrome/wrapper/footer-item.tsx +32 -24
- package/src/components/editor/chrome/wrapper/footer-items/attachment-status.tsx +237 -0
- package/src/components/editor/chrome/wrapper/footer.tsx +2 -0
- package/src/components/editor/controls/__tests__/notebook-menu-dropdown.test.tsx +4 -3
- package/src/components/editor/errors/__tests__/send-error-report-button.test.tsx +548 -0
- package/src/components/editor/errors/send-error-report-button.tsx +69 -0
- package/src/components/editor/output/MarimoErrorOutput.tsx +21 -5
- package/src/components/editor/output/MarimoTracebackOutput.tsx +35 -20
- package/src/components/editor/output/__tests__/ansi-reduce.test.ts +18 -0
- package/src/components/editor/output/ansi-reduce.ts +6 -0
- package/src/components/editor/output/console/ConsoleOutput.tsx +5 -3
- package/src/components/editor/output/console/__tests__/ConsoleOutput.test.tsx +18 -0
- package/src/components/storage/__tests__/storage-file-viewer.test.tsx +2 -1
- package/src/core/attachments/__tests__/toast.test.tsx +58 -0
- package/src/core/attachments/state.ts +21 -0
- package/src/core/attachments/toast.ts +15 -0
- package/src/core/cells/__tests__/cells.test.ts +52 -0
- package/src/core/cells/__tests__/document-roundtrip.test.ts +16 -0
- package/src/core/cells/__tests__/error-report.test.ts +139 -0
- package/src/core/cells/__tests__/session.test.ts +50 -1
- package/src/core/cells/error-report.ts +63 -0
- package/src/core/cells/session.ts +28 -1
- package/src/core/codemirror/copilot/__tests__/completion-integration.test.ts +447 -0
- package/src/core/codemirror/copilot/__tests__/inline-completion.test.ts +395 -0
- package/src/core/codemirror/copilot/__tests__/language-server.test.ts +511 -2
- package/src/core/codemirror/copilot/__tests__/rpc-cancellation.test.ts +201 -0
- package/src/core/codemirror/copilot/extension.ts +22 -11
- package/src/core/codemirror/copilot/language-server.ts +109 -60
- package/src/core/codemirror/language/__tests__/sql.test.ts +4 -3
- package/src/core/codemirror/language/embedded/__tests__/embedded-python.test.ts +138 -26
- package/src/core/codemirror/language/embedded/embedded-python.ts +47 -13
- package/src/core/codemirror/language/embedded/latex.ts +20 -13
- package/src/core/config/pair.ts +5 -3
- package/src/core/datasets/__tests__/data-source-discovery.test.ts +18 -11
- package/src/core/host/AGENTS.md +6 -0
- package/src/core/host/__tests__/protocol.test.ts +214 -0
- package/src/core/host/protocol.ts +1943 -0
- package/src/core/islands/__tests__/bootstrap.test.ts +26 -0
- package/src/core/islands/bootstrap.ts +1 -0
- package/src/core/islands/bridge.ts +2 -2
- package/src/core/kernel/messages.ts +4 -7
- package/src/core/network/__tests__/api.test.ts +114 -1
- package/src/core/network/api.ts +3 -2
- package/src/core/wasm/bridge.ts +2 -2
- package/src/core/wasm/worker/types.ts +2 -2
- package/src/core/websocket/__tests__/useMarimoKernelConnection.hook.test.tsx +193 -0
- package/src/core/websocket/useMarimoKernelConnection.tsx +9 -0
- package/src/css/katex-css.test.ts +1 -1
- package/src/css/katex.min.css +6 -1
- package/src/hooks/__tests__/useEventListener.test.tsx +45 -1
- package/src/hooks/useEventListener.ts +6 -1
- package/src/mount.tsx +3 -3
- package/src/plugins/impl/NumberPlugin.tsx +20 -3
- package/src/plugins/impl/__tests__/DataTablePlugin.test.tsx +84 -0
- package/src/plugins/impl/__tests__/NumberPlugin.test.tsx +159 -1
- package/src/utils/__tests__/dates.test.ts +116 -0
- package/src/utils/dates.ts +94 -0
- package/dist/assets/__vite-browser-external-BqAtzd2P.js +0 -1
- package/dist/assets/worker-Bf8dt6S-.js +0 -109
- package/dist/classDiagram-ZZMXUADV-Bbo2n384.js +0 -30
- package/dist/classDiagram-v2-VYDZK3BY-xR8cGP0r.js +0 -30
- package/dist/error-entries-BovkFYNy.js +0 -56
- package/dist/flowDiagram-HODETNUW-D7IBKS12.js +0 -16
- package/dist/mermaid-HWGCJPDP-DYCzSILp.js +0 -2
- package/dist/stateDiagram-v2-MP3YSRHH-ChNddepZ.js +0 -30
- package/dist/swimlanesDiagram-VR7AAH4N-FUSwmzEp.js +0 -30
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
EditorSelection,
|
|
5
|
+
EditorState,
|
|
6
|
+
type TransactionSpec,
|
|
7
|
+
} from "@codemirror/state";
|
|
8
|
+
import { EditorView } from "@codemirror/view";
|
|
9
|
+
import {
|
|
10
|
+
acceptInlineCompletion,
|
|
11
|
+
inlineCompletion,
|
|
12
|
+
rejectInlineCompletion,
|
|
13
|
+
} from "@marimo-team/codemirror-ai";
|
|
14
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
15
|
+
|
|
16
|
+
// Exercise the installed dependency to catch regressions in upstream releases.
|
|
17
|
+
describe("inline completion lifecycle", () => {
|
|
18
|
+
let view: EditorView;
|
|
19
|
+
const fetchFn =
|
|
20
|
+
vi.fn<
|
|
21
|
+
(
|
|
22
|
+
state: EditorState,
|
|
23
|
+
signal: AbortSignal,
|
|
24
|
+
view: EditorView,
|
|
25
|
+
) => Promise<string>
|
|
26
|
+
>();
|
|
27
|
+
|
|
28
|
+
function create(
|
|
29
|
+
options: Partial<Parameters<typeof inlineCompletion>[0]> = {},
|
|
30
|
+
) {
|
|
31
|
+
view = new EditorView({
|
|
32
|
+
parent: document.body,
|
|
33
|
+
state: EditorState.create({
|
|
34
|
+
doc: "pri",
|
|
35
|
+
selection: { anchor: 3 },
|
|
36
|
+
extensions: [
|
|
37
|
+
EditorState.allowMultipleSelections.of(true),
|
|
38
|
+
inlineCompletion({ delay: 150, fetchFn, ...options }),
|
|
39
|
+
],
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function type(text: string) {
|
|
45
|
+
view.dispatch({
|
|
46
|
+
...view.state.replaceSelection(text),
|
|
47
|
+
userEvent: "input.type",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function suggestion() {
|
|
52
|
+
return view.dom.querySelector(".cm-inline-suggestion")?.textContent ?? null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function show(text = 't("hello")') {
|
|
56
|
+
fetchFn.mockResolvedValue(text);
|
|
57
|
+
type("n");
|
|
58
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
59
|
+
expect(suggestion()).toBe(text);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
beforeEach(() => {
|
|
63
|
+
vi.useFakeTimers();
|
|
64
|
+
fetchFn.mockReset().mockResolvedValue('t("hello")');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
afterEach(() => {
|
|
68
|
+
view?.destroy();
|
|
69
|
+
vi.useRealTimers();
|
|
70
|
+
vi.restoreAllMocks();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("debounces bursts and fetches only the latest document at 150ms", async () => {
|
|
74
|
+
create();
|
|
75
|
+
type("n");
|
|
76
|
+
await vi.advanceTimersByTimeAsync(149);
|
|
77
|
+
expect(fetchFn).not.toHaveBeenCalled();
|
|
78
|
+
type("t");
|
|
79
|
+
await vi.advanceTimersByTimeAsync(149);
|
|
80
|
+
expect(fetchFn).not.toHaveBeenCalled();
|
|
81
|
+
const state = view.state;
|
|
82
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
83
|
+
expect(fetchFn).toHaveBeenCalledExactlyOnceWith(
|
|
84
|
+
state,
|
|
85
|
+
expect.objectContaining({ aborted: false }),
|
|
86
|
+
view,
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it.each(["t", 't("', 't("hello'])(
|
|
91
|
+
"retains the suffix immediately after matching input %j",
|
|
92
|
+
async (text) => {
|
|
93
|
+
create();
|
|
94
|
+
await show();
|
|
95
|
+
type(text);
|
|
96
|
+
expect(suggestion()).toBe('t("hello")'.slice(text.length));
|
|
97
|
+
await vi.advanceTimersByTimeAsync(1000);
|
|
98
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
99
|
+
expect(acceptInlineCompletion(view)).toBe(true);
|
|
100
|
+
expect(view.state.doc.toString()).toBe('print("hello")');
|
|
101
|
+
},
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
it("preserves multiline and UTF-16 suggestions", async () => {
|
|
105
|
+
create();
|
|
106
|
+
await show("😀\nnext()");
|
|
107
|
+
type("😀\n");
|
|
108
|
+
expect(suggestion()).toBe("next()");
|
|
109
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("fetches a continuation when the suggestion is fully typed", async () => {
|
|
113
|
+
create();
|
|
114
|
+
await show("t");
|
|
115
|
+
fetchFn.mockResolvedValue("(value)");
|
|
116
|
+
type("t");
|
|
117
|
+
expect(suggestion()).toBeNull();
|
|
118
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
119
|
+
expect(suggestion()).toBe("(value)");
|
|
120
|
+
expect(fetchFn).toHaveBeenCalledTimes(2);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it.each<[string, TransactionSpec]>([
|
|
124
|
+
[
|
|
125
|
+
"mismatch",
|
|
126
|
+
{ changes: { from: 4, insert: "x" }, selection: { anchor: 5 } },
|
|
127
|
+
],
|
|
128
|
+
["deletion", { changes: { from: 3, to: 4 }, selection: { anchor: 3 } }],
|
|
129
|
+
[
|
|
130
|
+
"replacement",
|
|
131
|
+
{ changes: { from: 3, to: 4, insert: "t" }, selection: { anchor: 4 } },
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
"edit away from cursor",
|
|
135
|
+
{ changes: { from: 0, insert: "t" }, selection: { anchor: 5 } },
|
|
136
|
+
],
|
|
137
|
+
[
|
|
138
|
+
"multiple edits",
|
|
139
|
+
{
|
|
140
|
+
changes: [
|
|
141
|
+
{ from: 0, insert: "x" },
|
|
142
|
+
{ from: 4, insert: "t" },
|
|
143
|
+
],
|
|
144
|
+
selection: { anchor: 6 },
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
"cursor moved after insertion",
|
|
149
|
+
{ changes: { from: 4, insert: "t" }, selection: { anchor: 0 } },
|
|
150
|
+
],
|
|
151
|
+
])("discards a suggestion after %s", async (_label, transaction) => {
|
|
152
|
+
create();
|
|
153
|
+
await show();
|
|
154
|
+
view.dispatch(transaction);
|
|
155
|
+
expect(suggestion()).toBeNull();
|
|
156
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
157
|
+
expect(fetchFn).toHaveBeenCalledTimes(2);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("does not reuse suggestions or fetch for multiple cursors", async () => {
|
|
161
|
+
create();
|
|
162
|
+
await show();
|
|
163
|
+
view.dispatch({
|
|
164
|
+
selection: EditorSelection.create(
|
|
165
|
+
[EditorSelection.cursor(0), EditorSelection.cursor(4)],
|
|
166
|
+
1,
|
|
167
|
+
),
|
|
168
|
+
});
|
|
169
|
+
type("t");
|
|
170
|
+
expect(view.state.doc.toString()).toBe("tprint");
|
|
171
|
+
expect(view.state.selection.toJSON()).toEqual(
|
|
172
|
+
EditorSelection.create(
|
|
173
|
+
[EditorSelection.cursor(1), EditorSelection.cursor(6)],
|
|
174
|
+
1,
|
|
175
|
+
).toJSON(),
|
|
176
|
+
);
|
|
177
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
178
|
+
expect(suggestion()).toBeNull();
|
|
179
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("does not fetch when an edit leaves a nonempty selection", async () => {
|
|
183
|
+
create();
|
|
184
|
+
view.dispatch({
|
|
185
|
+
changes: { from: 3, insert: "n" },
|
|
186
|
+
selection: { anchor: 0, head: 4 },
|
|
187
|
+
});
|
|
188
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
189
|
+
expect(fetchFn).not.toHaveBeenCalled();
|
|
190
|
+
expect(suggestion()).toBeNull();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("cancels a deferred cache hit before it can display at a new cursor", async () => {
|
|
194
|
+
create();
|
|
195
|
+
await show();
|
|
196
|
+
view.dispatch({ changes: { from: 3, to: 4 }, selection: { anchor: 3 } });
|
|
197
|
+
type("n");
|
|
198
|
+
view.dispatch({ selection: { anchor: 0 } });
|
|
199
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
200
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
201
|
+
expect(suggestion()).toBeNull();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("ignores a late failure from a cancelled request without hiding its replacement", async () => {
|
|
205
|
+
create();
|
|
206
|
+
const error = vi
|
|
207
|
+
.spyOn(console, "error")
|
|
208
|
+
.mockImplementation(() => undefined);
|
|
209
|
+
const old = Promise.withResolvers<string>();
|
|
210
|
+
fetchFn.mockReturnValueOnce(old.promise).mockResolvedValueOnce("(new)");
|
|
211
|
+
type("n");
|
|
212
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
213
|
+
type("t");
|
|
214
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
215
|
+
expect(suggestion()).toBe("(new)");
|
|
216
|
+
old.reject(new Error("old connection failed"));
|
|
217
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
218
|
+
expect(suggestion()).toBe("(new)");
|
|
219
|
+
expect(error).not.toHaveBeenCalled();
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("cancels scheduled work when the cursor moves", async () => {
|
|
223
|
+
create();
|
|
224
|
+
type("n");
|
|
225
|
+
view.dispatch({ selection: { anchor: 0 } });
|
|
226
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
227
|
+
expect(fetchFn).not.toHaveBeenCalled();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("aborts superseded work and ignores an out-of-order response", async () => {
|
|
231
|
+
create();
|
|
232
|
+
const old = Promise.withResolvers<string>();
|
|
233
|
+
const latest = Promise.withResolvers<string>();
|
|
234
|
+
fetchFn
|
|
235
|
+
.mockReturnValueOnce(old.promise)
|
|
236
|
+
.mockReturnValueOnce(latest.promise);
|
|
237
|
+
type("n");
|
|
238
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
239
|
+
const oldSignal = fetchFn.mock.calls[0][1];
|
|
240
|
+
type("t");
|
|
241
|
+
expect(oldSignal.aborted).toBe(true);
|
|
242
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
243
|
+
latest.resolve("(new)");
|
|
244
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
245
|
+
old.resolve("stale");
|
|
246
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
247
|
+
expect(suggestion()).toBe("(new)");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("ignores a response after moving away and back to the same cursor", async () => {
|
|
251
|
+
create();
|
|
252
|
+
const result = Promise.withResolvers<string>();
|
|
253
|
+
fetchFn.mockReturnValue(result.promise);
|
|
254
|
+
type("n");
|
|
255
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
256
|
+
view.dispatch({ selection: { anchor: 0 } });
|
|
257
|
+
view.dispatch({ selection: { anchor: 4 } });
|
|
258
|
+
result.resolve("stale");
|
|
259
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
260
|
+
expect(suggestion()).toBeNull();
|
|
261
|
+
expect(fetchFn.mock.calls[0][1].aborted).toBe(true);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it.each([false, true])(
|
|
265
|
+
"cancels on destruction (already fetching: %s)",
|
|
266
|
+
async (started) => {
|
|
267
|
+
create();
|
|
268
|
+
const result = Promise.withResolvers<string>();
|
|
269
|
+
fetchFn.mockReturnValue(result.promise);
|
|
270
|
+
type("n");
|
|
271
|
+
if (started) {
|
|
272
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
273
|
+
}
|
|
274
|
+
view.destroy();
|
|
275
|
+
result.resolve("stale");
|
|
276
|
+
await vi.advanceTimersByTimeAsync(200);
|
|
277
|
+
expect(fetchFn).toHaveBeenCalledTimes(started ? 1 : 0);
|
|
278
|
+
expect(fetchFn.mock.calls[0]?.[1].aborted).toBe(
|
|
279
|
+
started ? true : undefined,
|
|
280
|
+
);
|
|
281
|
+
},
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
it("recovers after a failed request", async () => {
|
|
285
|
+
create();
|
|
286
|
+
const error = vi
|
|
287
|
+
.spyOn(console, "error")
|
|
288
|
+
.mockImplementation(() => undefined);
|
|
289
|
+
fetchFn.mockRejectedValueOnce(new Error("offline"));
|
|
290
|
+
type("n");
|
|
291
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
292
|
+
expect(suggestion()).toBeNull();
|
|
293
|
+
expect(error).toHaveBeenCalledTimes(1);
|
|
294
|
+
type("t");
|
|
295
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
296
|
+
expect(suggestion()).toBe('t("hello")');
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("does not log an expected abort rejection", async () => {
|
|
300
|
+
create();
|
|
301
|
+
const error = vi
|
|
302
|
+
.spyOn(console, "error")
|
|
303
|
+
.mockImplementation(() => undefined);
|
|
304
|
+
fetchFn.mockRejectedValueOnce(new DOMException("aborted", "AbortError"));
|
|
305
|
+
type("n");
|
|
306
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
307
|
+
expect(error).not.toHaveBeenCalled();
|
|
308
|
+
expect(suggestion()).toBeNull();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("respects fetch/display gates and Escape rejection", async () => {
|
|
312
|
+
const before = vi.fn(() => false);
|
|
313
|
+
const display = vi.fn(() => false);
|
|
314
|
+
create({
|
|
315
|
+
events: { beforeSuggestionFetch: before, shouldShowSuggestion: display },
|
|
316
|
+
});
|
|
317
|
+
type("n");
|
|
318
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
319
|
+
expect(fetchFn).not.toHaveBeenCalled();
|
|
320
|
+
before.mockReturnValue(true);
|
|
321
|
+
type("t");
|
|
322
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
323
|
+
expect(suggestion()).toBeNull();
|
|
324
|
+
display.mockReturnValue(true);
|
|
325
|
+
type("(");
|
|
326
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
327
|
+
expect(rejectInlineCompletion(view)).toBe(true);
|
|
328
|
+
expect(suggestion()).toBeNull();
|
|
329
|
+
expect(acceptInlineCompletion(view)).toBe(false);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("reuses a cached result without dispatching during a view update", async () => {
|
|
333
|
+
create();
|
|
334
|
+
await show();
|
|
335
|
+
view.dispatch({ changes: { from: 3, to: 4 }, selection: { anchor: 3 } });
|
|
336
|
+
type("n");
|
|
337
|
+
expect(() => view.dispatch({})).not.toThrow();
|
|
338
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
339
|
+
expect(suggestion()).toBe('t("hello")');
|
|
340
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("does not reuse the same document's cached suggestion at a different cursor", async () => {
|
|
344
|
+
create();
|
|
345
|
+
await show();
|
|
346
|
+
view.dispatch({ changes: { from: 3, to: 4 }, selection: { anchor: 3 } });
|
|
347
|
+
view.dispatch({
|
|
348
|
+
changes: { from: 3, insert: "n" },
|
|
349
|
+
selection: { anchor: 0 },
|
|
350
|
+
});
|
|
351
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
352
|
+
expect(fetchFn).toHaveBeenCalledTimes(2);
|
|
353
|
+
expect(fetchFn.mock.calls[1][0].selection.main.head).toBe(0);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("expires cached results", async () => {
|
|
357
|
+
create({ cacheTimeout: 100 });
|
|
358
|
+
await show();
|
|
359
|
+
await vi.advanceTimersByTimeAsync(101);
|
|
360
|
+
view.dispatch({ changes: { from: 3, to: 4 }, selection: { anchor: 3 } });
|
|
361
|
+
type("n");
|
|
362
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
363
|
+
expect(fetchFn).toHaveBeenCalledTimes(2);
|
|
364
|
+
});
|
|
365
|
+
it("bounds the cache instead of retaining every document ever typed", async () => {
|
|
366
|
+
create({ delay: 0, cacheTimeout: 1_000_000 });
|
|
367
|
+
await show();
|
|
368
|
+
for (let i = 0; i < 21; i++) {
|
|
369
|
+
const text = `entry${i}`;
|
|
370
|
+
view.dispatch({
|
|
371
|
+
changes: { from: 0, to: view.state.doc.length, insert: text },
|
|
372
|
+
selection: { anchor: text.length },
|
|
373
|
+
});
|
|
374
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
375
|
+
}
|
|
376
|
+
view.dispatch({
|
|
377
|
+
changes: { from: 0, to: view.state.doc.length, insert: "prin" },
|
|
378
|
+
selection: { anchor: 4 },
|
|
379
|
+
});
|
|
380
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
381
|
+
expect(fetchFn).toHaveBeenCalledTimes(23);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("does not cache empty results", async () => {
|
|
385
|
+
create();
|
|
386
|
+
fetchFn.mockResolvedValueOnce("");
|
|
387
|
+
type("n");
|
|
388
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
389
|
+
view.dispatch({ changes: { from: 3, to: 4 }, selection: { anchor: 3 } });
|
|
390
|
+
type("n");
|
|
391
|
+
await vi.advanceTimersByTimeAsync(150);
|
|
392
|
+
expect(fetchFn).toHaveBeenCalledTimes(2);
|
|
393
|
+
expect(suggestion()).toBe('t("hello")');
|
|
394
|
+
});
|
|
395
|
+
});
|