Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1d89f95b
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,发现更多精彩内容 >>
提交
1d89f95b
编写于
3月 22, 2017
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #22984 and add unit tests
上级
00187b00
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
166 addition
and
10 deletion
+166
-10
.vscode/launch.json
.vscode/launch.json
+1
-0
src/vs/workbench/services/search/node/ripgrepTextSearch.ts
src/vs/workbench/services/search/node/ripgrepTextSearch.ts
+12
-10
src/vs/workbench/services/search/test/node/ripgrepTextSearch.test.ts
...bench/services/search/test/node/ripgrepTextSearch.test.ts
+153
-0
未找到文件。
.vscode/launch.json
浏览文件 @
1d89f95b
...
...
@@ -66,6 +66,7 @@
{
"type"
:
"node"
,
"request"
:
"attach"
,
"protocol"
:
"legacy"
,
"name"
:
"Attach to Search process"
,
"port"
:
7890
,
"sourceMaps"
:
true
,
...
...
src/vs/workbench/services/search/node/ripgrepTextSearch.ts
浏览文件 @
1d89f95b
...
...
@@ -88,6 +88,7 @@ export class RipgrepEngine implements ISearchEngine<ISerializedFileMatch> {
});
this
.
rgProc
.
on
(
'
close
'
,
code
=>
{
this
.
ripgrepParser
.
flush
();
// Get last result
this
.
rgProc
=
null
;
// console.log(`closed with ${code}`);
...
...
@@ -106,8 +107,8 @@ export class RipgrepParser extends EventEmitter {
private
static
RESULT_REGEX
=
/^
\u
001b
\[
m
(\d
+
)\u
001b
\[
m:
(
.*
)
$/
;
private
static
FILE_REGEX
=
/^
\u
001b
\[
m
(
.+
)\u
001b
\[
m$/
;
p
rivate
static
MATCH_START_MARKER
=
'
\
u001b[m
\
u001b[31m
'
;
p
rivate
static
MATCH_END_MARKER
=
'
\
u001b[m
'
;
p
ublic
static
MATCH_START_MARKER
=
'
\
u001b[m
\
u001b[31m
'
;
p
ublic
static
MATCH_END_MARKER
=
'
\
u001b[m
'
;
private
fileMatch
:
FileMatch
;
private
remainder
:
string
;
...
...
@@ -123,8 +124,14 @@ export class RipgrepParser extends EventEmitter {
this
.
isDone
=
true
;
}
public
flush
():
void
{
if
(
this
.
fileMatch
)
{
this
.
onResult
();
}
}
public
handleData
(
data
:
string
|
Buffer
):
void
{
// If the previous data chunk didn't end in a newline,
ap
pend it to this chunk
// If the previous data chunk didn't end in a newline,
pre
pend it to this chunk
const
dataStr
=
this
.
remainder
?
this
.
remainder
+
data
.
toString
()
:
data
.
toString
();
...
...
@@ -139,23 +146,18 @@ export class RipgrepParser extends EventEmitter {
}
let
r
:
RegExpMatchArray
;
if
(
!
outputLine
)
{
if
(
this
.
fileMatch
)
{
this
.
onResult
();
}
}
else
if
(
r
=
outputLine
.
match
(
RipgrepParser
.
RESULT_REGEX
))
{
if
(
r
=
outputLine
.
match
(
RipgrepParser
.
RESULT_REGEX
))
{
// Line is a result - add to collected results for the current file path
this
.
handleMatchLine
(
outputLine
,
parseInt
(
r
[
1
])
-
1
,
r
[
2
]);
}
else
if
(
r
=
outputLine
.
match
(
RipgrepParser
.
FILE_REGEX
))
{
// Line is a file path - send all collected results for the previous file path
if
(
this
.
fileMatch
)
{
// TODO@Rob Check fileMatch against other exclude globs
this
.
onResult
();
}
this
.
fileMatch
=
new
FileMatch
(
path
.
join
(
this
.
rootFolder
,
r
[
1
]));
}
else
{
// Line is
malformed
// Line is
empty (or malformed)
}
}
}
...
...
src/vs/workbench/services/search/test/node/ripgrepTextSearch.test.ts
0 → 100644
浏览文件 @
1d89f95b
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
path
=
require
(
'
path
'
);
import
assert
=
require
(
'
assert
'
);
import
*
as
arrays
from
'
vs/base/common/arrays
'
;
import
{
RipgrepParser
}
from
'
vs/workbench/services/search/node/ripgrepTextSearch
'
;
import
{
ISerializedFileMatch
}
from
'
vs/workbench/services/search/node/search
'
;
suite
(
'
RipgrepParser
'
,
()
=>
{
const
rootFolder
=
'
/workspace
'
;
const
fileSectionEnd
=
'
\n
'
;
function
getFileLine
(
relativePath
:
string
):
string
{
return
`\u001b\[m
${
relativePath
}
\u001b\[m`
;
}
function
getMatchLine
(
lineNum
:
number
,
matchParts
:
string
[]):
string
{
let
matchLine
=
`\u001b\[m
${
lineNum
}
\u001b\[m:`
+
`
${
matchParts
.
shift
()}${
RipgrepParser
.
MATCH_START_MARKER
}${
matchParts
.
shift
()}${
RipgrepParser
.
MATCH_END_MARKER
}${
matchParts
.
shift
()}
`
;
while
(
matchParts
.
length
)
{
matchLine
+=
`
${
RipgrepParser
.
MATCH_START_MARKER
}${
matchParts
.
shift
()}${
RipgrepParser
.
MATCH_END_MARKER
}${
matchParts
.
shift
()
||
''
}
`
;
}
return
matchLine
;
}
function
parseInput
(
inputChunks
:
string
[]):
ISerializedFileMatch
[]
{
const
matches
:
ISerializedFileMatch
[]
=
[];
const
rgp
=
new
RipgrepParser
(
1
e6
,
rootFolder
);
rgp
.
on
(
'
result
'
,
(
match
:
ISerializedFileMatch
)
=>
{
matches
.
push
(
match
);
});
inputChunks
.
forEach
(
chunk
=>
rgp
.
handleData
(
chunk
));
rgp
.
flush
();
return
matches
;
}
function
halve
(
str
:
string
)
{
const
halfIdx
=
Math
.
floor
(
str
.
length
/
2
);
return
[
str
.
substr
(
0
,
halfIdx
),
str
.
substr
(
halfIdx
)];
}
function
arrayOfChars
(
str
:
string
)
{
const
chars
=
[];
for
(
let
char
of
str
)
{
chars
.
push
(
char
);
}
return
chars
;
}
test
(
'
Parses one chunk
'
,
()
=>
{
const
input
=
[
[
getFileLine
(
'
a.txt
'
),
getMatchLine
(
1
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
getMatchLine
(
2
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
fileSectionEnd
].
join
(
'
\n
'
)
];
const
results
=
parseInput
(
input
);
assert
.
equal
(
results
.
length
,
1
);
assert
.
deepEqual
(
results
[
0
],
<
ISerializedFileMatch
>
{
numMatches
:
2
,
path
:
path
.
join
(
rootFolder
,
'
a.txt
'
),
lineMatches
:
[
{
lineNumber
:
0
,
preview
:
'
beforematchafter
'
,
offsetAndLengths
:
[[
6
,
5
]]
},
{
lineNumber
:
1
,
preview
:
'
beforematchafter
'
,
offsetAndLengths
:
[[
6
,
5
]]
}
]
});
});
test
(
'
Parses multiple chunks broken at file sections
'
,
()
=>
{
const
input
=
[
[
getFileLine
(
'
a.txt
'
),
getMatchLine
(
1
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
getMatchLine
(
2
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
fileSectionEnd
].
join
(
'
\n
'
),
[
getFileLine
(
'
b.txt
'
),
getMatchLine
(
1
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
getMatchLine
(
2
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
fileSectionEnd
].
join
(
'
\n
'
),
[
getFileLine
(
'
c.txt
'
),
getMatchLine
(
1
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
getMatchLine
(
2
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
fileSectionEnd
].
join
(
'
\n
'
)
];
const
results
=
parseInput
(
input
);
assert
.
equal
(
results
.
length
,
3
);
results
.
forEach
(
fileResult
=>
assert
.
equal
(
fileResult
.
numMatches
,
2
));
});
const
singleLineChunks
=
[
getFileLine
(
'
a.txt
'
),
getMatchLine
(
1
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
getMatchLine
(
2
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
fileSectionEnd
,
getFileLine
(
'
b.txt
'
),
getMatchLine
(
1
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
getMatchLine
(
2
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
fileSectionEnd
,
getFileLine
(
'
c.txt
'
),
getMatchLine
(
1
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
getMatchLine
(
2
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
fileSectionEnd
];
test
(
'
Parses multiple chunks broken at each line
'
,
()
=>
{
const
input
=
singleLineChunks
.
map
(
chunk
=>
chunk
+
'
\n
'
);
const
results
=
parseInput
(
input
);
assert
.
equal
(
results
.
length
,
3
);
results
.
forEach
(
fileResult
=>
assert
.
equal
(
fileResult
.
numMatches
,
2
));
});
test
(
'
Parses multiple chunks broken in the middle of each line
'
,
()
=>
{
const
input
=
arrays
.
flatten
(
singleLineChunks
.
map
(
chunk
=>
chunk
+
'
\n
'
)
.
map
(
halve
));
const
results
=
parseInput
(
input
);
assert
.
equal
(
results
.
length
,
3
);
results
.
forEach
(
fileResult
=>
assert
.
equal
(
fileResult
.
numMatches
,
2
));
});
test
(
'
Parses multiple chunks broken at each character
'
,
()
=>
{
const
input
=
arrays
.
flatten
(
singleLineChunks
.
map
(
chunk
=>
chunk
+
'
\n
'
)
.
map
(
arrayOfChars
));
const
results
=
parseInput
(
input
);
assert
.
equal
(
results
.
length
,
3
);
results
.
forEach
(
fileResult
=>
assert
.
equal
(
fileResult
.
numMatches
,
2
));
});
test
(
'
Parses chunks broken before newline
'
,
()
=>
{
const
input
=
arrays
.
flatten
(
singleLineChunks
.
map
(
chunk
=>
'
\n
'
+
chunk
)
.
map
(
arrayOfChars
));
const
results
=
parseInput
(
input
);
assert
.
equal
(
results
.
length
,
3
);
results
.
forEach
(
fileResult
=>
assert
.
equal
(
fileResult
.
numMatches
,
2
));
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录