mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-13 11:38:36 -05:00
Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)
* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 * disable strict null check
This commit is contained in:
@@ -121,9 +121,10 @@ export class RipgrepTextSearchEngine {
|
||||
* "failed" when a fatal error was produced.
|
||||
*/
|
||||
export function rgErrorMsgForDisplay(msg: string): Maybe<SearchError> {
|
||||
const firstLine = msg.split('\n')[0].trim();
|
||||
const lines = msg.split('\n');
|
||||
const firstLine = lines[0].trim();
|
||||
|
||||
if (startsWith(firstLine, 'regex parse error')) {
|
||||
if (lines.some(l => startsWith(l, 'regex parse error'))) {
|
||||
return new SearchError('Regex parse error', SearchErrorCode.regexParseError);
|
||||
}
|
||||
|
||||
@@ -209,7 +210,7 @@ export class RipgrepParser extends EventEmitter {
|
||||
newlineIdx = dataStr.indexOf('\n', prevIdx);
|
||||
}
|
||||
|
||||
this.remainder = dataStr.substring(prevIdx).trim();
|
||||
this.remainder = dataStr.substring(prevIdx);
|
||||
}
|
||||
|
||||
private handleLine(outputLine: string): void {
|
||||
@@ -409,24 +410,25 @@ function getRgArgs(query: TextSearchQuery, options: TextSearchOptions): string[]
|
||||
|
||||
if ((<IExtendedExtensionSearchOptions>options).usePCRE2) {
|
||||
args.push('--pcre2');
|
||||
|
||||
if (query.isRegExp) {
|
||||
pattern = unicodeEscapesToPCRE2(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
if (query.isRegExp) {
|
||||
pattern = unicodeEscapesToPCRE2(pattern);
|
||||
}
|
||||
|
||||
// Allow $ to match /r/n
|
||||
args.push('--crlf');
|
||||
|
||||
let searchPatternAfterDoubleDashes: Maybe<string>;
|
||||
if (query.isWordMatch) {
|
||||
const regexp = createRegExp(pattern, !!query.isRegExp, { wholeWord: query.isWordMatch });
|
||||
const regexpStr = regexp.source.replace(/\\\//g, '/'); // RegExp.source arbitrarily returns escaped slashes. Search and destroy.
|
||||
args.push('--regexp', regexpStr);
|
||||
} else if (query.isRegExp) {
|
||||
let fixedRegexpQuery = fixRegexEndingPattern(query.pattern);
|
||||
fixedRegexpQuery = fixRegexNewline(fixedRegexpQuery);
|
||||
let fixedRegexpQuery = fixRegexNewline(query.pattern);
|
||||
fixedRegexpQuery = fixNewline(fixedRegexpQuery);
|
||||
fixedRegexpQuery = fixRegexCRMatchingNonWordClass(fixedRegexpQuery, !!query.isMultiline);
|
||||
fixedRegexpQuery = fixRegexCRMatchingWhitespaceClass(fixedRegexpQuery, !!query.isMultiline);
|
||||
args.push('--regexp', fixedRegexpQuery);
|
||||
args.push('--auto-hybrid-regex');
|
||||
} else {
|
||||
searchPatternAfterDoubleDashes = pattern;
|
||||
args.push('--fixed-strings');
|
||||
@@ -508,32 +510,12 @@ export interface IRgSubmatch {
|
||||
|
||||
export type IRgBytesOrText = { bytes: string } | { text: string };
|
||||
|
||||
export function fixRegexEndingPattern(pattern: string): string {
|
||||
// Replace an unescaped $ at the end of the pattern with \r?$
|
||||
// Match $ preceeded by none or even number of literal \
|
||||
return pattern.match(/([^\\]|^)(\\\\)*\$$/) ?
|
||||
pattern.replace(/\$$/, '\\r?$') :
|
||||
pattern;
|
||||
}
|
||||
|
||||
export function fixRegexNewline(pattern: string): string {
|
||||
// Replace an unescaped $ at the end of the pattern with \r?$
|
||||
// Match $ preceeded by none or even number of literal \
|
||||
return pattern.replace(/([^\\]|^)(\\\\)*\\n/g, '$1$2\\r?\\n');
|
||||
}
|
||||
|
||||
export function fixRegexCRMatchingWhitespaceClass(pattern: string, isMultiline: boolean): string {
|
||||
return isMultiline ?
|
||||
pattern.replace(/([^\\]|^)((?:\\\\)*)\\s/g, '$1$2(\\r?\\n|[^\\S\\r])') :
|
||||
pattern.replace(/([^\\]|^)((?:\\\\)*)\\s/g, '$1$2[ \\t\\f]');
|
||||
}
|
||||
|
||||
export function fixRegexCRMatchingNonWordClass(pattern: string, isMultiline: boolean): string {
|
||||
return isMultiline ?
|
||||
pattern.replace(/([^\\]|^)((?:\\\\)*)\\W/g, '$1$2(\\r?\\n|[^\\w\\r])') :
|
||||
pattern.replace(/([^\\]|^)((?:\\\\)*)\\W/g, '$1$2[^\\w\\r]');
|
||||
}
|
||||
|
||||
export function fixNewline(pattern: string): string {
|
||||
return pattern.replace(/\n/g, '\\r?\\n');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user