pieceTreeTextBufferBuilder.ts ×19

Frontier kind: Code frontier

unlabeled · c_8b25f8063b57

639 tests · 35858 LOC · 206 files · introduces 0 tests · 149 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
36 ranges149 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
4080 ranges35858 lines · 206 files · Browse complete extent
All tests (intent)
639 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.

3 files ranked by introduced lines: 149 introduced LOC across 36 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder.ts 73 introduced LOC · 19 ranges

Open complete file

14
15 constructor(
16 > private readonly _chunks: StringBuffer[], pieceTreeTextBufferBuilder.ts
17 > private readonly _bom: string,
18 > private readonly _cr: number,
19 > private readonly _lf: number,
20 > private readonly _crlf: number,
21 > private readonly _containsRTL: boolean,
22 > private readonly _containsUnusualLineTerminators: boolean,
23 > private readonly _isBasicASCII: boolean,
24 > private readonly _normalizeEOL: boolean
25 > ) { }
26
27 private _getEOL(defaultEOL: DefaultEndOfLine): '\r\n' | '\n' {
28 > const totalEOLCount = this._cr + this._lf + this._crlf; pieceTreeTextBufferBuilder.ts
29 > const totalCRCount = this._cr + this._crlf;
30 > if (totalEOLCount === 0) {
31 // This is an empty file or a file with precisely one line
32 return (defaultEOL === DefaultEndOfLine.LF ? '\n' : '\r\n');
38 // At least one line more ends in \n
39 return '\n';
41
42 public create(defaultEOL: DefaultEndOfLine): { textBuffer: ITextBuffer; disposable: IDisposable } {
43 > const eol = this._getEOL(defaultEOL); pieceTreeTextBufferBuilder.ts
44 > const chunks = this._chunks;
45 >
46 > if (this._normalizeEOL &&
47 ((eol === '\r\n' && (this._cr > 0 || this._lf > 0))
48 || (eol === '\n' && (this._cr > 0 || this._crlf > 0)))
50 // Normalize pieces
51 for (let i = 0, len = chunks.length; i < len; i++) {
55 }
56 }
58 > const textBuffer = new PieceTreeTextBuffer(chunks, this._bom, eol, this._containsRTL, this._containsUnusualLineTerminators, this._isBasicASCII, this._normalizeEOL);
59 > return { textBuffer: textBuffer, disposable: textBuffer };
60 > }
61
62 public getFirstLineText(lengthLimit: number): string {
81
82 constructor() {
83 > this.chunks = []; pieceTreeTextBufferBuilder.ts
84 > this.BOM = '';
85 >
86 > this._hasPreviousChar = false;
87 > this._previousChar = 0;
88 > this._tmpLineStarts = [];
89 >
90 > this.cr = 0;
91 > this.lf = 0;
92 > this.crlf = 0;
93 > this.containsRTL = false;
94 > this.containsUnusualLineTerminators = false;
95 > this.isBasicASCII = true;
96 > }
97
98 public acceptChunk(chunk: string): void {
99 > if (chunk.length === 0) { pieceTreeTextBufferBuilder.ts
100 return;
101 }
109
110 const lastChar = chunk.charCodeAt(chunk.length - 1);
111 > if (lastChar === CharCode.CarriageReturn || (lastChar >= 0xD800 && lastChar <= 0xDBFF)) { pieceTreeTextBufferBuilder.ts
112 // last character is \r or a high surrogate => keep it back
113 this._acceptChunk1(chunk.substr(0, chunk.length - 1), false);
119 this._previousChar = lastChar;
120 }
122
123 private _acceptChunk1(chunk: string, allowEmptyStrings: boolean): void {
124 > if (!allowEmptyStrings && chunk.length === 0) { pieceTreeTextBufferBuilder.ts
125 // Nothing to do
126 return;
127 }
129 > if (this._hasPreviousChar) {
130 this._acceptChunk2(String.fromCharCode(this._previousChar) + chunk);
132 > this._acceptChunk2(chunk);
133 > }
134 > }
135
136 private _acceptChunk2(chunk: string): void {
137 > const lineStarts = createLineStarts(this._tmpLineStarts, chunk); pieceTreeTextBufferBuilder.ts
138 >
139 > this.chunks.push(new StringBuffer(chunk, lineStarts.lineStarts));
140 > this.cr += lineStarts.cr;
141 > this.lf += lineStarts.lf;
142 > this.crlf += lineStarts.crlf;
143 >
144 > if (!lineStarts.isBasicASCII) {
145 // this chunk contains non basic ASCII characters
146 this.isBasicASCII = false;
152 }
153 }
155
156 public finish(normalizeEOL: boolean = true): PieceTreeTextBufferFactory {
157 > this._finish(); pieceTreeTextBufferBuilder.ts
158 > return new PieceTreeTextBufferFactory(
159 > this.chunks,
160 > this.BOM,
161 > this.cr,
162 > this.lf,
163 > this.crlf,
164 > this.containsRTL,
165 > this.containsUnusualLineTerminators,
166 > this.isBasicASCII,
167 > normalizeEOL
168 > );
169 > }
170
171 private _finish(): void {
172 > if (this.chunks.length === 0) { pieceTreeTextBufferBuilder.ts
173 this._acceptChunk1('', true);
174 }
176 > if (this._hasPreviousChar) {
177 this._hasPreviousChar = false;
178 // recreate last chunk
src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeBase.ts 69 introduced LOC · 16 ranges

Open complete file

14 const AverageBufferSize = 65535;
15
16 > function createUintArray(arr: number[]): Uint32Array | Uint16Array { pieceTreeBase.ts
17 > let r;
18 > if (arr[arr.length - 1] < 65536) {
19 r = new Uint16Array(arr.length);
20 > } else { pieceTreeBase.ts
21 r = new Uint32Array(arr.length);
22 }
23 > r.set(arr, 0); pieceTreeBase.ts
24 > return r;
25 > }
26
27 class LineStarts {
28 constructor(
29 > public readonly lineStarts: Uint32Array | Uint16Array | number[], pieceTreeBase.ts
30 > public readonly cr: number,
31 > public readonly lf: number,
32 > public readonly crlf: number,
33 > public readonly isBasicASCII: boolean
34 > ) { }
35 }
36
63
64 export function createLineStarts(r: number[], str: string): LineStarts {
65 > r.length = 0; pieceTreeBase.ts
66 > r[0] = 0;
67 > let rLength = 1;
68 > let cr = 0, lf = 0, crlf = 0;
69 > let isBasicASCII = true;
70 > for (let i = 0, len = str.length; i < len; i++) {
71 const chr = str.charCodeAt(i);
72
93 }
94 }
95 > const result = new LineStarts(createUintArray(r), cr, lf, crlf, isBasicASCII); pieceTreeBase.ts
96 > r.length = 0;
97 >
98 > return result;
99 > }
100
101 interface NodePosition {
146
147 constructor(buffer: string, lineStarts: Uint32Array | Uint16Array | number[]) {
148 > this.buffer = buffer; pieceTreeBase.ts
149 > this.lineStarts = lineStarts;
150 > }
151 }
152
210
211 constructor(limit: number) {
212 > this._limit = limit; pieceTreeBase.ts
213 > this._cache = [];
214 > }
215
216 public get(offset: number): CacheEntry | null {
242
243 public validate(offset: number) {
244 > let hasInvalidVal = false; pieceTreeBase.ts
245 > const tmp: Array<CacheEntry | null> = this._cache;
246 > for (let i = 0; i < tmp.length; i++) {
247 const nodePos = tmp[i]!;
248 if (nodePos.node.parent === null || nodePos.nodeStartOffset >= offset) {
252 }
253 }
255 > if (hasInvalidVal) {
256 const newArr: CacheEntry[] = [];
257 for (const entry of tmp) {
279
280 constructor(chunks: StringBuffer[], eol: '\r\n' | '\n', eolNormalized: boolean) {
281 > this.create(chunks, eol, eolNormalized); pieceTreeBase.ts
282 > }
283
284 create(chunks: StringBuffer[], eol: '\r\n' | '\n', eolNormalized: boolean) {
285 > this._buffers = [ pieceTreeBase.ts
286 > new StringBuffer('', [0])
287 > ];
288 > this._lastChangeBufferPos = { line: 0, column: 0 };
289 > this.root = SENTINEL;
290 > this._lineCnt = 1;
291 > this._length = 0;
292 > this._EOL = eol;
293 > this._EOLLength = eol.length;
294 > this._EOLNormalized = eolNormalized;
295 >
296 > let lastNode: TreeNode | null = null;
297 > for (let i = 0, len = chunks.length; i < len; i++) {
298 > if (chunks[i].buffer.length > 0) {
299 if (!chunks[i].lineStarts) {
300 chunks[i].lineStarts = createLineStartsFast(chunks[i].buffer);
311 lastNode = this.rbInsertRight(lastNode, piece);
312 }
314 >
315 > this._searchCache = new PieceTreeSearchCache(1);
316 > this._lastVisitedLine = { lineNumber: 0, value: '' };
317 > this.computeBufferMetadata();
318 > }
319
320 normalizeEOL(eol: '\r\n' | '\n') {
1324
1325 private computeBufferMetadata() {
1326 > let x = this.root; pieceTreeBase.ts
1327 >
1328 > let lfCnt = 1;
1329 > let len = 0;
1330 >
1331 > while (x !== SENTINEL) {
1332 lfCnt += x.lf_left + x.piece.lineFeedCnt;
1333 len += x.size_left + x.piece.length;
1334 x = x.right;
1335 }
1337 > this._lineCnt = lfCnt;
1338 > this._length = len;
1339 > this._searchCache.validate(this._length);
1340 > }
1341
1342 // #region node operations
src/vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.ts 7 introduced LOC · 1 range

Open complete file

43
44 constructor(chunks: StringBuffer[], BOM: string, eol: '\r\n' | '\n', containsRTL: boolean, containsUnusualLineTerminators: boolean, isBasicASCII: boolean, eolNormalized: boolean) {
45 > super(); pieceTreeTextBuffer.ts
46 > this._BOM = BOM;
47 > this._mightContainNonBasicASCII = !isBasicASCII;
48 > this._mightContainRTL = containsRTL;
49 > this._mightContainUnusualLineTerminators = containsUnusualLineTerminators;
50 > this._pieceTree = new PieceTreeBase(chunks, eol, eolNormalized);
51 > }
52
53 // #region TextBuffer