Remove check for lookbehind support in regex

We no longer support VSCode versions older than 1.37.0, and this was fixed in 1.31.0
This commit is contained in:
Jason Fields 2020-05-11 12:10:36 -04:00
parent bd5b3945f2
commit 1d273ebb33

View File

@ -589,32 +589,23 @@ export class Position extends vscode.Position {
const escaped = characterSet && _.escapeRegExp(characterSet).replace(/-/g, '\\-');
const segments: string[] = [];
// old versions of VSCode before 1.31 will crash when trying to parse a regex with a lookbehind
let supportsLookbehind = true;
try {
// tslint:disable-next-line
new RegExp('(<=x)');
} catch {
supportsLookbehind = false;
}
// prettier-ignore
const firstSegment =
'(' + // OPEN: group for matching camel case words
`[^\\s${escaped}]` + // words can start with any word character
'(?:' + // OPEN: group for characters after initial char
`(?:${supportsLookbehind ? '(?<=[A-Z_])' : ''}` + // If first char was a capital
`[A-Z](?=[\\sA-Z0-9${escaped}_]))+` + // the word can continue with all caps
'|' + // OR
`(?:${supportsLookbehind ? '(?<=[0-9_])' : ''}` + // If first char was a digit
`[0-9](?=[\\sA-Z0-9${escaped}_]))+` + // the word can continue with all digits
'|' + // OR
`(?:${supportsLookbehind ? '(?<=[_])' : ''}` + // If first char was an underscore
`[_](?=[\\s${escaped}_]))+` + // the word can continue with all underscores
'|' + // OR
`[^\\sA-Z0-9${escaped}_]*` + // Continue with regular characters
')' + // END: group for characters after initial char
')' + // END: group for matching camel case words
'(' + // OPEN: group for matching camel case words
`[^\\s${escaped}]` + // words can start with any word character
'(?:' + // OPEN: group for characters after initial char
`(?:(?<=[A-Z_])` + // If first char was a capital
`[A-Z](?=[\\sA-Z0-9${escaped}_]))+` + // the word can continue with all caps
'|' + // OR
`(?:(?<=[0-9_])` + // If first char was a digit
`[0-9](?=[\\sA-Z0-9${escaped}_]))+` + // the word can continue with all digits
'|' + // OR
`(?:(?<=[_])` + // If first char was an underscore
`[_](?=[\\s${escaped}_]))+` + // the word can continue with all underscores
'|' + // OR
`[^\\sA-Z0-9${escaped}_]*` + // Continue with regular characters
')' + // END: group for characters after initial char
')' + // END: group for matching camel case words
'';
segments.push(firstSegment);