agentSubscription.ts ×19

Frontier kind: Code frontier

unlabeled · c_d0a70c87c2fa

14 tests · 15415 LOC · 93 files · introduces 0 tests · 55 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
19 ranges55 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1332 ranges15415 lines · 93 files · Browse complete extent
All tests (intent)
14 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 55 introduced LOC across 19 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/common/state/agentSubscription.ts 55 introduced LOC · 19 ranges

Open complete file

882 */
883 getSubscription<T>(kind: StateComponents, resource: URI, owner: string): IReference<IAgentSubscription<T>> {
884 > const existing = this._subscriptions.get(resource); agentSubscription.ts
885 > if (existing) {
886 if (existing.sub.value instanceof Error) {
887 // Failed subscriptions should not poison the resource forever. Evict
894 }
895 }
897 > // Create new subscription based on caller-specified kind
898 > const key = resource.toString();
899 > const sub = this._createSubscription(kind, key);
900 > const entry: ManagedSubscriptionEntry = { sub, kind, refCount: 1, holders: new Map() };
901 > this._subscriptions.set(resource, entry);
902 >
903 > // Kick off server subscription asynchronously.
904 > // Capture the entry reference so we can validate it hasn't been
905 > // replaced by a new subscription for the same key (race guard).
906 > void (async () => {
907 > const inflight = this._inflightCreates.get(resource);
908 > if (inflight) {
909 try {
910 await inflight;
915 }
916 }
917 > try { agentSubscription.ts
918 > const snapshot = await this._subscribe(resource);
919 if (this._subscriptions.get(resource) === entry) {
920 sub.handleSnapshot(snapshot.state as never, snapshot.fromSeq);
921 }
922 > } catch (err) { agentSubscription.ts
923 if (this._subscriptions.get(resource) === entry) {
924 sub.setError(err instanceof Error ? err : new Error(String(err)));
925 }
926 }
927 > })(); agentSubscription.ts
928 >
929 > return this._acquireReference<T>(resource, entry, owner);
930 > }
931
932 /**
937 */
938 private _acquireReference<T>(resource: URI, entry: ManagedSubscriptionEntry, owner: string): IReference<IAgentSubscription<T>> {
939 > const ownerId = ++this._referenceOwnerIds; agentSubscription.ts
940 > entry.holders.set(ownerId, owner);
941 >
942 > let isDisposed = false;
943 > return {
944 > object: entry.sub as unknown as IAgentSubscription<T>,
945 > dispose: () => {
946 > if (isDisposed) {
947 return;
948 }
949 > isDisposed = true; agentSubscription.ts
950 > entry.holders.delete(ownerId);
951 > this._releaseSubscription(resource, entry);
952 > },
953 > };
954 > }
955
956 private _disposeSubscriptionEntry(resource: URI, entry: ManagedSubscriptionEntry): void {
963
964 private _tryUnsubscribe(resource: URI): void {
965 > try { agentSubscription.ts
966 > this._unsubscribe(resource);
967 > } catch (error) {
968 const message = error instanceof Error ? error.message : String(error);
969 this._log(`Failed to unsubscribe ${resource.toString()}: ${message}`);
970 }
972
973 /**
1126
1127 private _createSubscription(kind: StateComponents, key: string): ManagedSubscription {
1128 > switch (kind) { agentSubscription.ts
1129 > case StateComponents.Session:
1130 return new SessionStateSubscription(key, this._clientId, this._seqAllocator, this._log);
1131 > case StateComponents.Chat: agentSubscription.ts
1132 return new ChatStateSubscription(key, this._clientId, this._seqAllocator, this._log);
1133 > case StateComponents.Terminal: agentSubscription.ts
1134 return new TerminalStateSubscription(key, this._clientId, this._log);
1135 > case StateComponents.Changeset: agentSubscription.ts
1136 return new ChangesetStateSubscription(key, this._clientId, this._seqAllocator, this._log);
1137 > case StateComponents.Annotations: agentSubscription.ts
1138 return new AnnotationsStateSubscription(key, this._clientId, this._seqAllocator, this._log);
1139 > case StateComponents.Root: agentSubscription.ts
1140 throw new Error('_createSubscription: root subscription is managed separately');
1141 > default: agentSubscription.ts
1142 assertNever(kind, `_createSubscription: unsupported StateComponents kind: ${kind}`);
1144 > }
1145
1146 private _releaseSubscription(resource: URI, expected?: ManagedSubscriptionEntry): void {
1147 > const entry = this._subscriptions.get(resource); agentSubscription.ts
1148 > // A failed subscription can be evicted and replaced while old references
1149 > // still exist; stale disposals must not release the replacement entry.
1150 > if (!entry || (expected && entry !== expected)) {
1151 return;
1152 }
1156 this._disposeSubscriptionEntry(resource, entry);
1157 }
1159
1160 override dispose(): void {