@hydranium/client-theia 1.0.0-next.123 → 1.0.0-next.127

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.
Files changed (47) hide show
  1. package/README.md +33 -6
  2. package/lib/browser/channel-logger.d.ts +4 -3
  3. package/lib/browser/channel-logger.d.ts.map +1 -1
  4. package/lib/browser/channel-logger.js +9 -4
  5. package/lib/browser/channel-logger.js.map +1 -1
  6. package/lib/browser/editor-disk-sync.d.ts +133 -0
  7. package/lib/browser/editor-disk-sync.d.ts.map +1 -0
  8. package/lib/browser/editor-disk-sync.js +232 -0
  9. package/lib/browser/editor-disk-sync.js.map +1 -0
  10. package/lib/browser/hydranium-file-service.d.ts +44 -0
  11. package/lib/browser/hydranium-file-service.d.ts.map +1 -0
  12. package/lib/browser/hydranium-file-service.js +61 -0
  13. package/lib/browser/hydranium-file-service.js.map +1 -0
  14. package/lib/browser/index.d.ts +2 -0
  15. package/lib/browser/index.d.ts.map +1 -1
  16. package/lib/browser/index.js +2 -0
  17. package/lib/browser/index.js.map +1 -1
  18. package/lib/common/clock.d.ts +19 -0
  19. package/lib/common/clock.d.ts.map +1 -0
  20. package/lib/common/clock.js +13 -0
  21. package/lib/common/clock.js.map +1 -0
  22. package/lib/common/index.d.ts +1 -0
  23. package/lib/common/index.d.ts.map +1 -1
  24. package/lib/common/index.js +4 -3
  25. package/lib/common/index.js.map +1 -1
  26. package/lib/node/abstract-socket-forwarding-connection-handler.d.ts +8 -7
  27. package/lib/node/abstract-socket-forwarding-connection-handler.d.ts.map +1 -1
  28. package/lib/node/abstract-socket-forwarding-connection-handler.js +22 -6
  29. package/lib/node/abstract-socket-forwarding-connection-handler.js.map +1 -1
  30. package/lib/node/index.d.ts +1 -0
  31. package/lib/node/index.d.ts.map +1 -1
  32. package/lib/node/index.js +1 -0
  33. package/lib/node/index.js.map +1 -1
  34. package/lib/node/socket-channel-forwarder.d.ts +54 -0
  35. package/lib/node/socket-channel-forwarder.d.ts.map +1 -0
  36. package/lib/node/socket-channel-forwarder.js +93 -0
  37. package/lib/node/socket-channel-forwarder.js.map +1 -0
  38. package/package.json +12 -6
  39. package/src/browser/channel-logger.ts +9 -4
  40. package/src/browser/editor-disk-sync.ts +236 -0
  41. package/src/browser/hydranium-file-service.ts +56 -0
  42. package/src/browser/index.ts +2 -0
  43. package/src/common/clock.ts +20 -0
  44. package/src/common/index.ts +4 -3
  45. package/src/node/abstract-socket-forwarding-connection-handler.ts +13 -8
  46. package/src/node/index.ts +1 -0
  47. package/src/node/socket-channel-forwarder.ts +99 -0
package/README.md CHANGED
@@ -32,6 +32,21 @@ hydranium server; a non-Theia host does not need it.
32
32
  (Backend) — register only when the optional `HostMemoryDiagnosticsService` is
33
33
  bound. You bind `MemoryDiagnosticsService` to your own connected data-server
34
34
  frontend; the framework cannot, because that class is yours.
35
+ - **`EditorDiskSync`** — keeps a dirty editor's save from applying edits its
36
+ file already holds, as the file does once the server saves a document the
37
+ editor shows unsaved. Before each save of the editor it drops the edits the
38
+ file holds, so the save writes only the rest, a save participant's included;
39
+ on each watched change of the file to the editor's text it marks the editor
40
+ clean. Theia otherwise keeps the editor dirty, and its next save applies the
41
+ editor's edits to a file that already holds them. You bind it as a
42
+ `FrontendApplicationContribution`.
43
+ - **`HydraniumFileService`** — Theia's `FileService`, refusing an editor's
44
+ incremental save once the file's mtime has moved past the one the editor
45
+ read, so the editor writes its whole text instead. Theia's own check passes a
46
+ file of unchanged size, and the save then applies the editor's edits to a
47
+ file that may already hold them; `write` keeps Theia's check. The safety net
48
+ behind `EditorDiskSync`, for a save the sync cannot catch. You bind it with
49
+ `rebind(FileService).to(HydraniumFileService).inSingletonScope()`.
35
50
  - **`captureBrowserRuntime` / `formatBrowserRuntime`** — the renderer's own memory
