@marimo-team/islands 0.21.2-dev13 → 0.21.2-dev15

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/main.js CHANGED
@@ -29325,6 +29325,8 @@ ${c.sqlString}
29325
29325
  var NotebookLanguageServerClient = (_a = class {
29326
29326
  constructor(e, r, c = defaultGetNotebookEditors) {
29327
29327
  __publicField(this, "completionItemCache", new LRUCache(10));
29328
+ __publicField(this, "latestDiagnosticsVersion", null);
29329
+ __publicField(this, "forwardedDiagnosticsVersion", 0);
29328
29330
  this.documentUri = getLSPDocument(), this.getNotebookEditors = c, this.initialSettings = r, this.client = e, this.patchProcessNotification(), this.initializePromise.then(() => {
29329
29331
  invariant(isClientWithNotify(this.client), "notify is not a method on the client"), this.client.notify("workspace/didChangeConfiguration", {
29330
29332
  settings: r
@@ -29372,7 +29374,7 @@ ${c.sqlString}
29372
29374
  settings: this.initialSettings
29373
29375
  });
29374
29376
  let { lens: e, version: r } = this.snapshotter.snapshot();
29375
- await this.client.textDocumentDidOpen({
29377
+ this.latestDiagnosticsVersion = null, this.forwardedDiagnosticsVersion = 0, await this.client.textDocumentDidOpen({
29376
29378
  textDocument: {
29377
29379
  languageId: "python",
29378
29380
  text: e.mergedText,
@@ -29570,39 +29572,49 @@ ${c.sqlString}
29570
29572
  invariant("processNotification" in this.client, "processNotification is not a method on the client");
29571
29573
  let r = this.client.processNotification.bind(this.client), c = (c2) => {
29572
29574
  if (c2.method === "textDocument/publishDiagnostics") {
29575
+ let d = c2.params.version;
29576
+ if (d != null) {
29577
+ let e = this.latestDiagnosticsVersion;
29578
+ if (e !== null && Number.isFinite(d) && d < e) {
29579
+ Logger.debug("[lsp] dropping stale diagnostics notification", c2);
29580
+ return;
29581
+ }
29582
+ this.latestDiagnosticsVersion = d;
29583
+ }
29573
29584
  Logger.debug("[lsp] handling diagnostics", c2);
29574
- let d = this.snapshotter.getLatestSnapshot(), f = c2.params.diagnostics, { lens: _, version: v } = d, y = /* @__PURE__ */ new Map();
29575
- for (let e of f) for (let r2 of _.cellIds) if (_.isInRange(e.range, r2)) {
29576
- y.has(r2) || y.set(r2, []);
29585
+ let f = this.snapshotter.getLatestSnapshot(), _ = c2.params.diagnostics, { lens: v } = f, y = ++this.forwardedDiagnosticsVersion, S = /* @__PURE__ */ new Map();
29586
+ for (let e of _) for (let r2 of v.cellIds) if (v.isInRange(e.range, r2)) {
29587
+ S.has(r2) || S.set(r2, []);
29577
29588
  let c3 = {
29578
29589
  ...e,
29579
- range: _.reverseRange(e.range, r2)
29590
+ range: v.reverseRange(e.range, r2)
29580
29591
  };
29581
- y.get(r2).push(c3);
29592
+ S.get(r2).push(c3);
29582
29593
  break;
29583
29594
  }
29584
- let S = new Set(_.cellIds);
29585
- _a.pruneSeenCellUris(S);
29586
- let w = new Set(_a.SEEN_CELL_DOCUMENT_URIS);
29587
- for (let [e, d2] of y.entries()) {
29595
+ let w = new Set(v.cellIds);
29596
+ _a.pruneSeenCellUris(w);
29597
+ let E = new Set(_a.SEEN_CELL_DOCUMENT_URIS);
29598
+ for (let [e, d2] of S.entries()) {
29588
29599
  Logger.debug("[lsp] diagnostics for cell", e, d2);
29589
29600
  let f2 = CellDocumentUri.of(e);
29590
- w.delete(f2), r({
29601
+ E.delete(f2), r({
29591
29602
  ...c2,
29592
29603
  params: {
29593
29604
  ...c2.params,
29594
29605
  uri: f2,
29595
- version: v,
29606
+ version: y,
29596
29607
  diagnostics: d2
29597
29608
  }
29598
29609
  });
29599
29610
  }
29600
- if (w.size > 0) {
29601
- Logger.debug("[lsp] clearing diagnostics", w);
29602
- for (let e of w) r({
29611
+ if (E.size > 0) {
29612
+ Logger.debug("[lsp] clearing diagnostics", E);
29613
+ for (let e of E) r({
29603
29614
  method: "textDocument/publishDiagnostics",
29604
29615
  params: {
29605
29616
  uri: e,
29617
+ version: y,
29606
29618
  diagnostics: []
29607
29619
  }
29608
29620
  });
@@ -70786,7 +70798,7 @@ Image URL: ${r.imageUrl}`)), contextToXml({
70786
70798
  return Logger.warn("Failed to get version from mount config"), null;
70787
70799
  }
70788
70800
  }
70789
- const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.21.2-dev13"), showCodeInRunModeAtom = atom(true);
70801
+ const marimoVersionAtom = atom(getVersionFromMountConfig() || "0.21.2-dev15"), showCodeInRunModeAtom = atom(true);
70790
70802
  atom(null);
70791
70803
  var import_compiler_runtime$89 = require_compiler_runtime();
70792
70804
  function useKeydownOnElement(e, r) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.21.2-dev13",
3
+ "version": "0.21.2-dev15",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { zodResolver } from "@hookform/resolvers/zod";
4
4
  import { atom, useAtom, useAtomValue, useSetAtom } from "jotai";
5
+ import { merge } from "lodash-es";
5
6
  import {
6
7
  AlertTriangleIcon,
7
8
  BrainIcon,
@@ -287,10 +288,10 @@ export const UserConfigForm: React.FC = () => {
287
288
  dirtyValues.ai = setAiModels(values.ai, dirtyValues.ai);
288
289
  }
289
290
 
290
- await saveUserConfig({ config: dirtyValues }).then(() => {
291
- // Update local state with form values
292
- setConfig((prev) => ({ ...prev, ...values }));
293
- });
291
+ await saveUserConfig({ config: dirtyValues });
292
+ // Only apply the changed keys; this avoids stale request responses
293
+ // overwriting newer config changes.
294
+ setConfig((prev) => merge({}, prev, dirtyValues));
294
295
  };
295
296
  const onSubmit = useDebouncedCallback(onSubmitNotDebounced, FORM_DEBOUNCE);
296
297
 
@@ -178,6 +178,8 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {
178
178
  string,
179
179
  Promise<LSP.CompletionItem>
180
180
  >(10);
181
+ private latestDiagnosticsVersion: number | null = null;
182
+ private forwardedDiagnosticsVersion = 0;
181
183
 
182
184
  constructor(
183
185
  client: ILanguageServerClient,
@@ -270,6 +272,8 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {
270
272
 
271
273
  // Get the current document state
272
274
  const { lens, version } = this.snapshotter.snapshot();
275
+ this.latestDiagnosticsVersion = null;
276
+ this.forwardedDiagnosticsVersion = 0;
273
277
 
274
278
  // Re-open the merged document with the LSP server
275
279
  // This sends a textDocument/didOpen for the entire notebook
@@ -768,13 +772,34 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {
768
772
  | { method: "other"; params: unknown },
769
773
  ) => {
770
774
  if (notification.method === "textDocument/publishDiagnostics") {
775
+ const incomingVersion = notification.params.version;
776
+ if (incomingVersion != null) {
777
+ const latestVersion = this.latestDiagnosticsVersion;
778
+ if (
779
+ latestVersion !== null &&
780
+ Number.isFinite(incomingVersion) &&
781
+ incomingVersion < latestVersion
782
+ ) {
783
+ Logger.debug(
784
+ "[lsp] dropping stale diagnostics notification",
785
+ notification,
786
+ );
787
+ return;
788
+ }
789
+ this.latestDiagnosticsVersion = incomingVersion;
790
+ }
791
+
771
792
  Logger.debug("[lsp] handling diagnostics", notification);
772
793
  // Use the correct lens by version
773
794
  const payload = this.snapshotter.getLatestSnapshot();
774
795
 
775
796
  const diagnostics = notification.params.diagnostics;
776
797
 
777
- const { lens, version: cellVersion } = payload;
798
+ const { lens } = payload;
799
+ // Forward diagnostics with a strictly increasing version so downstream
800
+ // plugin updates/clears reliably, even when server repeats the same
801
+ // document version across multiple publishDiagnostics notifications.
802
+ const diagnosticsVersion = ++this.forwardedDiagnosticsVersion;
778
803
 
779
804
  // Pre-partition diagnostics by cell
780
805
  const diagnosticsByCellId = new Map<CellId, LSP.Diagnostic[]>();
@@ -817,7 +842,7 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {
817
842
  params: {
818
843
  ...notification.params,
819
844
  uri: cellDocumentUri,
820
- version: cellVersion,
845
+ version: diagnosticsVersion,
821
846
  diagnostics: cellDiagnostics,
822
847
  },
823
848
  });
@@ -832,6 +857,7 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {
832
857
  method: "textDocument/publishDiagnostics",
833
858
  params: {
834
859
  uri: cellDocumentUri,
860
+ version: diagnosticsVersion,
835
861
  diagnostics: [],
836
862
  },
837
863
  });