Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9999dac5
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,发现更多精彩内容 >>
提交
9999dac5
编写于
7月 25, 2018
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SearchProvider - split out separate TextSearchProvider #47058
上级
9cc1fc91
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
71 addition
and
26 deletion
+71
-26
extensions/search-rg/src/extension.ts
extensions/search-rg/src/extension.ts
+2
-1
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+30
-9
src/vs/workbench/api/node/extHost.api.impl.ts
src/vs/workbench/api/node/extHost.api.impl.ts
+3
-0
src/vs/workbench/api/node/extHostSearch.ts
src/vs/workbench/api/node/extHostSearch.ts
+13
-2
src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts
...workbench/test/electron-browser/api/extHostSearch.test.ts
+23
-14
未找到文件。
extensions/search-rg/src/extension.ts
浏览文件 @
9999dac5
...
...
@@ -13,12 +13,13 @@ export function activate(): void {
const
outputChannel
=
vscode
.
window
.
createOutputChannel
(
'
search-rg
'
);
const
provider
=
new
RipgrepSearchProvider
(
outputChannel
);
vscode
.
workspace
.
registerSearchProvider
(
'
file
'
,
provider
);
vscode
.
workspace
.
registerTextSearchProvider
(
'
file
'
,
provider
);
}
}
type
SearchEngine
=
RipgrepFileSearchEngine
|
RipgrepTextSearchEngine
;
class
RipgrepSearchProvider
implements
vscode
.
SearchProvider
{
class
RipgrepSearchProvider
implements
vscode
.
SearchProvider
,
vscode
.
TextSearchProvider
{
private
cachedProvider
:
CachedSearchProvider
;
private
inProgress
:
Set
<
SearchEngine
>
=
new
Set
();
...
...
src/vs/vscode.proposed.d.ts
浏览文件 @
9999dac5
...
...
@@ -160,6 +160,25 @@ declare module 'vscode' {
preview
:
TextSearchResultPreview
;
}
// interface FileIndexProvider {
// provideFileIndex(options: FileSearchOptions, token: CancellationToken): Thenable<Uri[]>
// }
// interface FileSearchProvider {
// provideFileSearchResults(query: FileSear, options, token): Thenable<Uri[]>
// }
interface
TextSearchProvider
{
/**
* Provide results that match the given text pattern.
* @param query The parameters for this query.
* @param options A set of options to consider while searching.
* @param progress A progress callback that must be invoked for all results.
* @param token A cancellation token.
*/
provideTextSearchResults
?(
query
:
TextSearchQuery
,
options
:
TextSearchOptions
,
progress
:
Progress
<
TextSearchResult
>
,
token
:
CancellationToken
):
Thenable
<
void
>
;
}
/**
* A SearchProvider provides search results for files or text in files. It can be invoked by quickopen, the search viewlet, and other extensions.
*/
...
...
@@ -178,15 +197,6 @@ declare module 'vscode' {
* @param cacheKey The same key that was passed as `query.cacheKey`.
*/
clearCache
?(
cacheKey
:
string
):
void
;
/**
* Provide results that match the given text pattern.
* @param query The parameters for this query.
* @param options A set of options to consider while searching.
* @param progress A progress callback that must be invoked for all results.
* @param token A cancellation token.
*/
provideTextSearchResults
?(
query
:
TextSearchQuery
,
options
:
TextSearchOptions
,
progress
:
Progress
<
TextSearchResult
>
,
token
:
CancellationToken
):
Thenable
<
void
>
;
}
/**
...
...
@@ -243,6 +253,17 @@ declare module 'vscode' {
*/
export
function
registerSearchProvider
(
scheme
:
string
,
provider
:
SearchProvider
):
Disposable
;
/**
* Register a text search provider.
*
* Only one provider can be registered per scheme.
*
* @param scheme The provider will be invoked for workspace folders that have this file scheme.
* @param provider The provider.
* @return A [disposable](#Disposable) that unregisters this provider when being disposed.
*/
export
function
registerTextSearchProvider
(
scheme
:
string
,
provider
:
TextSearchProvider
):
Disposable
;
/**
* Search text in files across all [workspace folders](#workspace.workspaceFolders) in the workspace.
...
...
src/vs/workbench/api/node/extHost.api.impl.ts
浏览文件 @
9999dac5
...
...
@@ -585,6 +585,9 @@ export function createApiFactory(
registerSearchProvider
:
proposedApiFunction
(
extension
,
(
scheme
,
provider
)
=>
{
return
extHostSearch
.
registerSearchProvider
(
scheme
,
provider
);
}),
registerTextSearchProvider
:
proposedApiFunction
(
extension
,
(
scheme
,
provider
)
=>
{
return
extHostSearch
.
registerTextSearchProvider
(
scheme
,
provider
);
}),
registerDocumentCommentProvider
:
proposedApiFunction
(
extension
,
(
provider
:
vscode
.
DocumentCommentProvider
)
=>
{
return
exthostCommentProviders
.
registerDocumentCommentProvider
(
provider
);
}),
...
...
src/vs/workbench/api/node/extHostSearch.ts
浏览文件 @
9999dac5
...
...
@@ -25,6 +25,7 @@ export class ExtHostSearch implements ExtHostSearchShape {
private
readonly
_proxy
:
MainThreadSearchShape
;
private
readonly
_searchProvider
=
new
Map
<
number
,
vscode
.
SearchProvider
>
();
private
readonly
_textSearchProvider
=
new
Map
<
number
,
vscode
.
TextSearchProvider
>
();
private
_handlePool
:
number
=
0
;
private
_fileSearchManager
:
FileSearchManager
;
...
...
@@ -51,6 +52,16 @@ export class ExtHostSearch implements ExtHostSearchShape {
});
}
registerTextSearchProvider
(
scheme
:
string
,
provider
:
vscode
.
TextSearchProvider
)
{
const
handle
=
this
.
_handlePool
++
;
this
.
_textSearchProvider
.
set
(
handle
,
provider
);
this
.
_proxy
.
$registerSearchProvider
(
handle
,
this
.
_transformScheme
(
scheme
));
return
toDisposable
(()
=>
{
this
.
_searchProvider
.
delete
(
handle
);
this
.
_proxy
.
$unregisterProvider
(
handle
);
});
}
$provideFileSearchResults
(
handle
:
number
,
session
:
number
,
rawQuery
:
IRawSearchQuery
):
TPromise
<
ISearchCompleteStats
>
{
const
provider
=
this
.
_searchProvider
.
get
(
handle
);
if
(
!
provider
.
provideFileSearchResults
)
{
...
...
@@ -74,7 +85,7 @@ export class ExtHostSearch implements ExtHostSearchShape {
}
$provideTextSearchResults
(
handle
:
number
,
session
:
number
,
pattern
:
IPatternInfo
,
rawQuery
:
IRawSearchQuery
):
TPromise
<
ISearchCompleteStats
>
{
const
provider
=
this
.
_
s
earchProvider
.
get
(
handle
);
const
provider
=
this
.
_
textS
earchProvider
.
get
(
handle
);
if
(
!
provider
.
provideTextSearchResults
)
{
return
TPromise
.
as
(
undefined
);
}
...
...
@@ -363,7 +374,7 @@ class TextSearchEngine {
private
resultCount
=
0
;
private
isCanceled
:
boolean
;
constructor
(
private
pattern
:
IPatternInfo
,
private
config
:
ISearchQuery
,
private
provider
:
vscode
.
SearchProvider
,
private
_extfs
:
typeof
extfs
)
{
constructor
(
private
pattern
:
IPatternInfo
,
private
config
:
ISearchQuery
,
private
provider
:
vscode
.
Text
SearchProvider
,
private
_extfs
:
typeof
extfs
)
{
}
public
cancel
():
void
{
...
...
src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts
浏览文件 @
9999dac5
...
...
@@ -32,6 +32,10 @@ class MockMainThreadSearch implements MainThreadSearchShape {
this
.
lastHandle
=
handle
;
}
$registerTextSearchProvider
(
handle
:
number
,
scheme
:
string
):
void
{
this
.
lastHandle
=
handle
;
}
$unregisterProvider
(
handle
:
number
):
void
{
}
...
...
@@ -53,6 +57,11 @@ class MockMainThreadSearch implements MainThreadSearchShape {
let
mockExtfs
:
Partial
<
typeof
extfs
>
;
suite
(
'
ExtHostSearch
'
,
()
=>
{
async
function
registerTestTextSearchProvider
(
provider
:
vscode
.
TextSearchProvider
,
scheme
=
'
file
'
):
Promise
<
void
>
{
disposables
.
push
(
extHostSearch
.
registerTextSearchProvider
(
scheme
,
provider
));
await
rpcProtocol
.
sync
();
}
async
function
registerTestSearchProvider
(
provider
:
vscode
.
SearchProvider
,
scheme
=
'
file
'
):
Promise
<
void
>
{
disposables
.
push
(
extHostSearch
.
registerSearchProvider
(
scheme
,
provider
));
await
rpcProtocol
.
sync
();
...
...
@@ -734,7 +743,7 @@ suite('ExtHostSearch', () => {
}
test
(
'
no results
'
,
async
()
=>
{
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
return
TPromise
.
wrap
(
null
);
}
...
...
@@ -751,7 +760,7 @@ suite('ExtHostSearch', () => {
makeTextResult
(
rootFolderA
,
'
file2.ts
'
)
];
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
providedResults
.
forEach
(
r
=>
progress
.
report
(
r
));
return
TPromise
.
wrap
(
null
);
...
...
@@ -764,7 +773,7 @@ suite('ExtHostSearch', () => {
});
test
(
'
all provider calls get global include/excludes
'
,
async
()
=>
{
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
assert
.
equal
(
options
.
includes
.
length
,
1
);
assert
.
equal
(
options
.
excludes
.
length
,
1
);
...
...
@@ -793,7 +802,7 @@ suite('ExtHostSearch', () => {
});
test
(
'
global/local include/excludes combined
'
,
async
()
=>
{
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
if
(
options
.
folder
.
toString
()
===
rootFolderA
.
toString
())
{
assert
.
deepEqual
(
options
.
includes
.
sort
(),
[
'
*.ts
'
,
'
foo
'
]);
...
...
@@ -834,7 +843,7 @@ suite('ExtHostSearch', () => {
});
test
(
'
include/excludes resolved correctly
'
,
async
()
=>
{
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
assert
.
deepEqual
(
options
.
includes
.
sort
(),
[
'
*.jsx
'
,
'
*.ts
'
]);
assert
.
deepEqual
(
options
.
excludes
.
sort
(),
[]);
...
...
@@ -871,7 +880,7 @@ suite('ExtHostSearch', () => {
});
test
(
'
provider fail
'
,
async
()
=>
{
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
throw
new
Error
(
'
Provider fail
'
);
}
...
...
@@ -902,7 +911,7 @@ suite('ExtHostSearch', () => {
makeTextResult
(
rootFolderA
,
'
file1.ts
'
)
];
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
providedResults
.
forEach
(
r
=>
progress
.
report
(
r
));
return
TPromise
.
wrap
(
null
);
...
...
@@ -946,7 +955,7 @@ suite('ExtHostSearch', () => {
}
};
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
let
reportedResults
;
if
(
options
.
folder
.
fsPath
===
rootFolderA
.
fsPath
)
{
...
...
@@ -1010,7 +1019,7 @@ suite('ExtHostSearch', () => {
makeTextResult
(
rootFolderA
,
'
file1.ts
'
)
];
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
providedResults
.
forEach
(
r
=>
progress
.
report
(
r
));
return
TPromise
.
wrap
(
null
);
...
...
@@ -1040,7 +1049,7 @@ suite('ExtHostSearch', () => {
];
let
wasCanceled
=
false
;
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
token
.
onCancellationRequested
(()
=>
wasCanceled
=
true
);
providedResults
.
forEach
(
r
=>
progress
.
report
(
r
));
...
...
@@ -1072,7 +1081,7 @@ suite('ExtHostSearch', () => {
];
let
wasCanceled
=
false
;
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
token
.
onCancellationRequested
(()
=>
wasCanceled
=
true
);
providedResults
.
forEach
(
r
=>
progress
.
report
(
r
));
...
...
@@ -1103,7 +1112,7 @@ suite('ExtHostSearch', () => {
];
let
wasCanceled
=
false
;
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
token
.
onCancellationRequested
(()
=>
wasCanceled
=
true
);
providedResults
.
forEach
(
r
=>
progress
.
report
(
r
));
...
...
@@ -1129,7 +1138,7 @@ suite('ExtHostSearch', () => {
test
(
'
multiroot max results
'
,
async
()
=>
{
let
cancels
=
0
;
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
token
.
onCancellationRequested
(()
=>
cancels
++
);
return
new
TPromise
(
r
=>
process
.
nextTick
(
r
))
...
...
@@ -1166,7 +1175,7 @@ suite('ExtHostSearch', () => {
makeTextResult
(
fancySchemeFolderA
,
'
file3.ts
'
)
];
await
registerTestSearchProvider
({
await
registerTest
Text
SearchProvider
({
provideTextSearchResults
(
query
:
vscode
.
TextSearchQuery
,
options
:
vscode
.
TextSearchOptions
,
progress
:
vscode
.
Progress
<
vscode
.
TextSearchResult
>
,
token
:
vscode
.
CancellationToken
):
Thenable
<
void
>
{
providedResults
.
forEach
(
r
=>
progress
.
report
(
r
));
return
TPromise
.
wrap
(
null
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录