Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1926da78
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,发现更多精彩内容 >>
提交
1926da78
编写于
10月 26, 2018
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#59458 for editor matches, tests
上级
9a6cd0a3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
187 addition
and
5 deletion
+187
-5
src/vs/workbench/services/search/common/searchHelpers.ts
src/vs/workbench/services/search/common/searchHelpers.ts
+48
-1
src/vs/workbench/services/search/node/searchService.ts
src/vs/workbench/services/search/node/searchService.ts
+3
-3
src/vs/workbench/services/search/test/common/searchHelpers.test.ts
...rkbench/services/search/test/common/searchHelpers.test.ts
+136
-1
未找到文件。
src/vs/workbench/services/search/common/searchHelpers.ts
浏览文件 @
1926da78
...
...
@@ -5,7 +5,7 @@
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
FindMatch
,
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
ITextSearchPreviewOptions
,
TextSearchMatch
}
from
'
vs/platform/search/common/search
'
;
import
{
ITextSearchPreviewOptions
,
TextSearchMatch
,
ITextSearchResult
,
ITextSearchMatch
,
ITextQuery
,
ITextSearchContext
}
from
'
vs/platform/search/common/search
'
;
function
editorMatchToTextSearchResult
(
matches
:
FindMatch
[],
model
:
ITextModel
,
previewOptions
?:
ITextSearchPreviewOptions
):
TextSearchMatch
{
const
firstLine
=
matches
[
0
].
range
.
startLineNumber
;
...
...
@@ -43,4 +43,51 @@ export function editorMatchesToTextSearchResults(matches: FindMatch[], model: IT
return
groupedMatches
.
map
(
sameLineMatches
=>
{
return
editorMatchToTextSearchResult
(
sameLineMatches
,
model
,
previewOptions
);
});
}
export
function
addContextToEditorMatches
(
matches
:
ITextSearchMatch
[],
model
:
ITextModel
,
query
:
ITextQuery
):
ITextSearchResult
[]
{
const
results
:
ITextSearchResult
[]
=
[];
let
prevLine
=
-
1
;
for
(
let
i
=
0
;
i
<
matches
.
length
;
i
++
)
{
const
{
start
:
matchStartLine
,
end
:
matchEndLine
}
=
getMatchStartEnd
(
matches
[
i
]);
if
(
query
.
beforeContext
>
0
)
{
const
beforeContextStartLine
=
Math
.
max
(
prevLine
+
1
,
matchStartLine
-
query
.
beforeContext
);
for
(
let
b
=
beforeContextStartLine
;
b
<
matchStartLine
;
b
++
)
{
results
.
push
(
<
ITextSearchContext
>
{
text
:
model
.
getLineContent
(
b
+
1
),
lineNumber
:
b
});
}
}
results
.
push
(
matches
[
i
]);
const
nextMatch
=
matches
[
i
+
1
];
let
nextMatchStartLine
=
nextMatch
?
getMatchStartEnd
(
nextMatch
).
start
:
Number
.
MAX_VALUE
;
if
(
query
.
afterContext
>
0
)
{
const
afterContextToLine
=
Math
.
min
(
nextMatchStartLine
-
1
,
matchEndLine
+
query
.
afterContext
,
model
.
getLineCount
()
-
1
);
for
(
let
a
=
matchEndLine
+
1
;
a
<=
afterContextToLine
;
a
++
)
{
results
.
push
(
<
ITextSearchContext
>
{
text
:
model
.
getLineContent
(
a
+
1
),
lineNumber
:
a
});
}
}
prevLine
=
matchEndLine
;
}
return
results
;
}
function
getMatchStartEnd
(
match
:
ITextSearchMatch
):
{
start
:
number
,
end
:
number
}
{
const
matchRanges
=
match
.
ranges
;
const
matchStartLine
=
Array
.
isArray
(
matchRanges
)
?
matchRanges
[
0
].
startLineNumber
:
matchRanges
.
startLineNumber
;
const
matchEndLine
=
Array
.
isArray
(
matchRanges
)
?
matchRanges
[
matchRanges
.
length
-
1
].
endLineNumber
:
matchRanges
.
endLineNumber
;
return
{
start
:
matchStartLine
,
end
:
matchEndLine
};
}
\ No newline at end of file
src/vs/workbench/services/search/node/searchService.ts
浏览文件 @
1926da78
...
...
@@ -26,7 +26,7 @@ import { FileMatch, ICachedSearchStats, IFileMatch, IFileQuery, IFileSearchStats
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IExtensionService
}
from
'
vs/workbench/services/extensions/common/extensions
'
;
import
{
editorMatchesToTextSearchResults
}
from
'
vs/workbench/services/search/common/searchHelpers
'
;
import
{
addContextToEditorMatches
,
editorMatchesToTextSearchResults
}
from
'
vs/workbench/services/search/common/searchHelpers
'
;
import
{
IUntitledEditorService
}
from
'
vs/workbench/services/untitled/common/untitledEditorService
'
;
import
{
IRawSearchService
,
ISerializedFileMatch
,
ISerializedSearchComplete
,
ISerializedSearchProgressItem
,
isSerializedSearchComplete
,
isSerializedSearchSuccess
}
from
'
./search
'
;
import
{
ISearchChannel
,
SearchChannelClient
}
from
'
./searchIpc
'
;
...
...
@@ -422,7 +422,8 @@ export class SearchService extends Disposable implements ISearchService {
let
fileMatch
=
new
FileMatch
(
resource
);
localResults
.
set
(
resource
,
fileMatch
);
fileMatch
.
results
=
editorMatchesToTextSearchResults
(
matches
,
model
,
query
.
previewOptions
);
const
textSearchResults
=
editorMatchesToTextSearchResults
(
matches
,
model
,
query
.
previewOptions
);
fileMatch
.
results
=
addContextToEditorMatches
(
textSearchResults
,
model
,
query
);
}
else
{
localResults
.
set
(
resource
,
null
);
}
...
...
@@ -591,4 +592,3 @@ export class DiskSearch implements ISearchResultProvider {
return
this
.
raw
.
clearCache
(
cacheKey
);
}
}
src/vs/workbench/services/search/test/common/searchHelpers.test.ts
浏览文件 @
1926da78
...
...
@@ -5,8 +5,9 @@
import
*
as
assert
from
'
assert
'
;
import
{
ITextModel
,
FindMatch
}
from
'
vs/editor/common/model
'
;
import
{
editorMatchesToTextSearchResults
}
from
'
vs/workbench/services/search/common/searchHelpers
'
;
import
{
editorMatchesToTextSearchResults
,
addContextToEditorMatches
}
from
'
vs/workbench/services/search/common/searchHelpers
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
ITextQuery
,
QueryType
,
ITextSearchContext
}
from
'
vs/platform/search/common/search
'
;
suite
(
'
editorMatchesToTextSearchResults
'
,
()
=>
{
const
mockTextModel
:
ITextModel
=
<
ITextModel
>
{
...
...
@@ -50,4 +51,138 @@ suite('editorMatchesToTextSearchResults', () => {
]);
assert
.
equal
(
results
[
1
].
preview
.
text
,
'
9
\n
10
'
);
});
});
suite
(
'
addContextToEditorMatches
'
,
()
=>
{
const
MOCK_LINE_COUNT
=
100
;
const
mockTextModel
:
ITextModel
=
<
ITextModel
>
{
getLineContent
(
lineNumber
:
number
):
string
{
if
(
lineNumber
<
1
||
lineNumber
>
MOCK_LINE_COUNT
)
{
throw
new
Error
(
`invalid line count:
${
lineNumber
}
`
);
}
return
''
+
lineNumber
;
},
getLineCount
():
number
{
return
MOCK_LINE_COUNT
;
}
};
function
getQuery
(
beforeContext
?:
number
,
afterContext
?:
number
):
ITextQuery
{
return
{
type
:
QueryType
.
Text
,
contentPattern
:
{
pattern
:
'
test
'
},
beforeContext
,
afterContext
};
}
test
(
'
no context
'
,
()
=>
{
const
matches
=
[{
preview
:
{
text
:
'
foo
'
,
matches
:
new
Range
(
0
,
0
,
0
,
10
)
},
ranges
:
new
Range
(
0
,
0
,
0
,
10
)
}];
assert
.
deepEqual
(
addContextToEditorMatches
(
matches
,
mockTextModel
,
getQuery
()),
matches
);
});
test
(
'
simple
'
,
()
=>
{
const
matches
=
[{
preview
:
{
text
:
'
foo
'
,
matches
:
new
Range
(
0
,
0
,
0
,
10
)
},
ranges
:
new
Range
(
1
,
0
,
1
,
10
)
}];
assert
.
deepEqual
(
addContextToEditorMatches
(
matches
,
mockTextModel
,
getQuery
(
1
,
2
)),
[
<
ITextSearchContext
>
{
text
:
'
1
'
,
lineNumber
:
0
},
...
matches
,
<
ITextSearchContext
>
{
text
:
'
3
'
,
lineNumber
:
2
},
<
ITextSearchContext
>
{
text
:
'
4
'
,
lineNumber
:
3
},
]);
});
test
(
'
multiple matches next to each other
'
,
()
=>
{
const
matches
=
[
{
preview
:
{
text
:
'
foo
'
,
matches
:
new
Range
(
0
,
0
,
0
,
10
)
},
ranges
:
new
Range
(
1
,
0
,
1
,
10
)
},
{
preview
:
{
text
:
'
bar
'
,
matches
:
new
Range
(
0
,
0
,
0
,
10
)
},
ranges
:
new
Range
(
2
,
0
,
2
,
10
)
}];
assert
.
deepEqual
(
addContextToEditorMatches
(
matches
,
mockTextModel
,
getQuery
(
1
,
2
)),
[
<
ITextSearchContext
>
{
text
:
'
1
'
,
lineNumber
:
0
},
...
matches
,
<
ITextSearchContext
>
{
text
:
'
4
'
,
lineNumber
:
3
},
<
ITextSearchContext
>
{
text
:
'
5
'
,
lineNumber
:
4
},
]);
});
test
(
'
boundaries
'
,
()
=>
{
const
matches
=
[
{
preview
:
{
text
:
'
foo
'
,
matches
:
new
Range
(
0
,
0
,
0
,
10
)
},
ranges
:
new
Range
(
0
,
0
,
0
,
10
)
},
{
preview
:
{
text
:
'
bar
'
,
matches
:
new
Range
(
0
,
0
,
0
,
10
)
},
ranges
:
new
Range
(
MOCK_LINE_COUNT
-
1
,
0
,
MOCK_LINE_COUNT
-
1
,
10
)
}];
assert
.
deepEqual
(
addContextToEditorMatches
(
matches
,
mockTextModel
,
getQuery
(
1
,
2
)),
[
matches
[
0
],
<
ITextSearchContext
>
{
text
:
'
2
'
,
lineNumber
:
1
},
<
ITextSearchContext
>
{
text
:
'
3
'
,
lineNumber
:
2
},
<
ITextSearchContext
>
{
text
:
''
+
(
MOCK_LINE_COUNT
-
1
),
lineNumber
:
MOCK_LINE_COUNT
-
2
},
matches
[
1
]
]);
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录