wordHelper.ts ×8

Frontier kind: Code frontier

unlabeled · c_fb3f1d1c7390

5 tests · 40643 LOC · 238 files · introduces 0 tests · 51 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
8 ranges51 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
4943 ranges40643 lines · 238 files · Browse complete extent
All tests (intent)
5 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: 51 introduced LOC across 8 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/core/wordHelper.ts 51 introduced LOC · 8 ranges

Open complete file

51
52 export function ensureValidWordDefinition(wordDefinition?: RegExp | null): RegExp {
53 > let result: RegExp = DEFAULT_WORD_REGEXP; wordHelper.ts
54 >
55 > if (wordDefinition && (wordDefinition instanceof RegExp)) {
56 > if (!wordDefinition.global) {
57 let flags = 'g';
58 if (wordDefinition.ignoreCase) {
66 }
67 result = new RegExp(wordDefinition.source, flags);
68 > } else { wordHelper.ts
69 > result = wordDefinition;
70 > }
71 > }
72 >
73 > result.lastIndex = 0;
74 >
75 > return result;
76 > }
77
78
97
98 export function getWordAtText(column: number, wordDefinition: RegExp, text: string, textOffset: number, config?: IGetWordAtTextConfig): IWordAtPosition | null {
99 > // Ensure the regex has the 'g' flag, otherwise this will loop forever wordHelper.ts
100 > wordDefinition = ensureValidWordDefinition(wordDefinition);
101 >
102 > if (!config) {
103 > config = Iterable.first(_defaultConfig)!;
104 > }
105 >
106 > if (text.length > config.maxLen) {
107 // don't throw strings that long at the regexp
108 // but use a sub-string in which a word must occur
116 return getWordAtText(column, wordDefinition, text, textOffset, config);
117 }
119 > const t1 = Date.now();
120 > const pos = column - 1 - textOffset;
121 >
122 > let prevRegexIndex = -1;
123 > let match: RegExpExecArray | null = null;
124 >
125 > for (let i = 1; ; i++) {
126 > // check time budget
127 > if (Date.now() - t1 >= config.timeBudget) {
128 break;
129 }
131 > // reset the index at which the regexp should start matching, also know where it
132 > // should stop so that subsequent search don't repeat previous searches
133 > const regexIndex = pos - config.windowSize * i;
134 > wordDefinition.lastIndex = Math.max(0, regexIndex);
135 > const thisMatch = _findRegexMatchEnclosingPosition(wordDefinition, text, pos, prevRegexIndex);
136 >
137 > if (!thisMatch && match) {
138 // stop: we have something
139 break;
140 }
142 > match = thisMatch;
143 >
144 > // stop: searched at start
145 > if (regexIndex <= 0) {
146 > break;
147 > }
148 prevRegexIndex = regexIndex;
149 }
151 > if (match) {
152 const result = {
153 word: match[0],
162 }
163
164 > function _findRegexMatchEnclosingPosition(wordDefinition: RegExp, text: string, pos: number, stopPos: number): RegExpExecArray | null { wordHelper.ts
165 > let match: RegExpExecArray | null;
166 > while (match = wordDefinition.exec(text)) {
167 const matchIndex = match.index || 0;
168 if (matchIndex <= pos && wordDefinition.lastIndex >= pos) {