36
51
  reading as a `BrowserRuntimeReport`, preferring the standardized
37
52
  `performance.measureUserAgentSpecificMemory()` and falling back to Chromium's
@@ -43,6 +58,14 @@ hydranium server; a non-Theia host does not need it.
43
58
  forwarder bridges the two; port discovery, connect orchestration, and the
44
59
  buffer-and-replay fix for frontend writes that arrive before the forwarder is
45
60
  wired all live here.
61
+ - **`SocketChannelForwarder`** (Node side) — the byte forwarder both heads plug
62
+ into that hook. When the frontend channel closes, it finishes the writes it
63
+ still has queued before it ends the socket, so a message sent just before a
64
+ page goes away still reaches the server.
65
+ - **`Clock`** (either side) — the protocol's `Clock` as an injection token.
66
+ The frontend and backend classes above that time or bound something inject
67
+ it as optional and use a `SystemClock` when the container binds none, so a
68
+ container can supply another clock.
46
69
  - **`./testing`** — `makeStubOutputChannelManager` and `makeStubInversifyContext`,
47
70
  the doubles that let the pieces above be unit-tested without a Theia
48
71
  application.
@@ -60,8 +83,11 @@ declared peer dependencies are:
60
83
  | --------------------- | ------------- |
61
84
  | `@hydranium/protocol` | `^1.0.0-next` |
62
85
  | `@theia/core` | `^1.70.0` |
86
+ | `@theia/editor` | `^1.70.0` |
87
+ | `@theia/filesystem` | `^1.70.0` |
63
88
  | `@theia/output` | `^1.70.0` |
64
89
  | `inversify` | `^6.0.0` |
90
+ | `vscode-jsonrpc` | `9.0.1` |
65
91
 
66
92
  `@theia/output` is easy to miss: the memory-diagnostics commands and the channel
67
93
  logger both write to an Output channel, so a host that does not already depend on
@@ -86,12 +112,13 @@ from here:
86
112
 
87
113
  ## Entry points
88
114
 
89
- | Subpath | Holds | Environment |
90
- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
91
- | `.` | Nothing. Deliberately empty, so an environment-specific import cannot reach the wrong bundle through a barrel. | browser-neutral (gated) |
92
- | `./browser` | `ChannelLogger`, `ChannelTracer`, `LogLevelPreferenceContribution`, `MemoryDiagnosticsContribution`, the `bind*` helpers, `captureBrowserRuntime` | browser / Theia frontend (gated) |
93
- | `./node` | `AbstractSocketForwardingConnectionHandler` and its options — imports `node:net` | Node / Theia backend |
94
- | `./testing` | `makeStubOutputChannelManager`, `makeStubInversifyContext` | browser-neutral (gated) |
115
+ | Subpath | Holds | Environment |
116
+ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
117
+ | `.` | Nothing. Deliberately empty, so an environment-specific import cannot reach the wrong bundle through a barrel. | browser-neutral (gated) |
118
+ | `./browser` | `ChannelLogger`, `ChannelTracer`, `LogLevelPreferenceContribution`, `MemoryDiagnosticsContribution`, `EditorDiskSync`, `HydraniumFileService`, the `bind*` helpers, `captureBrowserRuntime` | browser / Theia frontend (gated) |
119
+ | `./common` | `Clock`, the framed socket write buffer and the connection-resilience options | browser-neutral (gated) |
120
+ | `./node` | `AbstractSocketForwardingConnectionHandler` and its options, `SocketChannelForwarder` — imports `node:net` | Node / Theia backend |
121
+ | `./testing` | `makeStubOutputChannelManager`, `makeStubInversifyContext` | browser-neutral (gated) |
95
122
 
96
123
  Every subpath also has a `./lib/<name>` twin, so a consumer on
97
124
  `moduleResolution: "Node"` can reach it. "Gated" means the entry is enforced
@@ -61,9 +61,10 @@ export declare class ChannelLogger extends AbstractLogger {
61
61
  }
62
62
  /**
63
63
  * Inversify token for the browser `Tracer` — a {@link DefaultTracer} over
64
- * the {@link ChannelLogger} (emit sink) + a {@link SystemClock} + a browser
65
- * heap reader. The browser head has no Langium `services.Tracer` slot, so this
66
- * is how frontend services that time obtain a tracer: `@inject(ChannelTracer)`.
64
+ * the {@link ChannelLogger} (emit sink) + the container's {@link Clock}, or a
65
+ * `SystemClock` when it binds none, + a browser heap reader. The browser head
66
+ * has no Langium `services.Tracer` slot, so this is how frontend services that
67
+ * time obtain a tracer: `@inject(ChannelTracer)`.
67
68
  * Bound by {@link bindChannelLogger}.
68
69
  */
