nodeReader.ts ×9

Frontier kind: Code frontier

unlabeled · c_9561abf13157

14 tests · 42880 LOC · 238 files · introduces 0 tests · 59 LOC · 5 files

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges59 lines · 5 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5562 ranges42880 lines · 238 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.

5 files ranked by introduced lines: 59 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/nodeReader.ts 39 introduced LOC · 9 ranges

Open complete file

18
19 constructor(node: AstNode) {
20 > this.nextNodes = [node]; nodeReader.ts
21 > this.offsets = [lengthZero];
22 > this.idxs = [];
23 > }
24
25 /**
28 */
29 readLongestNodeAt(offset: Length, predicate: (node: AstNode) => boolean): AstNode | undefined {
30 > if (lengthLessThan(offset, this.lastOffset)) { nodeReader.ts
31 throw new Error('Invalid offset');
32 }
33 > this.lastOffset = offset; nodeReader.ts
34 >
35 > // Find the longest node of all those that are closest to the current offset.
36 > while (true) {
37 > const curNode = lastOrUndefined(this.nextNodes);
38 >
39 > if (!curNode) {
40 > return undefined;
41 > }
42 > const curNodeOffset = lastOrUndefined(this.offsets)!;
43 >
44 > if (lengthLessThan(offset, curNodeOffset)) {
45 // The next best node is not here yet.
46 // The reader must advance before a cached node is hit.
47 return undefined;
48 }
50 > if (lengthLessThan(curNodeOffset, offset)) {
51 // The reader is ahead of the current node.
52 if (lengthAdd(curNodeOffset, curNode.length) <= offset) {
66 }
67 }
68 > } else { nodeReader.ts
69 // readerOffsetBeforeChange === curNodeOffset
70 if (predicate(curNode)) {
86 }
87 }
88 > } nodeReader.ts
89 > }
90
91 // Navigates to the longest node that continues after the current node.
92 private nextNodeAfterCurrent(): void {
93 > while (true) { nodeReader.ts
94 > const currentOffset = lastOrUndefined(this.offsets);
95 > const currentNode = lastOrUndefined(this.nextNodes);
96 > this.nextNodes.pop();
97 > this.offsets.pop();
98 >
99 > if (this.idxs.length === 0) {
100 > // We just popped the root node, there is no next node.
101 > break;
102 > }
103
104 // Parent is not undefined, because idxs is not empty
114 this.idxs.pop();
115 }
116 > // We fully consumed the parent. nodeReader.ts
117 > // Current node is now parent, so call nextNodeAfterCurrent again
118 > }
119 > }
120 }
121
132 }
133
134 > function lastOrUndefined<T>(arr: readonly T[]): T | undefined { nodeReader.ts
135 > return arr.length > 0 ? arr[arr.length - 1] : undefined;
136 > }
src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/bracketPairsTree.ts 8 introduced LOC · 2 ranges

Open complete file

128 private flushQueue() {
129 if (this.queuedTextEdits.length > 0) {
130 > this.astWithTokens = this.parseDocumentFromTextBuffer(this.queuedTextEdits, this.astWithTokens, false); bracketPairsTree.ts
131 > this.queuedTextEdits = [];
132 > }
133 if (this.queuedTextEditsForInitialAstWithoutTokens.length > 0) {
134 > if (this.initialAstWithoutTokens) { bracketPairsTree.ts
135 > this.initialAstWithoutTokens = this.parseDocumentFromTextBuffer(this.queuedTextEditsForInitialAstWithoutTokens, this.initialAstWithoutTokens, false);
136 > }
137 > this.queuedTextEditsForInitialAstWithoutTokens = [];
138 > }
139 }
140
src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/parser.ts 8 introduced LOC · 3 ranges

Open complete file

105 private tryReadChildFromCache(openedBracketIds: SmallImmutableSet<number>): AstNode | undefined {
106 if (this.oldNodeReader) {
107 > const maxCacheableLength = this.positionMapper.getDistanceToNextChange(this.tokenizer.offset); parser.ts
108 > if (maxCacheableLength === null || !lengthIsZero(maxCacheableLength)) {
109 > const cachedNode = this.oldNodeReader.readLongestNodeAt(this.positionMapper.getOffsetBeforeChange(this.tokenizer.offset), curNode => {
110 // The edit could extend the ending token, thus we cannot re-use nodes that touch the edit.
111 // If there is no edit anymore, we can re-use the node in any case.
117 const canBeReused = curNode.canBeReused(openedBracketIds);
118 return canBeReused;
119 > }); parser.ts
120 >
121 > if (cachedNode) {
122 this._itemsFromCache++;
123 this.tokenizer.skip(cachedNode.length);
124 return cachedNode;
125 }
126 > } parser.ts
127 > }
128 return undefined;
129 }
src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/concat23Trees.ts 2 introduced LOC · 1 range

Open complete file

17 }
18 if (items.length === 1) {
19 > return items[0]; concat23Trees.ts
20 > }
21
22 let i = 0;
src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/tokenizer.ts 2 introduced LOC · 1 range

Open complete file

82
83 get offset() {
84 > return this._offset; tokenizer.ts
85 > }
86
87 get length() {