@hydranium/client-theia 1.0.0-next.39 → 1.0.0-next.390

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 (95) hide show
  1. package/README.md +53 -81
  2. package/lib/browser/browser-capture.js.map +1 -1
  3. package/lib/browser/channel-logger.d.ts +4 -3
  4. package/lib/browser/channel-logger.d.ts.map +1 -1
  5. package/lib/browser/channel-logger.js +11 -19
  6. package/lib/browser/channel-logger.js.map +1 -1
  7. package/lib/browser/connection-diagnostics-contribution.d.ts +73 -0
  8. package/lib/browser/connection-diagnostics-contribution.d.ts.map +1 -0
  9. package/lib/browser/connection-diagnostics-contribution.js +162 -0
  10. package/lib/browser/connection-diagnostics-contribution.js.map +1 -0
  11. package/lib/browser/connection-reporter.d.ts +57 -0
  12. package/lib/browser/connection-reporter.d.ts.map +1 -0
  13. package/lib/browser/connection-reporter.js +104 -0
  14. package/lib/browser/connection-reporter.js.map +1 -0
  15. package/lib/browser/editor-disk-sync.d.ts +142 -0
  16. package/lib/browser/editor-disk-sync.d.ts.map +1 -0
  17. package/lib/browser/editor-disk-sync.js +250 -0
  18. package/lib/browser/editor-disk-sync.js.map +1 -0
  19. package/lib/browser/hydranium-file-service.d.ts +44 -0
  20. package/lib/browser/hydranium-file-service.d.ts.map +1 -0
  21. package/lib/browser/hydranium-file-service.js +61 -0
  22. package/lib/browser/hydranium-file-service.js.map +1 -0
  23. package/lib/browser/index.d.ts +5 -0
  24. package/lib/browser/index.d.ts.map +1 -1
  25. package/lib/browser/index.js +5 -0
  26. package/lib/browser/index.js.map +1 -1
  27. package/lib/browser/log-level-preference.d.ts.map +1 -1
  28. package/lib/browser/log-level-preference.js +11 -0
  29. package/lib/browser/log-level-preference.js.map +1 -1
  30. package/lib/browser/memory-diagnostics-contribution.d.ts +1 -1
  31. package/lib/browser/memory-diagnostics-contribution.d.ts.map +1 -1
  32. package/lib/browser/memory-diagnostics-contribution.js +1 -1
  33. package/lib/browser/memory-diagnostics-contribution.js.map +1 -1
  34. package/lib/browser/session-aware-connection-source.d.ts +104 -0
  35. package/lib/browser/session-aware-connection-source.d.ts.map +1 -0
  36. package/lib/browser/session-aware-connection-source.js +193 -0
  37. package/lib/browser/session-aware-connection-source.js.map +1 -0
  38. package/lib/common/clock.d.ts +19 -0
  39. package/lib/common/clock.d.ts.map +1 -0
  40. package/lib/common/clock.js +13 -0
  41. package/lib/common/clock.js.map +1 -0
  42. package/lib/common/connection-resilience-options.d.ts +30 -0
  43. package/lib/common/connection-resilience-options.d.ts.map +1 -0
  44. package/lib/common/connection-resilience-options.js +11 -0
  45. package/lib/common/connection-resilience-options.js.map +1 -0
  46. package/lib/common/framed-socket-write-buffer.d.ts +173 -0
  47. package/lib/common/framed-socket-write-buffer.d.ts.map +1 -0
  48. package/lib/common/framed-socket-write-buffer.js +293 -0
  49. package/lib/common/framed-socket-write-buffer.js.map +1 -0
  50. package/lib/common/inbound-message-sequence.d.ts +56 -0
  51. package/lib/common/inbound-message-sequence.d.ts.map +1 -0
  52. package/lib/common/inbound-message-sequence.js +98 -0
  53. package/lib/common/inbound-message-sequence.js.map +1 -0
  54. package/lib/common/index.d.ts +13 -0
  55. package/lib/common/index.d.ts.map +1 -0
  56. package/lib/common/index.js +32 -0
  57. package/lib/common/index.js.map +1 -0
  58. package/lib/node/abstract-socket-forwarding-connection-handler.d.ts +16 -12
  59. package/lib/node/abstract-socket-forwarding-connection-handler.d.ts.map +1 -1
  60. package/lib/node/abstract-socket-forwarding-connection-handler.js +94 -31
  61. package/lib/node/abstract-socket-forwarding-connection-handler.js.map +1 -1
  62. package/lib/node/index.d.ts +2 -0
  63. package/lib/node/index.d.ts.map +1 -1
  64. package/lib/node/index.js +2 -0
  65. package/lib/node/index.js.map +1 -1
  66. package/lib/node/session-bound-frontend-connection-service.d.ts +122 -0
  67. package/lib/node/session-bound-frontend-connection-service.d.ts.map +1 -0
  68. package/lib/node/session-bound-frontend-connection-service.js +236 -0
  69. package/lib/node/session-bound-frontend-connection-service.js.map +1 -0
  70. package/lib/node/socket-channel-forwarder.d.ts +54 -0
  71. package/lib/node/socket-channel-forwarder.d.ts.map +1 -0
  72. package/lib/node/socket-channel-forwarder.js +95 -0
  73. package/lib/node/socket-channel-forwarder.js.map +1 -0
  74. package/lib/testing/stub-inversify-context.js.map +1 -1
  75. package/lib/testing/stub-output-channel.js.map +1 -1
  76. package/package.json +33 -34
  77. package/src/browser/browser-capture.ts +1 -1
  78. package/src/browser/channel-logger.ts +11 -19
  79. package/src/browser/connection-diagnostics-contribution.ts +146 -0
  80. package/src/browser/connection-reporter.ts +121 -0
  81. package/src/browser/editor-disk-sync.ts +253 -0
  82. package/src/browser/hydranium-file-service.ts +56 -0
  83. package/src/browser/index.ts +5 -0
  84. package/src/browser/log-level-preference.ts +11 -0
  85. package/src/browser/memory-diagnostics-contribution.ts +4 -3
  86. package/src/browser/session-aware-connection-source.ts +205 -0
  87. package/src/common/clock.ts +20 -0
  88. package/src/common/connection-resilience-options.ts +30 -0
  89. package/src/common/framed-socket-write-buffer.ts +345 -0
  90. package/src/common/inbound-message-sequence.ts +102 -0
  91. package/src/common/index.ts +16 -0
  92. package/src/node/abstract-socket-forwarding-connection-handler.ts +85 -36
  93. package/src/node/index.ts +2 -0
  94. package/src/node/session-bound-frontend-connection-service.ts +264 -0
  95. package/src/node/socket-channel-forwarder.ts +101 -0
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (c) 2026 CrossBreeze, 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
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.DefaultConnectionReporter = exports.ConnectionReporter = void 0;
21
+ exports.bindConnectionReporter = bindConnectionReporter;
22
+ const core_1 = require("@theia/core");
23
+ const inversify_1 = require("@theia/core/shared/inversify");
24
+ exports.ConnectionReporter = Symbol('ConnectionReporter');
25
+ /**
26
+ * Reports through Theia notifications: an attempt still running after
27
+ * {@link connectingNoticeDelayMs} shows its progress, and an attempt ends in at
28
+ * most one notification. A failure is shown once per target until it connects
29
+ * again, so a head that keeps retrying does not raise one per attempt.
30
+ */
31
+ let DefaultConnectionReporter = class DefaultConnectionReporter {
32
+ messageService;
33
+ connectingNoticeDelayMs = 3_000;
34
+ /** Targets whose last reported attempt failed. */
35
+ failing = new Set();
36
+ connecting(target) {
37
+ let progress;
38
+ const notice = this.failing.has(target)
39
+ ? undefined
40
+ : setTimeout(() => (progress = this.showConnecting(target)), this.connectingNoticeDelayMs);
41
+ let settled = false;
42
+ const settle = () => {
43
+ if (settled) {
44
+ return false;
45
+ }
46
+ settled = true;
47
+ clearTimeout(notice);
48
+ void progress?.then(shown => shown.cancel());
49
+ return true;
50
+ };
51
+ return {
52
+ connected: () => {
53
+ if (settle() && (this.failing.delete(target) || progress)) {
54
+ this.showConnected(target);
55
+ }
56
+ },
57
+ cancelled: () => {
58
+ settle();
59
+ },
60
+ failed: (message, retry) => {
61
+ if (settle() && !this.failing.has(target)) {
62
+ this.failing.add(target);
63
+ void this.showFailed(target, message, retry);
64
+ }
65
+ }
66
+ };
67
+ }
68
+ showConnecting(target) {
69
+ return this.messageService.showProgress({ text: target.connectingMessage });
70
+ }
71
+ showConnected(target) {
72
+ this.messageService.info(target.connectedMessage);
73
+ }
74
+ async showFailed(target, message, retry) {
75
+ if (!retry) {
76
+ this.messageService.error(message);
77
+ return;
78
+ }
79
+ const label = this.retryLabel();
80
+ if ((await this.messageService.error(message, label)) === label) {
81
+ // The retried attempt reports afresh, progress included.
82
+ this.failing.delete(target);
83
+ retry();
84
+ }
85
+ }
86
+ retryLabel() {
87
+ return core_1.nls.localize('hydranium/client-theia/connection-retry', 'Retry');
88
+ }
89
+ };
90
+ exports.DefaultConnectionReporter = DefaultConnectionReporter;
91
+ __decorate([
92
+ (0, inversify_1.inject)(core_1.MessageService),
93
+ __metadata("design:type", core_1.MessageService)
94
+ ], DefaultConnectionReporter.prototype, "messageService", void 0);
95
+ exports.DefaultConnectionReporter = DefaultConnectionReporter = __decorate([
96
+ (0, inversify_1.injectable)()
97
+ ], DefaultConnectionReporter);
98
+ /** Bind {@link DefaultConnectionReporter} unless the slot is bound already; every head calls this. */
99
+ function bindConnectionReporter(bind, isBound) {
100
+ if (!isBound(exports.ConnectionReporter)) {
101
+ bind(exports.ConnectionReporter).to(DefaultConnectionReporter).inSingletonScope();
102
+ }
103
+ }
104
+ //# sourceMappingURL=connection-reporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-reporter.js","sourceRoot":"","sources":["../../src/browser/connection-reporter.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;AAElF,sCAAiE;AACjE,4DAAmF;AA8BtE,QAAA,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAE/D;;;;;GAKG;AAEI,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACQ,cAAc,CAAkB;IAExD,uBAAuB,GAAW,KAAK,CAAC;IAC3D,kDAAkD;IAC/B,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEzD,UAAU,CAAC,MAAwB;QAChC,IAAI,QAAuC,CAAC;Q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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 { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application-contribution';
10
+ import { ILogger } from '@theia/core/lib/common/logger';
11
+ import URI from '@theia/core/lib/common/uri';
12
+ import { type interfaces } from '@theia/core/shared/inversify';
13
+ import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
14
+ import type { EditorWidget } from '@theia/editor/lib/browser/editor-widget';
15
+ import type { FileResourceVersion } from '@theia/filesystem/lib/browser/file-resource';
16
+ import { FileService, type TextFileContent } from '@theia/filesystem/lib/browser/file-service';
17
+ import { Clock } from '../common/clock';
18
+ /**
19
+ * The members of Theia's Monaco editor model {@link EditorDiskSync} reads and
20
+ * resets. `contentChanges`, `resourceVersion` and `run` are `protected` there,
21
+ * so {@link isResyncableEditorDocument} checks for them at runtime: a Theia
22
+ * that renames them yields a document it refuses, and the sync then leaves it
23
+ * alone.
24
+ */
25
+ export interface ResyncableEditorDocument {
26
+ readonly uri: string;
27
+ readonly dirty: boolean;
28
+ getText(): string;
29
+ revert(options: {
30
+ soft: boolean;
31
+ }): Promise<void>;
32
+ /** The edits the next save applies to the file, in place of the whole text. */
33
+ readonly contentChanges: unknown[];
34
+ /** The file version the next save expects to find on disk. */
35
+ resourceVersion: FileResourceVersion | undefined;
36
+ /** Queue `operation` behind the model's saves and syncs in progress. */
37
+ run(operation: () => Promise<void>): Promise<void>;
38
+ /** Awaited by each save before it takes the pending edits. */
39
+ onModelWillSaveModel(listener: () => Promise<void>): {
40
+ dispose(): void;
41
+ };
42
+ }
43
+ /** Whether `document` carries the members of {@link ResyncableEditorDocument}. */
44
+ export declare function isResyncableEditorDocument(document: object): document is ResyncableEditorDocument;
45
+ /**
46
+ * Keeps a dirty editor's save from applying edits its file already holds, as
47
+ * the file does once the server saves a document the editor shows unsaved.
48
+ *
49
+ * Theia keeps such an editor dirty, and its next save corrupts the file: the
50
+ * save applies the editor's pending edits to the file rather than writing the
51
+ * whole text, and the file already holds them, so each is applied twice.
52
+ * Theia's check that the file has not changed since the editor read it passes
53
+ * whenever the new file has the old one's size, so no conflict is reported. A
54
+ * revert alone keeps the pending edits.
55
+ *
56
+ * Before each save of the editor it reads the file. When the file holds the
57
+ * text the buffer held as the save began, it drops the edits pending then and
58
+ * has the save expect the file's version, so the save writes only the edits
59
+ * made after that point, a save participant's included, onto the file as it
60
+ * is. The save is not cancelled: it completes and is reported as saved. Save
61
+ * All relies on this check, since it saves a diagram and then an editor on the
62
+ * same file at once, before the file watcher has reported the diagram's write.
63
+ * The buffer is taken when the save calls its will-save listeners. Theia runs
64
+ * its save participants one after another, each behind an await, and its
65
+ * first one awaits before it edits, so none has changed the buffer by then. A
66
+ * participant ordered ahead of it that edits before its first await makes the
67
+ * file and the taken text differ, and the save applies every edit again.
68
+ *
69
+ * On each change the file watcher reports, it marks the editor clean when the
70
+ * file holds exactly its buffer. The file is compared with the buffer after
71
+ * it has been read, and the editor is marked in the same step, so a keystroke
72
+ * made while the file was read leaves the editor dirty. This sync waits behind
73
+ * a save in flight: that save drops the edits it sent from the pending ones
74
+ * when it finishes, and a sync before then would have it drop the edits typed
75
+ * meanwhile.
76
+ *
77
+ * An editor whose file holds neither text is left to Theia's own save,
78
+ * same-size gap included, and so is one whose file cannot be read within
79
+ * {@link readTimeoutMs}, or whose check throws.
80
+ *
81
+ * Bound by {@link bindEditorDiskSync}.
82
+ */
83
+ export declare class EditorDiskSync implements FrontendApplicationContribution {
84
+ protected readonly fileService: FileService;
85
+ protected readonly editorManager: EditorManager;
86
+ protected readonly logger: ILogger;
87
+ /** Times {@link readTimeoutMs}: the container's {@link Clock}, or a `SystemClock`. */
88
+ protected readonly clock: Clock;
89
+ /** Whether an editor's document has failed {@link isResyncableEditorDocument}; warned of once. */
90
+ protected warnedUnsyncable: boolean;
91
+ /**
92
+ * How long a check waits for the file. The editor's save, and every later
93
+ * save and sync of that editor, waits for the check.
94
+ */
95
+ protected readTimeoutMs: number;
96
+ onStart(): void;
97
+ /** Check `widget`'s document before each of its saves, for as long as the widget lives. */
98
+ protected guardSaves(widget: EditorWidget): void;
99
+ /** Check each dirty document an editor shows on `uri`, behind that document's save in flight. */
100
+ protected checkFile(uri: URI): void;
101
+ /** Read the file of `document` if it is dirty, and sync it if the file holds its buffer. */
102
+ protected syncIfOnDisk(document: ResyncableEditorDocument): Promise<void>;
103
+ /**
104
+ * Before a save of `document`, drop the edits pending now if its file holds
105
+ * the buffer as it is now, and take the file's version. The buffer and the
106
+ * count are taken before the first await, while the save is still calling
107
+ * its will-save listeners; an edit made after that stays pending, and the
108
+ * save writes it onto the file.
109
+ */
110
+ protected dropChangesOnDisk(document: ResyncableEditorDocument): Promise<void>;
111
+ /**
112
+ * The file of `document`, or `undefined` when it is gone, cannot be read, or
113
+ * is not read within {@link readTimeoutMs}.
114
+ */
115
+ protected readFile(document: ResyncableEditorDocument): Promise<TextFileContent | undefined>;
116
+ /**
117
+ * Run `check`, and log its failure rather than pass it on. A will-save
118
+ * listener that rejects makes Theia drop the save without writing, and a
119
+ * sync that rejects goes unhandled.
120
+ */
121
+ protected isolate(check: () => Promise<void>): Promise<void>;
122
+ /** The dirty documents open in an editor on `uri`, each once however many editors show it. */
123
+ protected dirtyDocuments(uri: URI): ResyncableEditorDocument[];
124
+ /** `document` if it carries the members the sync resets; otherwise `undefined`, warned of once. */
125
+ protected resyncable(document: object): ResyncableEditorDocument | undefined;
126
+ /**
127
+ * Take `version` as the file `document` was last saved to, with nothing
128
+ * pending, and mark it clean. Synchronous throughout: a soft revert only
129
+ * marks the document clean, and reads nothing. The revert also cancels a
130
+ * save queued behind the sync, which would have written the same text.
131
+ */
132
+ protected syncFromDisk(document: ResyncableEditorDocument, version: FileResourceVersion): void;
133
+ }
134
+ /**
135
+ * Bind {@link EditorDiskSync} as a frontend contribution and rebind Theia's
136
+ * `FileService` to {@link HydraniumFileService}, unless `EditorDiskSync` is
137
+ * bound already. No framework module calls this, because the rebind would
138
+ * replace a frontend's own `FileService` binding. A subclass of the sync is
139
+ * rebound after this call: one bound before it skips the whole call.
140
+ */
141
+ export declare function bindEditorDiskSync(bind: interfaces.Bind, isBound: interfaces.IsBound, rebind: interfaces.Rebind): void;
142
+ //# 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,EAAE,+BAA+B,EAAE,MAAM,2DAA2D,CAAC;AAC5G,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,GAAG,MAAM,4BAA4B,CAAC;AAC7C,OAAO,EAAgC,KAAK,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC7F,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;AAGxC;;;;;;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,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wB,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC,CAIjG;IAED;;;;OAIG;IACH,UAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAMjE;IAED,8FAA8F;IAC9F,SAAS,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,wBAAwB,EAAE,CAU7D;IAED,mGAAmG;IACnG,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAW3E;IAED;;;;;OAKG;IACH,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,wBAAwB,EAAE,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAI7F;CACH;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,GAAG,IAAI,CAOtH"}
@@ -0,0 +1,250 @@
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
+ exports.bindEditorDiskSync = bindEditorDiskSync;
26
+ const protocol_1 = require("@hydranium/protocol");
27
+ const frontend_application_contribution_1 = require("@theia/core/lib/browser/frontend-application-contribution");
28
+ const logger_1 = require("@theia/core/lib/common/logger");
29
+ const uri_1 = __importDefault(require("@theia/core/lib/common/uri"));
30
+ const inversify_1 = require("@theia/core/shared/inversify");
31
+ const editor_manager_1 = require("@theia/editor/lib/browser/editor-manager");
32
+ const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
33
+ const clock_1 = require("../common/clock");
34
+ const hydranium_file_service_1 = require("./hydranium-file-service");
35
+ /** Whether `document` carries the members of {@link ResyncableEditorDocument}. */
36
+ function isResyncableEditorDocument(document) {
37
+ return ('uri' in document &&
38
+ typeof document.uri === 'string' &&
39
+ 'dirty' in document &&
40
+ 'getText' in document &&
41
+ typeof document.getText === 'function' &&
42
+ 'revert' in document &&
43
+ typeof document.revert === 'function' &&
44
+ 'contentChanges' in document &&
45
+ Array.isArray(document.contentChanges) &&
46
+ 'resourceVersion' in document &&
47
+ 'run' in document &&
48
+ typeof document.run === 'function' &&
49
+ 'onModelWillSaveModel' in document &&
50
+ typeof document.onModelWillSaveModel === 'function');
51
+ }
52
+ /**
53
+ * Keeps a dirty editor's save from applying edits its file already holds, as
54
+ * the file does once the server saves a document the editor shows unsaved.
55
+ *
56
+ * Theia keeps such an editor dirty, and its next save corrupts the file: the
57
+ * save applies the editor's pending edits to the file rather than writing the
58
+ * whole text, and the file already holds them, so each is applied twice.
59
+ * Theia's check that the file has not changed since the editor read it passes
60
+ * whenever the new file has the old one's size, so no conflict is reported. A
61
+ * revert alone keeps the pending edits.
62
+ *
63
+ * Before each save of the editor it reads the file. When the file holds the
64
+ * text the buffer held as the save began, it drops the edits pending then and
65
+ * has the save expect the file's version, so the save writes only the edits
66
+ * made after that point, a save participant's included, onto the file as it
67
+ * is. The save is not cancelled: it completes and is reported as saved. Save
68
+ * All relies on this check, since it saves a diagram and then an editor on the
69
+ * same file at once, before the file watcher has reported the diagram's write.
70
+ * The buffer is taken when the save calls its will-save listeners. Theia runs
71
+ * its save participants one after another, each behind an await, and its
72
+ * first one awaits before it edits, so none has changed the buffer by then. A
73
+ * participant ordered ahead of it that edits before its first await makes the
74
+ * file and the taken text differ, and the save applies every edit again.
75
+ *
76
+ * On each change the file watcher reports, it marks the editor clean when the
77
+ * file holds exactly its buffer. The file is compared with the buffer after
78
+ * it has been read, and the editor is marked in the same step, so a keystroke
79
+ * made while the file was read leaves the editor dirty. This sync waits behind
80
+ * a save in flight: that save drops the edits it sent from the pending ones
81
+ * when it finishes, and a sync before then would have it drop the edits typed
82
+ * meanwhile.
83
+ *
84
+ * An editor whose file holds neither text is left to Theia's own save,
85
+ * same-size gap included, and so is one whose file cannot be read within
86
+ * {@link readTimeoutMs}, or whose check throws.
87
+ *
88
+ * Bound by {@link bindEditorDiskSync}.
89
+ */
90
+ let EditorDiskSync = class EditorDiskSync {
91
+ fileService;
92
+ editorManager;
93
+ logger;
94
+ /** Times {@link readTimeoutMs}: the container's {@link Clock}, or a `SystemClock`. */
95
+ clock = new protocol_1.SystemClock();
96
+ /** Whether an editor's document has failed {@link isResyncableEditorDocument}; warned of once. */
97
+ warnedUnsyncable = false;
98
+ /**
99
+ * How long a check waits for the file. The editor's save, and every later
100
+ * save and sync of that editor, waits for the check.
101
+ */
102
+ readTimeoutMs = 1_000;
103
+ onStart() {
104
+ this.fileService.onDidFilesChange(event => {
105
+ for (const change of event.changes) {
106
+ this.checkFile(change.resource);
107
+ }
108
+ });
109
+ this.editorManager.onCreated(widget => this.guardSaves(widget));
110
+ for (const widget of this.editorManager.all) {
111
+ this.guardSaves(widget);
112
+ }
113
+ }
114
+ /** Check `widget`'s document before each of its saves, for as long as the widget lives. */
115
+ guardSaves(widget) {
116
+ const document = this.resyncable(widget.editor.document);
117
+ if (document) {
118
+ const registration = document.onModelWillSaveModel(() => this.isolate(() => this.dropChangesOnDisk(document)));
119
+ widget.onDidDispose(() => registration.dispose());
120
+ }
121
+ }
122
+ /** Check each dirty document an editor shows on `uri`, behind that document's save in flight. */
123
+ checkFile(uri) {
124
+ for (const document of this.dirtyDocuments(uri)) {
125
+ void document.run(() => this.isolate(() => this.syncIfOnDisk(document)));
126
+ }
127
+ }
128
+ /** Read the file of `document` if it is dirty, and sync it if the file holds its buffer. */
129
+ async syncIfOnDisk(document) {
130
+ if (!document.dirty) {
131
+ return;
132
+ }
133
+ const content = await this.readFile(document);
134
+ if (content && document.getText() === content.value) {
135
+ this.syncFromDisk(document, { etag: content.etag, mtime: content.mtime, encoding: content.encoding });
136
+ }
137
+ }
138
+ /**
139
+ * Before a save of `document`, drop the edits pending now if its file holds
140
+ * the buffer as it is now, and take the file's version. The buffer and the
141
+ * count are taken before the first await, while the save is still calling
142
+ * its will-save listeners; an edit made after that stays pending, and the
143
+ * save writes it onto the file.
144
+ */
145
+ async dropChangesOnDisk(document) {
146
+ if (!document.dirty) {
147
+ return;
148
+ }
149
+ const text = document.getText();
150
+ const pending = document.contentChanges.length;
151
+ const content = await this.readFile(document);
152
+ if (content?.value === text) {
153
+ document.contentChanges.splice(0, pending);
154
+ document.resourceVersion = { etag: content.etag, mtime: content.mtime, encoding: content.encoding };
155
+ }
156
+ }
157
+ /**
158
+ * The file of `document`, or `undefined` when it is gone, cannot be read, or
159
+ * is not read within {@link readTimeoutMs}.
160
+ */
161
+ async readFile(document) {
162
+ const read = this.fileService.read(new uri_1.default(document.uri)).catch(() => undefined);
163
+ const content = await this.clock.raceTimer(read, this.readTimeoutMs);
164
+ return content === protocol_1.TIMED_OUT ? undefined : content;
165
+ }
166
+ /**
167
+ * Run `check`, and log its failure rather than pass it on. A will-save
168
+ * listener that rejects makes Theia drop the save without writing, and a
169
+ * sync that rejects goes unhandled.
170
+ */
171
+ async isolate(check) {
172
+ try {
173
+ await check();
174
+ }
175
+ catch (err) {
176
+ void this.logger.error('EditorDiskSync: checking an editor against its file failed; the editor is left as it is.', err);
177
+ }
178
+ }
179
+ /** The dirty documents open in an editor on `uri`, each once however many editors show it. */
180
+ dirtyDocuments(uri) {
181
+ const target = uri.toString();
182
+ const documents = new Set();
183
+ for (const widget of this.editorManager.all) {
184
+ const document = this.resyncable(widget.editor.document);
185
+ if (document && document.uri === target && document.dirty) {
186
+ documents.add(document);
187
+ }
188
+ }
189
+ return [...documents];
190
+ }
191
+ /** `document` if it carries the members the sync resets; otherwise `undefined`, warned of once. */
192
+ resyncable(document) {
193
+ if (isResyncableEditorDocument(document)) {
194
+ return document;
195
+ }
196
+ if (!this.warnedUnsyncable) {
197
+ this.warnedUnsyncable = true;
198
+ 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.');
199
+ }
200
+ return undefined;
201
+ }
202
+ /**
203
+ * Take `version` as the file `document` was last saved to, with nothing
204
+ * pending, and mark it clean. Synchronous throughout: a soft revert only
205
+ * marks the document clean, and reads nothing. The revert also cancels a
206
+ * save queued behind the sync, which would have written the same text.
207
+ */
208
+ syncFromDisk(document, version) {
209
+ document.contentChanges.splice(0, document.contentChanges.length);
210
+ document.resourceVersion = version;
211
+ void document.revert({ soft: true });
212
+ }
213
+ };
214
+ exports.EditorDiskSync = EditorDiskSync;
215
+ __decorate([
216
+ (0, inversify_1.inject)(file_service_1.FileService),
217
+ __metadata("design:type", file_service_1.FileService)
218
+ ], EditorDiskSync.prototype, "fileService", void 0);
219
+ __decorate([
220
+ (0, inversify_1.inject)(editor_manager_1.EditorManager),
221
+ __metadata("design:type", editor_manager_1.EditorManager)
222
+ ], EditorDiskSync.prototype, "editorManager", void 0);
223
+ __decorate([
224
+ (0, inversify_1.inject)(logger_1.ILogger),
225
+ __metadata("design:type", Object)
226
+ ], EditorDiskSync.prototype, "logger", void 0);
227
+ __decorate([
228
+ (0, inversify_1.inject)(clock_1.Clock),
229
+ (0, inversify_1.optional)(),
230
+ __metadata("design:type", Object)
231
+ ], EditorDiskSync.prototype, "clock", void 0);
232
+ exports.EditorDiskSync = EditorDiskSync = __decorate([
233
+ (0, inversify_1.injectable)()
234
+ ], EditorDiskSync);
235
+ /**
236
+ * Bind {@link EditorDiskSync} as a frontend contribution and rebind Theia's
237
+ * `FileService` to {@link HydraniumFileService}, unless `EditorDiskSync` is
238
+ * bound already. No framework module calls this, because the rebind would
239
+ * replace a frontend's own `FileService` binding. A subclass of the sync is
240
+ * rebound after this call: one bound before it skips the whole call.
241
+ */
242
+ function bindEditorDiskSync(bind, isBound, rebind) {
243
+ if (isBound(EditorDiskSync)) {
244
+ return;
245
+ }
246
+ bind(EditorDiskSync).toSelf().inSingletonScope();
247
+ bind(frontend_application_contribution_1.FrontendApplicationContribution).toService(EditorDiskSync);
248
+ rebind(file_service_1.FileService).to(hydranium_file_service_1.HydraniumFileService).inSingletonScope();
249
+ }
250
+ //# 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;;;;;;;;;;;;;;;;;AAElF,kDAA6D;AAC7D,iHAA4G;AAC5G,0DAAwD;AACxD,qEAA6C;AAC7C,4DAA6F;AAC7F,6EAAyE;AAGzE,6EAA+F;AAC/F,2CAAwC;AACxC,qEAAgE;AAwBhE,kFAAkF;AAClF,oCAA2C,QAAgB;IACxD,OAAO,CACJ,KAAK,IAAI,QAAQ;QACjB,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ;QAChC,OAAO,IAAI,QAAQ;QACnB,SAAS,IAAI,QAAQ;QACrB,OAAO,QAAQ,CAAC,OAAO,KAAK,UAAU;QACtC,QAAQ,IAAI,QAAQ;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DAAC;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;AAED;;;;;;GAMG;AACH,4BAAmC,IAAqB,EAAE,OAA2B,EAAE,MAAyB;IAC7G,IAAI,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QAC3B,OAAO;IACV,CAAC;IACD,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACjD,IAAI,CAAC,mEAA+B,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAChE,MAAM,CAAC,0BAAW,CAAC,CAAC,EAAE,CAAC,6CAAoB,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACnE,CAAC"}
@@ -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
+ * Bound by `bindEditorDiskSync`.
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,CAInC;CACH"}
@@ -0,0 +1,61 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.HydraniumFileService = void 0;
18
+ const inversify_1 = require("@theia/core/shared/inversify");
19
+ const file_service_1 = require("@theia/filesystem/lib/browser/file-service");
20
+ const files_1 = require("@theia/filesystem/lib/common/files");
21
+ /**
22
+ * Theia's `FileService`, refusing an incremental save once the file has
23
+ * changed since the editor read it.
24
+ *
25
+ * Theia's own check, which `write` and `update` share, passes a file whose
26
+ * mtime moved on when its size still matches the etag the editor read. That
27
+ * is safe for `write`, which replaces the file with the whole text, but
28
+ * `update` applies the editor's pending edits to the file as it is, so after a
29
+ * same-size change, the server saving those very edits included, it applies
30
+ * them a second time. Here `update` hands that check the etag with a `!`
31
+ * appended, which no file's etag can match: Theia writes an etag as the mtime
32
+ * in base 29 followed by the size in base 31, digits and lower-case letters
33
+ * only. An advanced mtime is then enough for Theia to refuse with its
34
+ * `FILE_MODIFIED_SINCE`. The editor's save then falls back to `write` with the
35
+ * whole text, which Theia checks as before: it writes when the size is
36
+ * unchanged, and asks the user otherwise. A same-size change by another
37
+ * process is therefore overwritten by that write rather than merged with the
38
+ * editor's edits. `write` is left as it is.
39
+ *
40
+ * It is the safety net behind `EditorDiskSync`, which acts only when the
41
+ * file holds the editor's buffer: a file holding some of the edits, as when a
42
+ * save participant ordered ahead of Theia's first one edits before its first
43
+ * await, is left to this check.
44
+ *
45
+ * A write within the file system's mtime resolution of the read goes unseen,
46
+ * as it does for Theia's own check. A file whose mtime moves while its text
47
+ * stays the same costs a whole-text write rather than the edits.
48
+ *
49
+ * Bound by `bindEditorDiskSync`.
50
+ */
51
+ let HydraniumFileService = class HydraniumFileService extends file_service_1.FileService {
52
+ update(resource, changes, options) {
53
+ const strict = typeof options.etag === 'string' && options.etag !== files_1.ETAG_DISABLED ? { ...options, etag: `${options.etag}!` } : options;
54
+ return super.update(resource, changes, strict);
55
+ }
56
+ };
57
+ exports.HydraniumFileService = HydraniumFileService;
58
+ exports.HydraniumFileService = HydraniumFileService = __decorate([
59
+ (0, inversify_1.injectable)()
60
+ ], HydraniumFileService);
61
+ //# sourceMappingURL=hydranium-file-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydranium-file-service.js","sourceRoot":"","sources":["../../src/browser/hydranium-file-service.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;AAGlF,4DAA0D;AAC1D,6EAAqG;AACrG,8DAAmE;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,0BAAW;IACzC,MAAM,CACZ,QAAa,EACb,OAA6C,EAC7C,OAA8B;QAE9B,MAAM,MAAM,GACT,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,KAAK,qBAAa,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QAC3H,OAAO,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAClD,CAAC;CACH,CAAA;;+BAVY,oBAAoB;IADhC,IAAA,sBAAU,GAAE;GACA,oBAAoB,CAUhC"}
@@ -10,4 +10,9 @@ export * from './channel-logger';
10
10
  export * from './log-level-preference';
11
11
  export * from './browser-capture';
12
12
  export * from './memory-diagnostics-contribution';
13
+ export * from './session-aware-connection-source';
14
+ export * from './connection-diagnostics-contribution';
15
+ export * from './connection-reporter';
16
+ export * from './editor-disk-sync';
17
+ export * from './hydranium-file-service';
13
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAGlF,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mCAAmC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAGlF,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,uCAAuC,CAAC;AACtD,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}