69
70
  export declare const ChannelTracer: unique symbol;
@@ -1 +1 @@
1
- {"version":3,"file":"channel-logger.d.ts","sourceRoot":"","sources":["../../src/browser/channel-logger.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,cAAc,EAAiB,KAAK,QAAQ,EAAkC,MAAM,qBAAqB,C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AU,CAAC,OAAO,GAAG,MAAM,GAAG,SAAS,CAOpF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAc5F"}
@@ -26,6 +26,7 @@ exports.bindChannelLogger = bindChannelLogger;
26
26
  const protocol_1 = require("@hydranium/protocol");
27
27
  const inversify_1 = require("@theia/core/shared/inversify");
28
28
  const output_channel_1 = require("@theia/output/lib/browser/output-channel");
29
+ const clock_1 = require("../common/clock");
29
30
  /** Inversify token for the {@link ChannelLoggerOptions} constant (merged with the
30
31
  * interface name — the standard Theia "type + token under one identifier" idiom). */
31
32
  exports.ChannelLoggerOptions = Symbol('ChannelLoggerOptions');
@@ -89,9 +90,10 @@ exports.ChannelLogger = ChannelLogger = __decorate([
89
90
  const ChannelLoggerBase = Symbol('ChannelLoggerBase');
90
91
  /**
91
92
  * Inversify token for the browser `Tracer` — a {@link DefaultTracer} over
92
- * the {@link ChannelLogger} (emit sink) + a {@link SystemClock} + a browser
93
- * heap reader. The browser head has no Langium `services.Tracer` slot, so this
94
- * is how frontend services that time obtain a tracer: `@inject(ChannelTracer)`.
93
+ * the {@link ChannelLogger} (emit sink) + the container's {@link Clock}, or a
94
+ * `SystemClock` when it binds none, + a browser heap reader. The browser head
95
+ * has no Langium `services.Tracer` slot, so this is how frontend services that
96
+ * time obtain a tracer: `@inject(ChannelTracer)`.
95
97
  * Bound by {@link bindChannelLogger}.
96
98
  */
97
99
  exports.ChannelTracer = Symbol('ChannelTracer');
@@ -127,7 +129,10 @@ function bindChannelLogger(bind, options) {
127
129
  return parentName ? base.for(parentName) : base;
128
130
  });
129
131
  bind(exports.ChannelTracer)
130
- .toDynamicValue(ctx => new protocol_1.DefaultTracer(ctx.container.get(ChannelLoggerBase), new protocol_1.SystemClock(), readBrowserMemory))
132
+ .toDynamicValue(ctx => {
133
+ const clock = ctx.container.isBound(clock_1.Clock) ? ctx.container.get(clock_1.Clock) : new protocol_1.SystemClock();
134
+ return new protocol_1.DefaultTracer(ctx.container.get(ChannelLoggerBase), clock, readBrowserMemory);
135
+ })
131
136
  .inSingletonScope();
132
137
  }
133
138
  /** Browser heap reader for {@link ChannelTracer}, backed by Chromium's non-standard `performance.memory`. */
@@ -1 +1 @@
1
- {"version":3,"file":"channel-logger.js","sourceRoot":"","sources":["../../src/browser/channel-logger.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;AAkGlF,oDAOC;AAeD,8CAWC;AAjID,kDAAmH;AACnH,4DAA8F;AAC9F,6EAAoG;AAkBpG;sFACsF;AACzE,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAEnE;;;;;;;;;;;;;;;;GAgBG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,yBAAc;IAIM;IACA;IAJ1C,QAAQ,CAAiB;IAEnC,YACoD,cAAoC,EACpC,OAA6B,EACjE,YAAgC,OAAO,CAAC,SAAS;QAE9D,KAAK,CAAC,SAAS,CAAC,CAAC;QAJgC,mBAAc,GAAd,cAAc,CAAsB;QACpC,YAAO,GAAP,OAAO,CAAsB;IAIjF,CAAC;IAED,IAAc,OAAO;QAClB,OAAO,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACvF,CAAC;IAES,IAAI,CAAC,MAAgB,EAAE,KAAa,EAAE,OAAe,EAAE,IAAwB;QACtF,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC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,CAAC;IACd,CAAC;IACD,IAAI,CAAC;QACF,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACN,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACtB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,133 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+ import type { FrontendApplicationContribution } from '@theia/core/lib/browser';
10
+ import { ILogger } from '@theia/core/lib/common/logger';
11
+ import URI from '@theia/core/lib/common/uri';
12
+ import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
13
+ import type { EditorWidget } from '@theia/editor/lib/browser/editor-widget';
14
+ import type { FileResourceVersion } from '@theia/filesystem/lib/browser/file-resource';
15
+ import { FileService, type TextFileContent } from '@theia/filesystem/lib/browser/file-service';
16
+ import { Clock } from '../common/clock';
17
+ /**
18
+ * The members of Theia's Monaco editor model {@link EditorDiskSync} reads and
19
+ * resets. `contentChanges`, `resourceVersion` and `run` are `protected` there,
20
+ * so {@link isResyncableEditorDocument} checks for them at runtime: a Theia
21
+ * that renames them yields a document it refuses, and the sync then leaves it
22
+ * alone.
23
+ */
24
+ export interface ResyncableEditorDocument {
25
+ readonly uri: string;
26
+ readonly dirty: boolean;
27
+ getText(): string;
28
+ revert(options: {
29
+ soft: boolean;
30
+ }): Promise<void>;
31
+ /** The edits the next save applies to the file, in place of the whole text. */
32
+ readonly contentChanges: unknown[];
33
+ /** The file version the next save expects to find on disk. */
34
+ resourceVersion: FileResourceVersion | undefined;
35
+ /** Queue `operation` behind the model's saves and syncs in progress. */
36
+ run(operation: () => Promise<void>): Promise<void>;
37
+ /** Awaited by each save before it takes the pending edits. */
38
+ onModelWillSaveModel(listener: () => Promise<void>): {
39
+ dispose(): void;
40
+ };
41
+ }
42
+ /** Whether `document` carries the members of {@link ResyncableEditorDocument}. */
43
+ export declare function isResyncableEditorDocument(document: object): document is ResyncableEditorDocument;
44
+ /**
45
+ * Keeps a dirty editor's save from applying edits its file already holds, as
46
+ * the file does once the server saves a document the editor shows unsaved.
47
+ *
48
+ * Theia keeps such an editor dirty, and its next save corrupts the file: the
49
+ * save applies the editor's pending edits to the file rather than writing the
50
+ * whole text, and the file already holds them, so each is applied twice.
51
+ * Theia's check that the file has not changed since the editor read it passes
52
+ * whenever the new file has the old one's size, so no conflict is reported. A
53
+ * revert alone keeps the pending edits.
54
+ *
55
+ * Before each save of the editor it reads the file. When the file holds the
56
+ * text the buffer held as the save began, it drops the edits pending then and
57
+ * has the save expect the file's version, so the save writes only the edits
58
+ * made after that point, a save participant's included, onto the file as it
59
+ * is. The save is not cancelled: it completes and is reported as saved. Save
60
+ * All relies on this check, since it saves a diagram and then an editor on the
61
+ * same file at once, before the file watcher has reported the diagram's write.
62
+ * The buffer is taken when the save calls its will-save listeners. Theia runs
63
+ * its save participants one after another, each behind an await, and its
64
+ * first one awaits before it edits, so none has changed the buffer by then. A
65
+ * participant ordered ahead of it that edits before its first await makes the
66
+ * file and the taken text differ, and the save applies every edit again.
67
+ *
68
+ * On each change the file watcher reports, it marks the editor clean when the
69
+ * file holds exactly its buffer. The file is compared with the buffer after
70
+ * it has been read, and the editor is marked in the same step, so a keystroke
71
+ * made while the file was read leaves the editor dirty. This sync waits behind
72
+ * a save in flight: that save drops the edits it sent from the pending ones
73
+ * when it finishes, and a sync before then would have it drop the edits typed
74
+ * meanwhile.
75
+ *
76
+ * An editor whose file holds neither text is left to Theia's own save,
77
+ * same-size gap included, and so is one whose file cannot be read within
78
+ * {@link readTimeoutMs}, or whose check throws.
79
+ *
80
+ * The adopter binds it as a `FrontendApplicationContribution`.
81
+ */
82
+ export declare class EditorDiskSync implements FrontendApplicationContribution {
83
+ protected readonly fileService: FileService;
84
+ protected readonly editorManager: EditorManager;
85
+ protected readonly logger: ILogger;
86
+ /** Times {@link readTimeoutMs}: the container's {@link Clock}, or a `SystemClock`. */
87
+ protected readonly clock: Clock;
88
+ /** Whether an editor's document has failed {@link isResyncableEditorDocument}; warned of once. */
89
+ protected warnedUnsyncable: boolean;
90
+ /**
91
+ * How long a check waits for the file. The editor's save, and every later
92
+ * save and sync of that editor, waits for the check.
93
+ */
94
+ protected readTimeoutMs: number;
95
+ onStart(): void;
96
+ /** Check `widget`'s document before each of its saves, for as long as the widget lives. */
97
+ protected guardSaves(widget: EditorWidget): void;
98
+ /** Check each dirty document an editor shows on `uri`, behind that document's save in flight. */
99
+ protected checkFile(uri: URI): void;
100
+ /** Read the file of `document` if it is dirty, and sync it if the file holds its buffer. */
101
+ protected syncIfOnDisk(document: ResyncableEditorDocument): Promise<void>;
102
+ /**
103
+ * Before a save of `document`, drop the edits pending now if its file holds
104
+ * the buffer as it is now, and take the file's version. The buffer and the
105
+ * count are taken before the first await, while the save is still calling
106
+ * its will-save listeners; an edit made after that stays pending, and the
107
+ * save writes it onto the file.
108
+ */
109
+ protected dropChangesOnDisk(document: ResyncableEditorDocument): Promise<void>;
110
+ /**
111
+ * The file of `document`, or `undefined` when it is gone, cannot be read, or
112
+ * is not read within {@link readTimeoutMs}.
113
+ */
114
+ protected readFile(document: ResyncableEditorDocument): Promise<TextFileContent | undefined>;
115
+ /**
116
+ * Run `check`, and log its failure rather than pass it on. A will-save
117
+ * listener that rejects makes Theia drop the save without writing, and a
118
+ * sync that rejects goes unhandled.
119
+ */
120
+ protected isolate(check: () => Promise<void>): Promise<void>;
121
+ /** The dirty documents open in an editor on `uri`, each once however many editors show it. */
122
+ protected dirtyDocuments(uri: URI): ResyncableEditorDocument[];
123
+ /** `document` if it carries the members the sync resets; otherwise `undefined`, warned of once. */
124
+ protected resyncable(document: object): ResyncableEditorDocument | undefined;
125
+ /**
126
+ * Take `version` as the file `document` was last saved to, with nothing
127
+ * pending, and mark it clean. Synchronous throughout: a soft revert only
128
+ * marks the document clean, and reads nothing. The revert also cancels a
129
+ * save queued behind the sync, which would have written the same text.
130
+ */
131
+ protected syncFromDisk(document: ResyncableEditorDocument, version: FileResourceVersion): void;
132
+ }
133
+ //# sourceMappingURL=editor-disk-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor-disk-sync.d.ts","sourceRoot":"","sources":["../../src/browser/editor-disk-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAGlF,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,GAAG,MAAM,4BAA4B,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAC/F,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,WAAW,wBAAwB;IACtC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,OAAO,IAAI,MAAM,CAAC;IAClB,MAAM,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,+EAA+E;IAC/E,QAAQ,CAAC,cAAc,EAAE,OAAO,EAAE,CAAC;IACnC,8DAA8D;IAC9D,eAAe,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACjD,wEAAwE;IACxE,GAAG,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,8DAA8D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c,CAAC,GAAG,EAAE,GAAG,GAAG,wBAAwB,EAAE;IAY9D,mGAAmG;IACnG,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS;IAa5E;;;;;OAKG;IACH,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,wBAAwB,EAAE,OAAO,EAAE,mBAAmB,GAAG,IAAI;CAKhG"}
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (c) 2026 EclipseSource and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the MIT License which is available in the project root.
7
+ *
8
+ * SPDX-License-Identifier: MIT
9
+ ********************************************************************************/
10
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
11
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
12
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
13
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
14
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
15
+ };
16
+ var __metadata = (this && this.__metadata) || function (k, v) {
17
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
18
+ };
19
+ var __importDefault = (this && this.__importDefault) || function (mod) {
20
+ return (mod && mod.__esModule) ? mod : { "default": mod };
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.EditorDiskSync = void 0;
24
+ exports.isResyncableEditorDocument = isResyncableEditorDocument;
25
+ const protocol_1 = require("@hydranium/protocol");
26
+ const logger_1 = require("@theia/core/lib/common/logger");
27
+ const uri_1 = __importDefault(require("@theia/core/lib/common/uri"));
28
+ const inversify_1 = require("@theia/core/shared/inversify");
29
+ const editor_manager_1 = require("@theia/editor/lib/browser/editor-manager");
30
+ const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
31
+ const clock_1 = require("../common/clock");
32
+ /** Whether `document` carries the members of {@link ResyncableEditorDocument}. */
33
+ function isResyncableEditorDocument(document) {
34
+ return ('uri' in document &&
35
+ typeof document.uri === 'string' &&
36
+ 'dirty' in document &&
37
+ 'getText' in document &&
38
+ typeof document.getText === 'function' &&
39
+ 'revert' in document &&
40
+ typeof document.revert === 'function' &&
41
+ 'contentChanges' in document &&
42
+ Array.isArray(document.contentChanges) &&
43
+ 'resourceVersion' in document &&
44
+ 'run' in document &&
45
+ typeof document.run === 'function' &&
46
+ 'onModelWillSaveModel' in document &&
47
+ typeof document.onModelWillSaveModel === 'function');
48
+ }
49
+ /**
50
+ * Keeps a dirty editor's save from applying edits its file already holds, as
51
+ * the file does once the server saves a document the editor shows unsaved.
52
+ *
53
+ * Theia keeps such an editor dirty, and its next save corrupts the file: the
54
+ * save applies the editor's pending edits to the file rather than writing the
55
+ * whole text, and the file already holds them, so each is applied twice.
56
+ * Theia's check that the file has not changed since the editor read it passes
57
+ * whenever the new file has the old one's size, so no conflict is reported. A
58
+ * revert alone keeps the pending edits.
59
+ *
60
+ * Before each save of the editor it reads the file. When the file holds the
61
+ * text the buffer held as the save began, it drops the edits pending then and
62
+ * has the save expect the file's version, so the save writes only the edits
63
+ * made after that point, a save participant's included, onto the file as it
64
+ * is. The save is not cancelled: it completes and is reported as saved. Save
65
+ * All relies on this check, since it saves a diagram and then an editor on the
66
+ * same file at once, before the file watcher has reported the diagram's write.
67
+ * The buffer is taken when the save calls its will-save listeners. Theia runs
68
+ * its save participants one after another, each behind an await, and its
69
+ * first one awaits before it edits, so none has changed the buffer by then. A
70
+ * participant ordered ahead of it that edits before its first await makes the
71
+ * file and the taken text differ, and the save applies every edit again.
72
+ *
73
+ * On each change the file watcher reports, it marks the editor clean when the
74
+ * file holds exactly its buffer. The file is compared with the buffer after
75
+ * it has been read, and the editor is marked in the same step, so a keystroke
76
+ * made while the file was read leaves the editor dirty. This sync waits behind
77
+ * a save in flight: that save drops the edits it sent from the pending ones
78
+ * when it finishes, and a sync before then would have it drop the edits typed
79
+ * meanwhile.
80
+ *
81
+ * An editor whose file holds neither text is left to Theia's own save,
82
+ * same-size gap included, and so is one whose file cannot be read within
83
+ * {@link readTimeoutMs}, or whose check throws.
84
+ *
85
+ * The adopter binds it as a `FrontendApplicationContribution`.
86
+ */
87
+ let EditorDiskSync = class EditorDiskSync {
88
+ fileService;
89
+ editorManager;
90
+ logger;
91
+ /** Times {@link readTimeoutMs}: the container's {@link Clock}, or a `SystemClock`. */
92
+ clock = new protocol_1.SystemClock();
93
+ /** Whether an editor's document has failed {@link isResyncableEditorDocument}; warned of once. */
94
+ warnedUnsyncable = false;
95
+ /**
96
+ * How long a check waits for the file. The editor's save, and every later
97
+ * save and sync of that editor, waits for the check.
98
+ */
99
+ readTimeoutMs = 1_000;
100
+ onStart() {
101
+ this.fileService.onDidFilesChange(event => {
102
+ for (const change of event.changes) {
103
+ this.checkFile(change.resource);
104
+ }
105
+ });
106
+ this.editorManager.onCreated(widget => this.guardSaves(widget));
107
+ for (const widget of this.editorManager.all) {
108
+ this.guardSaves(widget);
109
+ }
110
+ }
111
+ /** Check `widget`'s document before each of its saves, for as long as the widget lives. */
112
+ guardSaves(widget) {
113
+ const document = this.resyncable(widget.editor.document);
114
+ if (document) {
115
+ const registration = document.onModelWillSaveModel(() => this.isolate(() => this.dropChangesOnDisk(document)));
116
+ widget.onDidDispose(() => registration.dispose());
117
+ }
118
+ }
119
+ /** Check each dirty document an editor shows on `uri`, behind that document's save in flight. */
120
+ checkFile(uri) {
121
+ for (const document of this.dirtyDocuments(uri)) {
122
+ void document.run(() => this.isolate(() => this.syncIfOnDisk(document)));
123
+ }
124
+ }
125
+ /** Read the file of `document` if it is dirty, and sync it if the file holds its buffer. */
126
+ async syncIfOnDisk(document) {
127
+ if (!document.dirty) {
128
+ return;
129
+ }
130
+ const content = await this.readFile(document);
131
+ if (content && document.getText() === content.value) {
132
+ this.syncFromDisk(document, { etag: content.etag, mtime: content.mtime, encoding: content.encoding });
133
+ }
134
+ }
135
+ /**
136
+ * Before a save of `document`, drop the edits pending now if its file holds
137
+ * the buffer as it is now, and take the file's version. The buffer and the
138
+ * count are taken before the first await, while the save is still calling
139
+ * its will-save listeners; an edit made after that stays pending, and the
140
+ * save writes it onto the file.
141
+ */
142
+ async dropChangesOnDisk(document) {
143
+ if (!document.dirty) {
144
+ return;
145
+ }
146
+ const text = document.getText();
147
+ const pending = document.contentChanges.length;
148
+ const content = await this.readFile(document);
149
+ if (content?.value === text) {
150
+ document.contentChanges.splice(0, pending);
151
+ document.resourceVersion = { etag: content.etag, mtime: content.mtime, encoding: content.encoding };
152
+ }
153
+ }
154
+ /**
155
+ * The file of `document`, or `undefined` when it is gone, cannot be read, or
156
+ * is not read within {@link readTimeoutMs}.
157
+ */
158
+ async readFile(document) {
159
+ const read = this.fileService.read(new uri_1.default(document.uri)).catch(() => undefined);
160
+ const content = await this.clock.raceTimer(read, this.readTimeoutMs);
161
+ return content === protocol_1.TIMED_OUT ? undefined : content;
162
+ }
163
+ /**
164
+ * Run `check`, and log its failure rather than pass it on. A will-save
165
+ * listener that rejects makes Theia drop the save without writing, and a
166
+ * sync that rejects goes unhandled.
167
+ */
168
+ async isolate(check) {
169
+ try {
170
+ await check();
171
+ }
172
+ catch (err) {
173
+ void this.logger.error('EditorDiskSync: checking an editor against its file failed; the editor is left as it is.', err);
174
+ }
175
+ }
176
+ /** The dirty documents open in an editor on `uri`, each once however many editors show it. */
177
+ dirtyDocuments(uri) {
178
+ const target = uri.toString();
179
+ const documents = new Set();
180
+ for (const widget of this.editorManager.all) {
181
+ const document = this.resyncable(widget.editor.document);
182
+ if (document && document.uri === target && document.dirty) {
183
+ documents.add(document);
184
+ }
185
+ }
186
+ return [...documents];
187
+ }
188
+ /** `document` if it carries the members the sync resets; otherwise `undefined`, warned of once. */
189
+ resyncable(document) {
190
+ if (isResyncableEditorDocument(document)) {
191
+ return document;
192
+ }
193
+ if (!this.warnedUnsyncable) {
194
+ this.warnedUnsyncable = true;
195
+ void this.logger.warn('EditorDiskSync: an editor document lacks the Monaco model members the sync resets, so such editors are not synced with their files.');
196
+ }
197
+ return undefined;
198
+ }
199
+ /**
200
+ * Take `version` as the file `document` was last saved to, with nothing
201
+ * pending, and mark it clean. Synchronous throughout: a soft revert only
202
+ * marks the document clean, and reads nothing. The revert also cancels a
203
+ * save queued behind the sync, which would have written the same text.
204
+ */
205
+ syncFromDisk(document, version) {
206
+ document.contentChanges.splice(0, document.contentChanges.length);
207
+ document.resourceVersion = version;
208
+ void document.revert({ soft: true });
209
+ }
210
+ };
211
+ exports.EditorDiskSync = EditorDiskSync;
212
+ __decorate([
213
+ (0, inversify_1.inject)(file_service_1.FileService),
214
+ __metadata("design:type", file_service_1.FileService)
215
+ ], EditorDiskSync.prototype, "fileService", void 0);
216
+ __decorate([
217
+ (0, inversify_1.inject)(editor_manager_1.EditorManager),
218
+ __metadata("design:type", editor_manager_1.EditorManager)
219
+ ], EditorDiskSync.prototype, "editorManager", void 0);
220
+ __decorate([
221
+ (0, inversify_1.inject)(logger_1.ILogger),
222
+ __metadata("design:type", Object)
223
+ ], EditorDiskSync.prototype, "logger", void 0);
224
+ __decorate([
225
+ (0, inversify_1.inject)(clock_1.Clock),
226
+ (0, inversify_1.optional)(),
227
+ __metadata("design:type", Object)
228
+ ], EditorDiskSync.prototype, "clock", void 0);
229
+ exports.EditorDiskSync = EditorDiskSync = __decorate([
230
+ (0, inversify_1.injectable)()
231
+ ], EditorDiskSync);
232
+ //# sourceMappingURL=editor-disk-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor-disk-sync.js","sourceRoot":"","sources":["../../src/browser/editor-disk-sync.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;AAoClF,gEAiBC;AAnDD,kDAA6D;AAE7D,0DAAwD;AACxD,qEAA6C;AAC7C,4DAA4E;AAC5E,6EAA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AC,CAAC;QAClE,QAAQ,CAAC,eAAe,GAAG,OAAO,CAAC;QACnC,KAAK,QAAQ,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,CAAC;CACH,CAAA;AAtIY,wCAAc;AACgB;IAAvC,IAAA,kBAAM,EAAC,0BAAW,CAAC;8BAAkC,0BAAW;mDAAC;AACxB;IAAzC,IAAA,kBAAM,EAAC,8BAAa,CAAC;8BAAoC,8BAAa;qDAAC;AACpC;IAAnC,IAAA,kBAAM,EAAC,gBAAO,CAAC;;8CAAqC;AAEP;IAA7C,IAAA,kBAAM,EAAC,aAAK,CAAC;IAAE,IAAA,oBAAQ,GAAE;;6CAAqD;yBALrE,cAAc;IAD1B,IAAA,sBAAU,GAAE;GACA,cAAc,CAsI1B"}
@@ -0,0 +1,44 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2026 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the MIT License which is available in the project root.
6
+ *
7
+ * SPDX-License-Identifier: MIT
8
+ ********************************************************************************/
9
+ import type URI from '@theia/core/lib/common/uri';
10
+ import { FileService, type UpdateTextFileOptions } from '@theia/filesystem/lib/browser/file-service';
11
+ /**
12
+ * Theia's `FileService`, refusing an incremental save once the file has
13
+ * changed since the editor read it.
14
+ *
15
+ * Theia's own check, which `write` and `update` share, passes a file whose
16
+ * mtime moved on when its size still matches the etag the editor read. That
17
+ * is safe for `write`, which replaces the file with the whole text, but
18
+ * `update` applies the editor's pending edits to the file as it is, so after a
19
+ * same-size change, the server saving those very edits included, it applies
20
+ * them a second time. Here `update` hands that check the etag with a `!`
21
+ * appended, which no file's etag can match: Theia writes an etag as the mtime
22
+ * in base 29 followed by the size in base 31, digits and lower-case letters
23
+ * only. An advanced mtime is then enough for Theia to refuse with its
24
+ * `FILE_MODIFIED_SINCE`. The editor's save then falls back to `write` with the
25
+ * whole text, which Theia checks as before: it writes when the size is
26
+ * unchanged, and asks the user otherwise. A same-size change by another
27
+ * process is therefore overwritten by that write rather than merged with the
28
+ * editor's edits. `write` is left as it is.
29
+ *
30
+ * It is the safety net behind `EditorDiskSync`, which acts only when the
31
+ * file holds the editor's buffer: a file holding some of the edits, as when a
32
+ * save participant ordered ahead of Theia's first one edits before its first
33
+ * await, is left to this check.
34
+ *
35
+ * A write within the file system's mtime resolution of the read goes unseen,
36
+ * as it does for Theia's own check. A file whose mtime moves while its text
37
+ * stays the same costs a whole-text write rather than the edits.
38
+ *
39
+ * The adopter binds it with `rebind(FileService).to(HydraniumFileService).inSingletonScope()`.
40
+ */
41
+ export declare class HydraniumFileService extends FileService {
42
+ update(resource: URI, changes: Parameters<FileService['update']>[1], options: UpdateTextFileOptions): ReturnType<FileService['update']>;
43
+ }
44
+ //# sourceMappingURL=hydranium-file-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydranium-file-service.d.ts","sourceRoot":"","sources":["../../src/browser/hydranium-file-service.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,GAAG,MAAM,4BAA4B,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,KAAK,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AAGrG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBACa,oBAAqB,SAAQ,WAAW;IACzC,MAAM,CACZ,QAAQ,EAAE,GAAG,EACb,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAC7C,OAAO,EAAE,qBAAqB,GAC9B,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;CAKtC"}