Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
c7a24d09
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c7a24d09
编写于
11月 07, 2018
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #36309 - remap \W, \s, and \n in regex to match editor regex search
上级
0f4fab15
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
80 addition
and
25 deletion
+80
-25
src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts
...workbench/services/search/node/ripgrepTextSearchEngine.ts
+15
-13
src/vs/workbench/services/search/test/node/ripgrepTextSearchEngine.test.ts
...services/search/test/node/ripgrepTextSearchEngine.test.ts
+65
-12
未找到文件。
src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts
浏览文件 @
c7a24d09
...
...
@@ -357,7 +357,11 @@ function getRgArgs(query: vscode.TextSearchQuery, options: vscode.TextSearchOpti
const
regexpStr
=
regexp
.
source
.
replace
(
/
\\\/
/g
,
'
/
'
);
// RegExp.source arbitrarily returns escaped slashes. Search and destroy.
args
.
push
(
'
--regexp
'
,
regexpStr
);
}
else
if
(
query
.
isRegExp
)
{
args
.
push
(
'
--regexp
'
,
fixRegexEndingPattern
(
query
.
pattern
));
let
fixedRegexpQuery
=
fixRegexEndingPattern
(
query
.
pattern
);
fixedRegexpQuery
=
fixRegexNewline
(
fixedRegexpQuery
);
fixedRegexpQuery
=
fixRegexCRMatchingNonWordClass
(
fixedRegexpQuery
,
query
.
isMultiline
);
fixedRegexpQuery
=
fixRegexCRMatchingWhitespaceClass
(
fixedRegexpQuery
,
query
.
isMultiline
);
args
.
push
(
'
--regexp
'
,
fixedRegexpQuery
);
}
else
{
searchPatternAfterDoubleDashes
=
pattern
;
args
.
push
(
'
--fixed-strings
'
);
...
...
@@ -435,22 +439,20 @@ export function fixRegexEndingPattern(pattern: string): string {
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/
,
(
prefix1
,
prefix2
)
=>
{
return
prefix1
+
prefix2
+
'
(
\\
r?
\\
n|[^
\\
S
\\
r])
'
;
})
:
pattern
.
replace
(
/
([^\\]
|^
)((?:\\\\)
*
)\\
s/
,
(
prefix1
,
prefix2
)
=>
{
return
prefix1
+
prefix2
+
'
[
\\
t
\\
f]
'
;
});
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/
,
(
prefix1
,
prefix2
)
=>
{
return
prefix1
+
prefix2
+
'
(
\\
r?
\\
n|[^
\\
w
\\
r])
'
;
})
:
pattern
.
replace
(
/
([^\\]
|^
)((?:\\\\)
*
)\\
W/
,
(
prefix1
,
prefix2
)
=>
{
return
prefix1
+
prefix2
+
'
[^
\\
w
\\
r]
'
;
});
pattern
.
replace
(
/
([^\\]
|^
)((?:\\\\)
*
)\\
W/g
,
'
$1$2(
\\
r?
\\
n|[^
\\
w
\\
r])
'
)
:
pattern
.
replace
(
/
([^\\]
|^
)((?:\\\\)
*
)\\
W/g
,
'
$1$2[^
\\
w
\\
r]
'
);
}
src/vs/workbench/services/search/test/node/ripgrepTextSearchEngine.test.ts
浏览文件 @
c7a24d09
...
...
@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'
assert
'
;
import
{
unicodeEscapesToPCRE2
,
fixRegexEndingPattern
}
from
'
vs/workbench/services/search/node/ripgrepTextSearchEngine
'
;
import
{
unicodeEscapesToPCRE2
,
fixRegexEndingPattern
,
fixRegexCRMatchingWhitespaceClass
,
fixRegexCRMatchingNonWordClass
,
fixRegexNewline
}
from
'
vs/workbench/services/search/node/ripgrepTextSearchEngine
'
;
suite
(
'
RipgrepTextSearchEngine
'
,
()
=>
{
test
(
'
unicodeEscapesToPCRE2
'
,
async
()
=>
{
...
...
@@ -37,19 +37,72 @@ suite('RipgrepTextSearchEngine', () => {
].
forEach
(
testFixRegexEndingPattern
);
});
test
(
'
fixRegexEndingPattern
'
,
()
=>
{
function
testFixRegexEndingPattern
([
input
,
expectedResult
]:
string
[]):
void
{
assert
.
equal
(
fixRegexEndingPattern
(
input
),
expectedResult
);
test
(
'
fixRegexCRMatchingWhitespaceClass
'
,
()
=>
{
function
testFixRegexCRMatchingWhitespaceClass
([
inputReg
,
isMultiline
,
testStr
,
shouldMatch
]):
void
{
const
fixed
=
fixRegexCRMatchingWhitespaceClass
(
inputReg
,
isMultiline
);
const
reg
=
new
RegExp
(
fixed
);
assert
.
equal
(
reg
.
test
(
testStr
),
shouldMatch
,
`
${
inputReg
}
=>
${
reg
}
,
${
testStr
}
,
${
shouldMatch
}
`
);
}
[
[
'
foo
'
,
'
foo
'
],
[
''
,
''
],
[
'
^foo.*bar
\\
s+
'
,
'
^foo.*bar
\\
s+
'
],
[
'
foo$
'
,
'
foo
\\
r?$
'
],
[
'
$
'
,
'
\\
r?$
'
],
[
'
foo
\\
$
'
,
'
foo
\\
$
'
],
[
'
foo
\\\\
$
'
,
'
foo
\\\\\\
r?$
'
],
].
forEach
(
testFixRegexEndingPattern
);
[
'
foo
'
,
false
,
'
foo
'
,
true
],
[
'
foo
\\
s
'
,
false
,
'
foo
\r\n
'
,
false
],
[
'
foo
\\
sabc
'
,
true
,
'
foo
\r\n
abc
'
,
true
],
[
'
foo
\\
s
'
,
false
,
'
foo
\n
'
,
false
],
[
'
foo
\\
s
'
,
true
,
'
foo
\n
'
,
true
],
[
'
foo
\\
s
\\
n
'
,
true
,
'
foo
\r\n
'
,
false
],
[
'
foo
\\
r
\\
s
'
,
true
,
'
foo
\r\n
'
,
true
],
[
'
foo
\\
s+abc
'
,
true
,
'
foo
\r\n
abc
'
,
true
],
[
'
foo
\\
s+abc
'
,
false
,
'
foo
\t
abc
'
,
true
],
].
forEach
(
testFixRegexCRMatchingWhitespaceClass
);
});
test
(
'
fixRegexCRMatchingNonWordClass
'
,
()
=>
{
function
testRegexCRMatchingNonWordClass
([
inputReg
,
isMultiline
,
testStr
,
shouldMatch
]):
void
{
const
fixed
=
fixRegexCRMatchingNonWordClass
(
inputReg
,
isMultiline
);
const
reg
=
new
RegExp
(
fixed
);
assert
.
equal
(
reg
.
test
(
testStr
),
shouldMatch
,
`
${
inputReg
}
=>
${
reg
}
,
${
testStr
}
,
${
shouldMatch
}
`
);
}
[
[
'
foo
'
,
false
,
'
foo
'
,
true
],
[
'
foo
\\
W
'
,
false
,
'
foo
\r\n
'
,
false
],
[
'
foo
\\
Wabc
'
,
true
,
'
foo
\r\n
abc
'
,
true
],
[
'
foo
\\
W
'
,
false
,
'
foo
\n
'
,
true
],
[
'
foo
\\
W
'
,
true
,
'
foo
\n
'
,
true
],
[
'
foo
\\
W
\\
n
'
,
true
,
'
foo
\r\n
'
,
false
],
[
'
foo
\\
r
\\
W
'
,
true
,
'
foo
\r\n
'
,
true
],
[
'
foo
\\
W+abc
'
,
true
,
'
foo
\r\n
abc
'
,
true
],
[
'
foo
\\
W+abc
'
,
false
,
'
foo .-
\t
abc
'
,
true
],
].
forEach
(
testRegexCRMatchingNonWordClass
);
});
test
(
'
fixRegexNewline
'
,
()
=>
{
function
testFixRegexNewline
([
inputReg
,
testStr
,
shouldMatch
]):
void
{
const
fixed
=
fixRegexNewline
(
inputReg
);
const
reg
=
new
RegExp
(
fixed
);
assert
.
equal
(
reg
.
test
(
testStr
),
shouldMatch
,
`
${
inputReg
}
=>
${
reg
}
,
${
testStr
}
,
${
shouldMatch
}
`
);
}
[
[
'
foo
'
,
'
foo
'
,
true
],
[
'
foo
\\
n
'
,
'
foo
\r\n
'
,
true
],
[
'
foo
\\
n
'
,
'
foo
\n
'
,
true
],
[
'
foo
\\
nabc
'
,
'
foo
\r\n
abc
'
,
true
],
[
'
foo
\\
nabc
'
,
'
foo
\n
abc
'
,
true
],
[
'
foo
\\
r
\\
n
'
,
'
foo
\r\n
'
,
true
],
[
'
foo
\\
n+abc
'
,
'
foo
\r\n
abc
'
,
true
],
[
'
foo
\\
n+abc
'
,
'
foo
\n\n\n
abc
'
,
true
],
].
forEach
(
testFixRegexNewline
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录