smartSnippetInserter.ts ×11

Frontier kind: Code frontier

unlabeled · c_4f0e8c546095

7 tests · 41315 LOC · 240 files · introduces 0 tests · 62 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
11 ranges62 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5048 ranges41315 lines · 240 files · Browse complete extent
All tests (intent)
7 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: 62 introduced LOC across 11 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/preferences/common/smartSnippetInserter.ts 62 introduced LOC · 11 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- smartSnippetInserter.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 { JSONScanner, createScanner as createJSONScanner, SyntaxKind as JSONSyntaxKind } from '../../../../base/common/json.js';
7 > import { Position } from '../../../../editor/common/core/position.js';
8 > import { Range } from '../../../../editor/common/core/range.js';
9 > import { ITextModel } from '../../../../editor/common/model.js';
10 >
11 > export interface InsertSnippetResult {
12 > position: Position;
13 > prepend: string;
14 > append: string;
15 > }
16 >
17 > export class SmartSnippetInserter {
18 >
19 > private static hasOpenBrace(scanner: JSONScanner): boolean {
20
21 while (scanner.scan() !== JSONSyntaxKind.EOF) {
29 return false;
30 }
32 > private static offsetToPosition(model: ITextModel, offset: number): Position {
33 let offsetBeforeLine = 0;
34 const eolLength = model.getEOL().length;
51 );
52 }
54 > static insertSnippet(model: ITextModel, _position: Position): InsertSnippetResult {
55 >
56 > const desiredPosition = model.getValueLengthInRange(new Range(1, 1, _position.lineNumber, _position.column));
57 >
58 > // <INVALID> [ <BEFORE_OBJECT> { <INVALID> } <AFTER_OBJECT>, <BEFORE_OBJECT> { <INVALID> } <AFTER_OBJECT> ] <INVALID>
59 > enum State {
60 > INVALID = 0,
61 > AFTER_OBJECT = 1,
62 > BEFORE_OBJECT = 2,
63 > }
64 > let currentState = State.INVALID;
65 > let lastValidPos = -1;
66 > let lastValidState = State.INVALID;
67 >
68 > const scanner = createJSONScanner(model.getValue());
69 > let arrayLevel = 0;
70 > let objLevel = 0;
71 >
72 > const checkRangeStatus = (pos: number, state: State) => {
73 if (state !== State.INVALID && arrayLevel === 1 && objLevel === 0) {
74 currentState = state;
82 }
83 };
85 > while (scanner.scan() !== JSONSyntaxKind.EOF) {
86 > const currentPos = scanner.getPosition();
87 > const kind = scanner.getToken();
88 >
89 > let goodKind = false;
90 > switch (kind) {
91 > case JSONSyntaxKind.OpenBracketToken:
92 goodKind = true;
93 arrayLevel++;
94 checkRangeStatus(currentPos, State.BEFORE_OBJECT);
95 break;
96 > case JSONSyntaxKind.CloseBracketToken: smartSnippetInserter.ts
97 goodKind = true;
98 arrayLevel--;
99 checkRangeStatus(currentPos, State.INVALID);
100 break;
101 > case JSONSyntaxKind.CommaToken: smartSnippetInserter.ts
102 goodKind = true;
103 checkRangeStatus(currentPos, State.BEFORE_OBJECT);
104 break;
105 > case JSONSyntaxKind.OpenBraceToken: smartSnippetInserter.ts
106 goodKind = true;
107 objLevel++;
108 checkRangeStatus(currentPos, State.INVALID);
109 break;
110 > case JSONSyntaxKind.CloseBraceToken: smartSnippetInserter.ts
111 goodKind = true;
112 objLevel--;
113 checkRangeStatus(currentPos, State.AFTER_OBJECT);
114 break;
115 > case JSONSyntaxKind.Trivia: smartSnippetInserter.ts
116 > case JSONSyntaxKind.LineBreakTrivia:
117 > goodKind = true;
118 > }
119 >
120 > if (currentPos >= desiredPosition && (currentState !== State.INVALID || lastValidPos !== -1)) {
121 let acceptPosition: number;
122 let acceptState: State;