Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
3b573a0e
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,发现更多精彩内容 >>
提交
3b573a0e
编写于
11月 21, 2018
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a couple RipgrepParser tests
上级
2cbcd647
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
152 addition
and
5 deletion
+152
-5
src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts
...workbench/services/search/node/ripgrepTextSearchEngine.ts
+11
-4
src/vs/workbench/services/search/test/node/ripgrepTextSearchEngine.test.ts
...services/search/test/node/ripgrepTextSearchEngine.test.ts
+141
-1
未找到文件。
src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts
浏览文件 @
3b573a0e
...
...
@@ -161,6 +161,13 @@ export class RipgrepParser extends EventEmitter {
this
.
handleDecodedData
(
this
.
stringDecoder
.
end
());
}
on
(
event
:
'
result
'
,
listener
:
(
result
:
vscode
.
TextSearchResult
)
=>
void
);
on
(
event
:
'
hitLimit
'
,
listener
:
()
=>
void
);
on
(
event
:
string
,
listener
:
(...
args
:
any
[])
=>
void
)
{
super
.
on
(
event
,
listener
);
}
public
handleData
(
data
:
Buffer
|
string
):
void
{
if
(
this
.
isDone
)
{
return
;
...
...
@@ -427,12 +434,12 @@ export function unicodeEscapesToPCRE2(pattern: string): string {
return
pattern
;
}
interface
IRgMessage
{
export
interface
IRgMessage
{
type
:
'
match
'
|
'
context
'
|
string
;
data
:
IRgMatch
;
}
interface
IRgMatch
{
export
interface
IRgMatch
{
path
:
IRgBytesOrText
;
lines
:
IRgBytesOrText
;
line_number
:
number
;
...
...
@@ -440,13 +447,13 @@ interface IRgMatch {
submatches
:
IRgSubmatch
[];
}
interface
IRgSubmatch
{
export
interface
IRgSubmatch
{
match
:
IRgBytesOrText
;
start
:
number
;
end
:
number
;
}
type
IRgBytesOrText
=
{
bytes
:
string
}
|
{
text
:
string
};
export
type
IRgBytesOrText
=
{
bytes
:
string
}
|
{
text
:
string
};
export
function
fixRegexEndingPattern
(
pattern
:
string
):
string
{
// Replace an unescaped $ at the end of the pattern with \r?$
...
...
src/vs/workbench/services/search/test/node/ripgrepTextSearchEngine.test.ts
浏览文件 @
3b573a0e
...
...
@@ -4,7 +4,11 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'
assert
'
;
import
{
unicodeEscapesToPCRE2
,
fixRegexEndingPattern
,
fixRegexCRMatchingWhitespaceClass
,
fixRegexCRMatchingNonWordClass
,
fixRegexNewline
}
from
'
vs/workbench/services/search/node/ripgrepTextSearchEngine
'
;
import
{
joinPath
}
from
'
vs/base/common/resources
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
Range
}
from
'
vs/workbench/services/search/node/ripgrepSearchUtils
'
;
import
{
fixRegexCRMatchingNonWordClass
,
fixRegexCRMatchingWhitespaceClass
,
fixRegexEndingPattern
,
fixRegexNewline
,
IRgMatch
,
IRgMessage
,
RipgrepParser
,
unicodeEscapesToPCRE2
}
from
'
vs/workbench/services/search/node/ripgrepTextSearchEngine
'
;
import
{
TextSearchResult
}
from
'
vscode
'
;
suite
(
'
RipgrepTextSearchEngine
'
,
()
=>
{
test
(
'
unicodeEscapesToPCRE2
'
,
async
()
=>
{
...
...
@@ -105,4 +109,140 @@ suite('RipgrepTextSearchEngine', () => {
[
'
foo
\\
n+abc
'
,
'
foo
\n\n\n
abc
'
,
true
],
].
forEach
(
testFixRegexNewline
);
});
suite
(
'
RipgrepParser
'
,
()
=>
{
const
TEST_FOLDER
=
URI
.
file
(
'
/foo/bar
'
);
function
testParser
(
inputData
:
string
[],
expectedResults
:
TextSearchResult
[]):
void
{
const
testParser
=
new
RipgrepParser
(
1000
,
TEST_FOLDER
.
fsPath
);
const
actualResults
=
[];
testParser
.
on
(
'
result
'
,
r
=>
{
actualResults
.
push
(
r
);
});
inputData
.
forEach
(
d
=>
testParser
.
handleData
(
d
));
testParser
.
flush
();
assert
.
deepEqual
(
actualResults
,
expectedResults
);
}
function
makeRgMatch
(
relativePath
:
string
,
text
:
string
,
lineNumber
:
number
,
matchRanges
:
{
start
:
number
,
end
:
number
}[]):
string
{
return
JSON
.
stringify
(
<
IRgMessage
>
{
type
:
'
match
'
,
data
:
<
IRgMatch
>
{
path
:
{
text
:
relativePath
},
lines
:
{
text
},
line_number
:
lineNumber
,
absolute_offset
:
0
,
// unused
submatches
:
matchRanges
.
map
(
mr
=>
{
return
{
...
mr
,
match
:
{
text
:
text
.
substring
(
mr
.
start
,
mr
.
end
)
}
};
})
}
})
+
'
\n
'
;
}
test
(
'
single result
'
,
()
=>
{
testParser
(
[
makeRgMatch
(
'
file1.js
'
,
'
foobar
'
,
4
,
[{
start
:
3
,
end
:
6
}])
],
[
{
preview
:
{
text
:
'
foobar
'
,
matches
:
[
new
Range
(
0
,
3
,
0
,
6
)]
},
uri
:
joinPath
(
TEST_FOLDER
,
'
file1.js
'
),
ranges
:
[
new
Range
(
3
,
3
,
3
,
6
)]
}
]);
});
test
(
'
multiple results
'
,
()
=>
{
testParser
(
[
makeRgMatch
(
'
file1.js
'
,
'
foobar
'
,
4
,
[{
start
:
3
,
end
:
6
}]),
makeRgMatch
(
'
app/file2.js
'
,
'
foobar
'
,
4
,
[{
start
:
3
,
end
:
6
}]),
makeRgMatch
(
'
app2/file3.js
'
,
'
foobar
'
,
4
,
[{
start
:
3
,
end
:
6
}]),
],
[
{
preview
:
{
text
:
'
foobar
'
,
matches
:
[
new
Range
(
0
,
3
,
0
,
6
)]
},
uri
:
joinPath
(
TEST_FOLDER
,
'
file1.js
'
),
ranges
:
[
new
Range
(
3
,
3
,
3
,
6
)]
},
{
preview
:
{
text
:
'
foobar
'
,
matches
:
[
new
Range
(
0
,
3
,
0
,
6
)]
},
uri
:
joinPath
(
TEST_FOLDER
,
'
app/file2.js
'
),
ranges
:
[
new
Range
(
3
,
3
,
3
,
6
)]
},
{
preview
:
{
text
:
'
foobar
'
,
matches
:
[
new
Range
(
0
,
3
,
0
,
6
)]
},
uri
:
joinPath
(
TEST_FOLDER
,
'
app2/file3.js
'
),
ranges
:
[
new
Range
(
3
,
3
,
3
,
6
)]
}
]);
});
test
(
'
chopped-up input chunks
'
,
()
=>
{
const
dataStrs
=
[
makeRgMatch
(
'
file1.js
'
,
'
foobar
'
,
4
,
[{
start
:
3
,
end
:
6
}]),
makeRgMatch
(
'
app/file2.js
'
,
'
foobar
'
,
4
,
[{
start
:
3
,
end
:
6
}]),
makeRgMatch
(
'
app2/file3.js
'
,
'
foobar
'
,
4
,
[{
start
:
3
,
end
:
6
}]),
];
testParser
(
[
dataStrs
[
0
].
substring
(
0
,
5
),
dataStrs
[
0
].
substring
(
5
),
'
\n
'
,
dataStrs
[
1
].
trim
(),
'
\n
'
+
dataStrs
[
2
].
substring
(
0
,
25
),
dataStrs
[
2
].
substring
(
25
)
],
[
{
preview
:
{
text
:
'
foobar
'
,
matches
:
[
new
Range
(
0
,
3
,
0
,
6
)]
},
uri
:
joinPath
(
TEST_FOLDER
,
'
file1.js
'
),
ranges
:
[
new
Range
(
3
,
3
,
3
,
6
)]
},
{
preview
:
{
text
:
'
foobar
'
,
matches
:
[
new
Range
(
0
,
3
,
0
,
6
)]
},
uri
:
joinPath
(
TEST_FOLDER
,
'
app/file2.js
'
),
ranges
:
[
new
Range
(
3
,
3
,
3
,
6
)]
},
{
preview
:
{
text
:
'
foobar
'
,
matches
:
[
new
Range
(
0
,
3
,
0
,
6
)]
},
uri
:
joinPath
(
TEST_FOLDER
,
'
app2/file3.js
'
),
ranges
:
[
new
Range
(
3
,
3
,
3
,
6
)]
}
]);
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录