paging.ts ×21

Frontier kind: Code frontier

unlabeled · c_94f9d16c70cb

23 tests · 4534 LOC · 23 files · introduces 0 tests · 152 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
21 ranges152 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
633 ranges4534 lines · 23 files · Browse complete extent
All tests (intent)
23 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.

Introduced files, introduced tests, and structurally relevant concept specializationpaging.test|title=PagedModel cancellation works|occurrence=1 · 0 introduced LOCpaging.test|title=PagedM…paging.test|title=PagedModel same page cancellation works|occurrence=1 · 0 introduced LOCpaging.test|title=PagedM…paging.ts ×3 · 11 introduced LOCpaging.ts ×3paging.ts ×1 · 4 introduced LOCpaging.ts ×1paging.ts ×5 · 22 introduced LOCpaging.ts ×5paging.ts ×1 · 2 introduced LOCpaging.ts ×1paging.ts ×1 · 5 introduced LOCpaging.ts ×1paging.ts ×2 · 2 introduced LOCpaging.ts ×2arrays.ts ×3 · 36 introduced LOCarrays.ts ×3paging.ts ×1 · 2 introduced LOCpaging.ts ×1iterativePaging.test|title=IterativePagedModel sequential page loads work correctly|occurrence=1, iterativePaging.test|title=IterativePagedModel accessing items after loading all pages|occurrence=1 · 0 introduced LOCiterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel load multiple pages|occurrence=1, iterativePaging.test|title=IterativePagedModel pager with varying page sizes|occurrence=1 · 0 introduced LOCiterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel reaching end of data removes sentinel|occurrence=1 · 0 introduced LOCiterativePaging.test|tit…paging.ts ×1 · 3 introduced LOCpaging.ts ×1paging.ts ×1 · 2 introduced LOCpaging.ts ×1paging.ts ×5 · 25 introduced LOCpaging.ts ×5paging.ts ×1 · 2 introduced LOCpaging.ts ×1iterativePaging.test|title=IterativePagedModel load first page via sentinel access|occurrence=1 · 0 introduced LOCiterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel single page pager with no more pages|occurrence=1, iterativePaging.test|title=IterativePagedModel accessing regular items does not trigger loading|occurrence=1 · 0 introduced LOCiterativePaging.test|tit…paging.ts ×2 · 7 introduced LOCpaging.ts ×2paging.ts ×1 · 2 introduced LOCpaging.ts ×1paging.ts ×1 · 2 introduced LOCpaging.ts ×1paging.ts ×1 · 1 introduced LOCpaging.ts ×1paging.ts ×2 · 3 introduced LOCpaging.ts ×2paging.ts ×3 · 3 introduced LOCpaging.ts ×3paging.ts ×2 · 2 introduced LOCpaging.ts ×2paging.ts ×1 · 2 introduced LOCpaging.ts ×1paging.ts ×2 · 6 introduced LOCpaging.ts ×2cancellation.ts ×18 · 90 introduced LOCcancellation.ts ×18event.ts ×2 · 6 introduced LOCevent.ts ×2event.ts ×93 · 864 introduced LOCevent.ts ×93utils.ts ×3 · 9 introduced LOCutils.ts ×3linkedList.ts ×13 · 44 introduced LOClinkedList.ts ×13lifecycle.ts ×2 · 4 introduced LOClifecycle.ts ×2lifecycle.ts ×4 · 8 introduced LOClifecycle.ts ×4lifecycle.ts ×6 · 16 introduced LOClifecycle.ts ×6lifecycle.ts ×1 · 2 introduced LOClifecycle.ts ×1lifecycle.ts ×1 · 2 introduced LOClifecycle.ts ×1lifecycle.ts ×1 · 3 introduced LOClifecycle.ts ×1map.ts ×97 · 3334 introduced LOCmap.ts ×97src/vs/base/common/arrays.ts · 949 LOCcommon/arrays.tssrc/vs/base/common/arraysFind.ts · 226 LOCcommon/arraysFind.tssrc/vs/base/common/assert.ts · 91 LOCcommon/assert.tssrc/vs/base/common/cancellation.ts · 206 LOCcommon/cancellation.tssrc/vs/base/common/charCode.ts · 450 LOCcommon/charCode.tssrc/vs/base/common/collections.ts · 176 LOCcommon/collections.tssrc/vs/base/common/errors.ts · 357 LOCcommon/errors.tssrc/vs/base/common/event.ts · 1964 LOCcommon/event.tssrc/vs/base/common/functional.ts · 32 LOCcommon/functional.tssrc/vs/base/common/iterator.ts · 194 LOCcommon/iterator.tssrc/vs/base/common/lifecycle.ts · 974 LOCcommon/lifecycle.tssrc/vs/base/common/linkedList.ts · 151 LOCcommon/linkedList.tssrc/vs/base/common/map.ts · 1016 LOCcommon/map.tssrc/vs/base/common/marshallingIds.ts · 33 LOCcommon/marshallingIds.tssrc/vs/base/common/paging.ts · 392 LOCcommon/paging.tssrc/vs/base/common/path.ts · 1589 LOCcommon/path.tssrc/vs/base/common/platform.ts · 281 LOCcommon/platform.tssrc/vs/base/common/process.ts · 76 LOCcommon/process.tssrc/vs/base/common/stopwatch.ts · 41 LOCcommon/stopwatch.tssrc/vs/base/common/types.ts · 410 LOCcommon/types.tssrc/vs/base/common/uri.ts · 754 LOCcommon/uri.tssrc/vs/base/test/common/utils.ts · 107 LOCcommon/utils.tssrc/vs/nls.ts · 244 LOCvs/nls.tsiterativePaging.test|title=IterativePagedModel accessing item beyond loaded range throws|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel accessing item beyond loaded range throws|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel accessing items after loading all pages|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel accessing items after loading all pages|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel accessing regular items does not trigger loading|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel accessing regular items does not trigger loading|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel cancelled token during initial resolve|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel cancelled token during initial resolve|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel concurrent access to sentinel only loads once|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel concurrent access to sentinel only loads once|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel empty pager with no items|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel empty pager with no items|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel event fires for each page load|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel event fires for each page load|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel initial state|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel initial state|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel load first page via sentinel access|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel load first page via sentinel access|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel load multiple pages|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel load multiple pages|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel onDidIncrementLength event fires correctly|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel onDidIncrementLength event fires correctly|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel pager with varying page sizes|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel pager with varying page sizes|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel reaching end of data removes sentinel|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel reaching end of data removes sentinel|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel resolving item beyond all pages throws|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel resolving item beyond all pages throws|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel sequential page loads work correctly|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel sequential page loads work correctly|occurrence=1iterativePaging.test|tit…iterativePaging.test|title=IterativePagedModel single page pager with no more pages|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/iterativePaging.test|title=IterativePagedModel single page pager with no more pages|occurrence=1iterativePaging.test|tit…paging.test|title=PagedModel cancellation works|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/paging.test|title=PagedModel cancellation works|occurrence=1paging.test|title=PagedM…paging.test|title=PagedModel isResolved|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/paging.test|title=PagedModel isResolved|occurrence=1paging.test|title=PagedM…paging.test|title=PagedModel preemptive cancellation works|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/paging.test|title=PagedModel preemptive cancellation works|occurrence=1paging.test|title=PagedM…paging.test|title=PagedModel resolve page 2|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/paging.test|title=PagedModel resolve page 2|occurrence=1paging.test|title=PagedM…paging.test|title=PagedModel resolve page|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/paging.test|title=PagedModel resolve page|occurrence=1paging.test|title=PagedM…paging.test|title=PagedModel resolve single|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/paging.test|title=PagedModel resolve single|occurrence=1paging.test|title=PagedM…paging.test|title=PagedModel same page cancellation works|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/paging.test|title=PagedModel same page cancellation works|occurrence=1paging.test|title=PagedM…Focused concept · paging.ts ×21 · 152 introduced LOCpaging.ts ×21

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: 152 introduced LOC across 21 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/base/common/paging.ts 152 introduced LOC · 21 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- paging.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { range } from './arrays.js';
7 > import { CancellationToken, CancellationTokenSource } from './cancellation.js';
8 > import { CancellationError } from './errors.js';
9 > import { Event, Emitter } from './event.js';
10 >
11 > /**
12 > * A Pager is a stateless abstraction over a paged collection.
13 > */
14 > export interface IPager<T> {
15 > firstPage: T[];
16 > total: number;
17 > pageSize: number;
18 > getPage(pageIndex: number, cancellationToken: CancellationToken): Promise<T[]>;
19 > }
20 >
21 > export interface IIterativePage<T> {
22 > readonly items: T[];
23 > readonly hasMore: boolean;
24 > }
25 >
26 > export interface IIterativePager<T> {
27 > readonly firstPage: IIterativePage<T>;
28 > getNextPage(cancellationToken: CancellationToken): Promise<IIterativePage<T>>;
29 > }
30 >
31 > export interface IPageIterator<T> {
32 > elements: T[];
33 > total: number;
34 > hasNextPage: boolean;
35 > getNextPage(cancellationToken: CancellationToken): Promise<IPageIterator<T>>;
36 > }
37 >
38 > interface IPage<T> {
39 > isResolved: boolean;
40 > promise: Promise<void> | null;
41 > cts: CancellationTokenSource | null;
42 > promiseIndexes: Set<number>;
43 > elements: T[];
44 > }
45 >
46 function createPage<T>(elements?: T[]): IPage<T> {
47 return {
53 };
54 }
55 > paging.ts
56 > /**
57 > * A PagedModel is a stateful model over an abstracted paged collection.
58 > */
59 > export interface IPagedModel<T> {
60 > readonly length: number;
61 > readonly onDidIncrementLength: Event<number>;
62 > isResolved(index: number): boolean;
63 > get(index: number): T;
64 > resolve(index: number, cancellationToken: CancellationToken): Promise<T>;
65 > }
66 >
67 > export function singlePagePager<T>(elements: T[]): IPager<T> {
68 return {
69 firstPage: elements,
75 };
76 }
77 > paging.ts
78 > export class PagedModel<T> implements IPagedModel<T> {
79 >
80 > private pager: IPager<T>;
81 > private pages: IPage<T>[] = [];
82 >
83 > get length(): number { return this.pager.total; }
84 > readonly onDidIncrementLength = Event.None;
85 >
86 > constructor(arg: IPager<T> | T[]) {
87 this.pager = Array.isArray(arg) ? singlePagePager<T>(arg) : arg;
88
94 ];
95 }
96 > paging.ts
97 > isResolved(index: number): boolean {
98 const pageIndex = Math.floor(index / this.pager.pageSize);
99 const page = this.pages[pageIndex];
101 return !!page.isResolved;
102 }
103 > paging.ts
104 > get(index: number): T {
105 const pageIndex = Math.floor(index / this.pager.pageSize);
106 const indexInPage = index % this.pager.pageSize;
109 return page.elements[indexInPage];
110 }
111 > paging.ts
112 > resolve(index: number, cancellationToken: CancellationToken): Promise<T> {
113 if (cancellationToken.isCancellationRequested) {
114 return Promise.reject(new CancellationError());
156 .finally(() => listener.dispose());
157 }
158 > } paging.ts
159 >
160 > export class DelayedPagedModel<T> implements IPagedModel<T> {
161 >
162 > get length(): number { return this.model.length; }
163 > get onDidIncrementLength() { return this.model.onDidIncrementLength; }
164 >
165 > constructor(private readonly model: IPagedModel<T>, private timeout: number = 500) { }
166 >
167 > isResolved(index: number): boolean {
168 return this.model.isResolved(index);
169 }
170 > paging.ts
171 > get(index: number): T {
172 return this.model.get(index);
173 }
174 > paging.ts
175 > resolve(index: number, cancellationToken: CancellationToken): Promise<T> {
176 return new Promise((c, e) => {
177 if (cancellationToken.isCancellationRequested) {
195 });
196 }
197 > } paging.ts
198 >
199 > /**
200 > * A PageIteratorPager wraps an IPageIterator to provide IPager functionality.
201 > * It caches pages as they are accessed and supports random page access by
202 > * sequentially loading pages until the requested page is reached.
203 > */
204 > export class PageIteratorPager<T> implements IPager<T> {
205 > private cachedPages: T[][] = [];
206 > private currentIterator: IPageIterator<T>;
207 > private isComplete: boolean = false;
208 > private pendingRequests = new Map<number, Promise<void>>();
209 >
210 > public readonly firstPage: T[];
211 > public readonly pageSize: number;
212 > public readonly total: number;
213 >
214 > constructor(initialIterator: IPageIterator<T>) {
215 this.currentIterator = initialIterator;
216 this.firstPage = [...initialIterator.elements];
220 this.total = initialIterator.total;
221 }
222 > paging.ts
223 > async getPage(pageIndex: number, cancellationToken: CancellationToken): Promise<T[]> {
224 if (cancellationToken.isCancellationRequested) {
225 throw new CancellationError();
262 }
263 }
264 > paging.ts
265 > private async loadPagesUntil(targetPageIndex: number, cancellationToken: CancellationToken): Promise<void> {
266 while (targetPageIndex >= this.cachedPages.length && this.currentIterator.hasNextPage) {
267 if (cancellationToken.isCancellationRequested) {
276 }
277 }
278 > } paging.ts
279 >
280 > export class IterativePagedModel<T> implements IPagedModel<T> {
281 >
282 > private items: T[] = [];
283 > private _hasNextPage = true;
284 > private readonly _onDidIncrementLength = new Emitter<number>();
285 > private loadingPromise: Promise<void> | null = null;
286 >
287 > private readonly pager: IIterativePager<T>;
288 >
289 > constructor(pager: IIterativePager<T>) {
290 this.pager = pager;
291 this.items = [...pager.firstPage.items];
292 this._hasNextPage = pager.firstPage.hasMore;
293 }
294 > paging.ts
295 > get onDidIncrementLength(): Event<number> {
296 return this._onDidIncrementLength.event;
297 }
298 > paging.ts
299 > /**
300 > * Returns actual length + 1 if there are more pages (sentinel approach)
301 > */
302 > get length(): number {
303 return this.items.length + (this._hasNextPage ? 1 : 0);
304 }
305 > paging.ts
306 > /**
307 > * Sentinel item is never resolved - it triggers loading
308 > */
309 > isResolved(index: number): boolean {
310 if (index === this.items.length && this._hasNextPage) {
311 return false; // This will trigger resolve() call
313 return index < this.items.length;
314 }
315 > paging.ts
316 > get(index: number): T {
317 if (index < this.items.length) {
318 return this.items[index];
320 throw new Error('Item not resolved yet');
321 }
322 > paging.ts
323 > /**
324 > * When sentinel item is accessed, load next page
325 > */
326 > async resolve(index: number, cancellationToken: CancellationToken): Promise<T> {
327 if (cancellationToken.isCancellationRequested) {
328 return Promise.reject(new CancellationError());
341 throw new Error('Index out of bounds');
342 }
343 > paging.ts
344 > private async loadNextPage(cancellationToken: CancellationToken): Promise<void> {
345 if (!this._hasNextPage) {
346 return;
373 await this.loadingPromise;
374 }
375 > paging.ts
376 > dispose(): void {
377 this._onDidIncrementLength.dispose();
378 }
379 > } paging.ts
380 >
381 > /**
382 > * Similar to array.map, `mapPager` lets you map the elements of an
383 > * abstract paged collection to another type.
384 > */
385 > export function mapPager<T, R>(pager: IPager<T>, fn: (t: T) => R): IPager<R> {
386 return {
387 firstPage: pager.firstPage.map(fn),