parser.ts ×14

Frontier kind: Code frontier

unlabeled · c_a7b84b35ab76

45 tests · 40855 LOC · 238 files · introduces 0 tests · 116 LOC · 8 files

Introduces — evidence that enters the hierarchy at this concept

Code
28 ranges116 lines · 8 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5007 ranges40855 lines · 238 files · Browse complete extent
All tests (intent)
45 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.

8 files ranked by introduced lines: 116 introduced LOC across 28 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/parser.ts 70 introduced LOC · 14 ranges

Open complete file

16 */
17 export function parseDocument(tokenizer: Tokenizer, edits: TextEditInfo[], oldNode: AstNode | undefined, createImmutableLists: boolean): AstNode {
18 > const parser = new Parser(tokenizer, edits, oldNode, createImmutableLists); parser.ts
19 > return parser.parseDocument();
20 > }
21
22 /**
44
45 constructor(
46 > private readonly tokenizer: Tokenizer, parser.ts
47 > edits: TextEditInfo[],
48 > oldNode: AstNode | undefined,
49 > private readonly createImmutableLists: boolean,
50 > ) {
51 > if (oldNode && createImmutableLists) {
52 throw new Error('Not supported');
53 }
54 > parser.ts
55 > this.oldNodeReader = oldNode ? new NodeReader(oldNode) : undefined;
56 > this.positionMapper = new BeforeEditPositionMapper(edits);
57 > }
58
59 parseDocument(): AstNode {
60 > this._itemsConstructed = 0; parser.ts
61 > this._itemsFromCache = 0;
62 >
63 > let result = this.parseList(SmallImmutableSet.getEmpty(), 0);
64 > if (!result) {
65 result = ListAstNode.getEmpty();
66 }
67 > parser.ts
68 > return result;
69 > }
70
71 private parseList(
72 > openedBracketIds: SmallImmutableSet<OpeningBracketId>, parser.ts
73 > level: number,
74 > ): AstNode | null {
75 > const items: AstNode[] = [];
76 >
77 > while (true) {
78 > let child = this.tryReadChildFromCache(openedBracketIds);
79 >
80 > if (!child) {
81 > const token = this.tokenizer.peek();
82 > if (
83 > !token ||
84 > (token.kind === TokenKind.ClosingBracket &&
85 token.bracketIds.intersects(openedBracketIds))
86 > ) { parser.ts
87 > break;
88 > }
89 >
90 > child = this.parseChild(openedBracketIds, level + 1);
91 > }
92 >
93 > if (child.kind === AstNodeKind.List && child.childrenLength === 0) {
94 continue;
95 }
96 > parser.ts
97 > items.push(child);
98 > }
99 >
100 > // When there is no oldNodeReader, all items are created from scratch and must have the same height.
101 > const result = this.oldNodeReader ? concat23Trees(items) : concat23TreesOfSameHeight(items, this.createImmutableLists);
102 > return result;
103 > }
104
105 private tryReadChildFromCache(openedBracketIds: SmallImmutableSet<number>): AstNode | undefined {
106 > if (this.oldNodeReader) { parser.ts
107 const maxCacheableLength = this.positionMapper.getDistanceToNextChange(this.tokenizer.offset);
108 if (maxCacheableLength === null || !lengthIsZero(maxCacheableLength)) {
126 }
127 }
128 > return undefined; parser.ts
129 > }
130
131 private parseChild(
132 > openedBracketIds: SmallImmutableSet<number>, parser.ts
133 > level: number,
134 > ): AstNode {
135 > this._itemsConstructed++;
136 >
137 > const token = this.tokenizer.read()!;
138 >
139 > switch (token.kind) {
140 > case TokenKind.ClosingBracket:
141 return new InvalidBracketAstNode(token.bracketIds, token.length);
142 > parser.ts
143 > case TokenKind.Text:
144 > return token.astNode as TextAstNode;
145 >
146 > case TokenKind.OpeningBracket: {
147 if (level > 300) {
148 // To prevent stack overflows
173 }
174 }
175 > default: parser.ts
176 throw new Error('unexpected');
177 > } parser.ts
178 > }
179 }
src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsImpl.ts 19 introduced LOC · 3 ranges

Open complete file

74 private updateBracketPairsTree() {
75 if (this.bracketsRequested && this.canBuildAST) {
76 > if (!this.bracketPairsTree.value) { bracketPairsImpl.ts
77 > const store = new DisposableStore();
78 >
79 > this.bracketPairsTree.value = createDisposableRef(
80 > store.add(
81 > new BracketPairsTree(this.textModel, (languageId) => {
82 return this.languageConfigurationService.getLanguageConfiguration(languageId);
84 > ),
85 > store
86 > );
87 > store.add(this.bracketPairsTree.value.object.onDidChange(e => this.onDidChangeEmitter.fire(e)));
88 > this.onDidChangeEmitter.fire();
89 > }
90 } else {
91 if (this.bracketPairsTree.value) {
824 }
825
826 > function createDisposableRef<T>(object: T, disposable?: IDisposable): IReference<T> { bracketPairsImpl.ts
827 > return {
828 > object,
829 > dispose: () => disposable?.dispose(),
830 > };
831 > }
832
833 type ContinueBracketSearchPredicate = (() => boolean);
src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/bracketPairsTree.ts 17 introduced LOC · 6 ranges

Open complete file

52
53 public constructor(
54 > private readonly textModel: TextModel, bracketPairsTree.ts
55 > private readonly getLanguageConfiguration: (languageId: string) => ResolvedLanguageConfiguration
56 > ) {
57 > super();
58 > this.didChangeEmitter = this._register(new Emitter<void>());
59 > this.denseKeyProvider = new DenseKeyProvider<string>();
60 > this.brackets = new LanguageAgnosticBracketTokens(this.denseKeyProvider, this.getLanguageConfiguration);
61 > this.onDidChange = this.didChangeEmitter.event;
62 > this.queuedTextEditsForInitialAstWithoutTokens = [];
63 > this.queuedTextEdits = [];
64 >
65 > if (!textModel.tokenization.hasTokens) {
66 const brackets = this.brackets.getSingleLanguageBracketTokens(this.textModel.getLanguageId());
67 const tokenizer = new FastTokenizer(this.textModel.getValue(), brackets);
68 this.initialAstWithoutTokens = parseDocument(tokenizer, [], undefined, true);
69 this.astWithTokens = this.initialAstWithoutTokens;
70 > } else if (textModel.tokenization.backgroundTokenizationState === BackgroundTokenizationState.Completed) { bracketPairsTree.ts
71 // Skip the initial ast, as there is no flickering.
72 // Directly create the tree with token information.
78 this.astWithTokens = this.initialAstWithoutTokens;
79 }
81
82 //#region TextModel events
127
128 private flushQueue() {
129 > if (this.queuedTextEdits.length > 0) { bracketPairsTree.ts
130 this.astWithTokens = this.parseDocumentFromTextBuffer(this.queuedTextEdits, this.astWithTokens, false);
131 this.queuedTextEdits = [];
132 }
133 > if (this.queuedTextEditsForInitialAstWithoutTokens.length > 0) { bracketPairsTree.ts
134 if (this.initialAstWithoutTokens) {
135 this.initialAstWithoutTokens = this.parseDocumentFromTextBuffer(this.queuedTextEditsForInitialAstWithoutTokens, this.initialAstWithoutTokens, false);
137 this.queuedTextEditsForInitialAstWithoutTokens = [];
138 }
140
141 /**
src/vs/editor/common/model/textModel.ts 3 introduced LOC · 1 range

Open complete file

387
388 this._register(this._decorationProvider.onDidChange(() => {
389 > this._onDidChangeDecorations.beginDeferredEmit(); textModel.ts
390 > this._onDidChangeDecorations.fire();
391 > this._onDidChangeDecorations.endDeferredEmit();
392 }));
393 this._register(this._fontTokenDecorationsProvider.onDidChangeLineHeight((affectedLineHeights) => {
src/vs/editor/common/model/tokens/tokenizationTextModelPart.ts 2 introduced LOC · 1 range

Open complete file

180
181 public get hasTokens(): boolean {
182 > return this.tokens.get().hasTokens; tokenizationTextModelPart.ts
183 > }
184
185 public resetTokenization() {
src/vs/editor/common/model/tokens/tokenizerSyntaxTokenBackend.ts 2 introduced LOC · 1 range

Open complete file

src/vs/editor/common/tokens/contiguousTokensStore.ts 2 introduced LOC · 1 range

Open complete file

34
35 get hasTokens(): boolean {
36 > return this._lineTokens.length > 0; contiguousTokensStore.ts
37 > }
38
39 public getTokens(topLevelLanguageId: string, lineIndex: number, lineText: string): LineTokens {
src/vs/editor/common/model/bracketPairsTextModelPart/colorizedBracketPairsDecorationProvider.ts 1 introduced LOC · 1 range

Open complete file