Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
042217fc
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,发现更多精彩内容 >>
提交
042217fc
编写于
5月 25, 2017
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #26708 - use StringDecoder to handle data chunks that split multibyte characters
上级
fe69f9ac
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
10 deletion
+42
-10
src/vs/workbench/services/search/node/ripgrepTextSearch.ts
src/vs/workbench/services/search/node/ripgrepTextSearch.ts
+13
-3
src/vs/workbench/services/search/test/node/ripgrepTextSearch.test.ts
...bench/services/search/test/node/ripgrepTextSearch.test.ts
+29
-7
未找到文件。
src/vs/workbench/services/search/node/ripgrepTextSearch.ts
浏览文件 @
042217fc
...
...
@@ -6,6 +6,7 @@
import
{
EventEmitter
}
from
'
events
'
;
import
*
as
path
from
'
path
'
;
import
{
StringDecoder
,
NodeStringDecoder
}
from
'
string_decoder
'
;
import
*
as
cp
from
'
child_process
'
;
import
{
rgPath
}
from
'
vscode-ripgrep
'
;
...
...
@@ -174,11 +175,13 @@ export class RipgrepParser extends EventEmitter {
private
fileMatch
:
FileMatch
;
private
remainder
:
string
;
private
isDone
:
boolean
;
private
stringDecoder
:
NodeStringDecoder
;
private
numResults
=
0
;
constructor
(
private
maxResults
:
number
,
private
rootFolder
:
string
)
{
super
();
this
.
stringDecoder
=
new
StringDecoder
();
}
public
cancel
():
void
{
...
...
@@ -186,16 +189,23 @@ export class RipgrepParser extends EventEmitter {
}
public
flush
():
void
{
this
.
handleDecodedData
(
this
.
stringDecoder
.
end
());
if
(
this
.
fileMatch
)
{
this
.
onResult
();
}
}
public
handleData
(
data
:
string
|
Buffer
):
void
{
public
handleData
(
data
:
Buffer
|
string
):
void
{
const
dataStr
=
typeof
data
===
'
string
'
?
data
:
this
.
stringDecoder
.
write
(
data
);
this
.
handleDecodedData
(
dataStr
);
}
private
handleDecodedData
(
decodedData
:
string
):
void
{
// If the previous data chunk didn't end in a newline, prepend it to this chunk
const
dataStr
=
this
.
remainder
?
this
.
remainder
+
d
ata
.
toString
()
:
d
ata
.
toString
()
;
this
.
remainder
+
d
ecodedData
:
d
ecodedData
;
const
dataLines
:
string
[]
=
dataStr
.
split
(
/
\r\n
|
\n
/
);
this
.
remainder
=
dataLines
[
dataLines
.
length
-
1
]
?
dataLines
.
pop
()
:
null
;
...
...
src/vs/workbench/services/search/test/node/ripgrepTextSearch.test.ts
浏览文件 @
042217fc
...
...
@@ -33,7 +33,11 @@ suite('RipgrepParser', () => {
return
matchLine
;
}
function
parseInput
(
inputChunks
:
string
[]):
ISerializedFileMatch
[]
{
function
parseInputStrings
(
inputChunks
:
string
[]):
ISerializedFileMatch
[]
{
return
parseInput
(
inputChunks
.
map
(
chunk
=>
new
Buffer
(
chunk
)));
}
function
parseInput
(
inputChunks
:
Buffer
[]):
ISerializedFileMatch
[]
{
const
matches
:
ISerializedFileMatch
[]
=
[];
const
rgp
=
new
RipgrepParser
(
1
e6
,
rootFolder
);
rgp
.
on
(
'
result
'
,
(
match
:
ISerializedFileMatch
)
=>
{
...
...
@@ -65,7 +69,7 @@ suite('RipgrepParser', () => {
[
getFileLine
(
'
a.txt
'
),
getMatchLine
(
1
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
getMatchLine
(
2
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
fileSectionEnd
].
join
(
'
\n
'
)
];
const
results
=
parseInput
(
input
);
const
results
=
parseInput
Strings
(
input
);
assert
.
equal
(
results
.
length
,
1
);
assert
.
deepEqual
(
results
[
0
],
<
ISerializedFileMatch
>
{
...
...
@@ -93,7 +97,7 @@ suite('RipgrepParser', () => {
[
getFileLine
(
'
c.txt
'
),
getMatchLine
(
1
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
getMatchLine
(
2
,
[
'
before
'
,
'
match
'
,
'
after
'
]),
fileSectionEnd
].
join
(
'
\n
'
)
];
const
results
=
parseInput
(
input
);
const
results
=
parseInput
Strings
(
input
);
assert
.
equal
(
results
.
length
,
3
);
results
.
forEach
(
fileResult
=>
assert
.
equal
(
fileResult
.
numMatches
,
2
));
});
...
...
@@ -116,7 +120,7 @@ suite('RipgrepParser', () => {
test
(
'
Parses multiple chunks broken at each line
'
,
()
=>
{
const
input
=
singleLineChunks
.
map
(
chunk
=>
chunk
+
'
\n
'
);
const
results
=
parseInput
(
input
);
const
results
=
parseInput
Strings
(
input
);
assert
.
equal
(
results
.
length
,
3
);
results
.
forEach
(
fileResult
=>
assert
.
equal
(
fileResult
.
numMatches
,
2
));
});
...
...
@@ -126,7 +130,7 @@ suite('RipgrepParser', () => {
.
map
(
chunk
=>
chunk
+
'
\n
'
)
.
map
(
halve
));
const
results
=
parseInput
(
input
);
const
results
=
parseInput
Strings
(
input
);
assert
.
equal
(
results
.
length
,
3
);
results
.
forEach
(
fileResult
=>
assert
.
equal
(
fileResult
.
numMatches
,
2
));
});
...
...
@@ -136,7 +140,7 @@ suite('RipgrepParser', () => {
.
map
(
chunk
=>
chunk
+
'
\n
'
)
.
map
(
arrayOfChars
));
const
results
=
parseInput
(
input
);
const
results
=
parseInput
Strings
(
input
);
assert
.
equal
(
results
.
length
,
3
);
results
.
forEach
(
fileResult
=>
assert
.
equal
(
fileResult
.
numMatches
,
2
));
});
...
...
@@ -145,8 +149,26 @@ suite('RipgrepParser', () => {
const
input
=
singleLineChunks
.
map
(
chunk
=>
'
\n
'
+
chunk
);
const
results
=
parseInput
(
input
);
const
results
=
parseInput
Strings
(
input
);
assert
.
equal
(
results
.
length
,
3
);
results
.
forEach
(
fileResult
=>
assert
.
equal
(
fileResult
.
numMatches
,
2
));
});
test
(
'
Parses chunks broken in the middle of a multibyte character
'
,
()
=>
{
const
multibyteStr
=
'
漢
'
;
const
multibyteBuf
=
new
Buffer
(
multibyteStr
);
const
text
=
getFileLine
(
'
foo/bar
'
)
+
'
\n
'
+
getMatchLine
(
0
,
[
'
before
'
,
'
match
'
,
'
after
'
])
+
'
\n
'
;
// Split the multibyte char into two pieces and divide between the two buffers
const
beforeIndex
=
24
;
const
inputBufs
=
[
Buffer
.
concat
([
new
Buffer
(
text
.
substr
(
0
,
beforeIndex
)),
multibyteBuf
.
slice
(
0
,
2
)]),
Buffer
.
concat
([
multibyteBuf
.
slice
(
2
),
new
Buffer
(
text
.
substr
(
beforeIndex
))])
];
const
results
=
parseInput
(
inputBufs
);
assert
.
equal
(
results
.
length
,
1
);
assert
.
equal
(
results
[
0
].
lineMatches
.
length
,
1
);
assert
.
deepEqual
(
results
[
0
].
lineMatches
[
0
].
offsetAndLengths
,
[[
7
,
5
]]);
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录