1
>
/*---------------------------------------------------------------------------------------------
wordHelper.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 { Iterable } from '../../../base/common/iterator.js';
7
>
import { toDisposable } from '../../../base/common/lifecycle.js';
8
>
import { LinkedList } from '../../../base/common/linkedList.js';
9
>
10
>
export const USUAL_WORD_SEPARATORS = '`~!@#$%^&*()-=+[{]}\\|;:\'",.<>/?';
11
>
12
>
/**
13
>
* Word inside a model.
14
>
*/
15
>
export interface IWordAtPosition {
16
>
/**
17
>
* The word.
18
>
*/
19
>
readonly word: string;
20
>
/**
21
>
* The column where the word starts.
22
>
*/
23
>
readonly startColumn: number;
24
>
/**
25
>
* The column where the word ends.
26
>
*/
27
>
readonly endColumn: number;
28
>
}
29
>
30
>
/**
31
>
* Create a word definition regular expression based on default word separators.
32
>
* Optionally provide allowed separators that should be included in words.
33
>
*
34
>
* The default would look like this:
35
>
* /(-?\d*\.\d\w*)|([^\`\~\!\@\#\$\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g
36
>
*/
37
>
function createWordRegExp(allowInWords: string = ''): RegExp {
38
>
let source = '(-?\\d*\\.\\d\\w*)|([^';
39
>
for (const sep of USUAL_WORD_SEPARATORS) {
40
>
if (allowInWords.indexOf(sep) >= 0) {
41
continue;
42
}
44
>
}
45
>
source += '\\s]+)';
46
>
return new RegExp(source, 'g');
47
>
}
48
>
49
>
// catches numbers (including floating numbers) in the first group, and alphanum in the second
50
>
export const DEFAULT_WORD_REGEXP = createWordRegExp();
51
>
52
>
export function ensureValidWordDefinition(wordDefinition?: RegExp | null): RegExp {
53
let result: RegExp = DEFAULT_WORD_REGEXP;
54