Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9bea4fae
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,发现更多精彩内容 >>
提交
9bea4fae
编写于
11月 07, 2018
作者:
R
Rob Lourens
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove TPromise from search land #53526
上级
9669edc5
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
155 addition
and
138 deletion
+155
-138
src/vs/base/test/common/utils.ts
src/vs/base/test/common/utils.ts
+33
-0
src/vs/workbench/parts/search/browser/replaceService.ts
src/vs/workbench/parts/search/browser/replaceService.ts
+10
-11
src/vs/workbench/parts/search/browser/searchActions.ts
src/vs/workbench/parts/search/browser/searchActions.ts
+25
-26
src/vs/workbench/parts/search/browser/searchResultsView.ts
src/vs/workbench/parts/search/browser/searchResultsView.ts
+5
-6
src/vs/workbench/parts/search/browser/searchView.ts
src/vs/workbench/parts/search/browser/searchView.ts
+12
-13
src/vs/workbench/parts/search/browser/searchWidget.ts
src/vs/workbench/parts/search/browser/searchWidget.ts
+4
-5
src/vs/workbench/parts/search/common/replace.ts
src/vs/workbench/parts/search/common/replace.ts
+4
-5
src/vs/workbench/parts/search/common/searchModel.ts
src/vs/workbench/parts/search/common/searchModel.ts
+6
-7
src/vs/workbench/parts/search/electron-browser/search.contribution.ts
...ench/parts/search/electron-browser/search.contribution.ts
+2
-3
src/vs/workbench/parts/search/test/common/searchModel.test.ts
...vs/workbench/parts/search/test/common/searchModel.test.ts
+13
-14
src/vs/workbench/services/search/node/fileSearchManager.ts
src/vs/workbench/services/search/node/fileSearchManager.ts
+9
-10
src/vs/workbench/services/search/node/legacy/worker/searchWorker.ts
...kbench/services/search/node/legacy/worker/searchWorker.ts
+15
-16
src/vs/workbench/services/search/node/legacy/worker/searchWorkerIpc.ts
...nch/services/search/node/legacy/worker/searchWorkerIpc.ts
+11
-12
src/vs/workbench/services/search/node/textSearchManager.ts
src/vs/workbench/services/search/node/textSearchManager.ts
+2
-5
src/vs/workbench/services/search/test/node/textSearch.integrationTest.ts
...h/services/search/test/node/textSearch.integrationTest.ts
+2
-3
src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts
...workbench/test/electron-browser/api/extHostSearch.test.ts
+2
-2
未找到文件。
src/vs/base/test/common/utils.ts
浏览文件 @
9bea4fae
...
...
@@ -35,6 +35,39 @@ export class DeferredTPromise<T> extends TPromise<T> {
}
}
export
class
DeferredPromise
<
T
>
{
private
completeCallback
:
TValueCallback
<
T
>
;
private
errorCallback
:
(
err
:
any
)
=>
void
;
public
p
:
Promise
<
any
>
;
constructor
()
{
this
.
p
=
new
Promise
<
any
>
((
c
,
e
)
=>
{
this
.
completeCallback
=
c
;
this
.
errorCallback
=
e
;
});
}
public
complete
(
value
:
T
)
{
process
.
nextTick
(()
=>
{
this
.
completeCallback
(
value
);
});
}
public
error
(
err
:
any
)
{
process
.
nextTick
(()
=>
{
this
.
errorCallback
(
err
);
});
}
public
cancel
()
{
process
.
nextTick
(()
=>
{
this
.
errorCallback
(
canceled
());
});
}
}
export
function
toResource
(
this
:
any
,
path
:
string
)
{
return
URI
.
file
(
paths
.
join
(
'
C:
\\
'
,
Buffer
.
from
(
this
.
test
.
fullTitle
()).
toString
(
'
base64
'
),
path
));
}
...
...
src/vs/workbench/parts/search/browser/replaceService.ts
浏览文件 @
9bea4fae
...
...
@@ -5,7 +5,6 @@
import
*
as
nls
from
'
vs/nls
'
;
import
*
as
errors
from
'
vs/base/common/errors
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
*
as
network
from
'
vs/base/common/network
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
...
...
@@ -47,7 +46,7 @@ export class ReplacePreviewContentProvider implements ITextModelContentProvider,
this
.
textModelResolverService
.
registerTextModelContentProvider
(
network
.
Schemas
.
internal
,
this
);
}
public
provideTextContent
(
uri
:
URI
):
T
Promis
e
<
ITextModel
>
{
public
provideTextContent
(
uri
:
URI
):
T
henabl
e
<
ITextModel
>
{
if
(
uri
.
fragment
===
REPLACE_PREVIEW
)
{
return
this
.
instantiationService
.
createInstance
(
ReplacePreviewModel
).
resolve
(
uri
);
}
...
...
@@ -66,7 +65,7 @@ class ReplacePreviewModel extends Disposable {
super
();
}
resolve
(
replacePreviewUri
:
URI
):
T
Promis
e
<
ITextModel
>
{
resolve
(
replacePreviewUri
:
URI
):
T
henabl
e
<
ITextModel
>
{
const
fileResource
=
toFileResource
(
replacePreviewUri
);
const
fileMatch
=
<
FileMatch
>
this
.
searchWorkbenchService
.
searchModel
.
searchResult
.
matches
().
filter
(
match
=>
match
.
resource
().
toString
()
===
fileResource
.
toString
())[
0
];
return
this
.
textModelResolverService
.
createModelReference
(
fileResource
).
then
(
ref
=>
{
...
...
@@ -101,17 +100,17 @@ export class ReplaceService implements IReplaceService {
@
IBulkEditService
private
bulkEditorService
:
IBulkEditService
)
{
}
public
replace
(
match
:
Match
):
T
Promise
<
any
>
;
public
replace
(
files
:
FileMatch
[],
progress
?:
IProgressRunner
):
T
Promise
<
any
>
;
public
replace
(
match
:
FileMatchOrMatch
,
progress
?:
IProgressRunner
,
resource
?:
URI
):
T
Promise
<
any
>
;
public
replace
(
arg
:
any
,
progress
:
IProgressRunner
|
null
=
null
,
resource
:
URI
|
null
=
null
):
T
Promise
<
any
>
{
public
replace
(
match
:
Match
):
Promise
<
any
>
;
public
replace
(
files
:
FileMatch
[],
progress
?:
IProgressRunner
):
Promise
<
any
>
;
public
replace
(
match
:
FileMatchOrMatch
,
progress
?:
IProgressRunner
,
resource
?:
URI
):
Promise
<
any
>
;
public
replace
(
arg
:
any
,
progress
:
IProgressRunner
|
null
=
null
,
resource
:
URI
|
null
=
null
):
Promise
<
any
>
{
const
edits
:
ResourceTextEdit
[]
=
this
.
createEdits
(
arg
,
resource
);
return
this
.
bulkEditorService
.
apply
({
edits
},
{
progress
}).
then
(()
=>
this
.
textFileService
.
saveAll
(
edits
.
map
(
e
=>
e
.
resource
)));
}
public
openReplacePreview
(
element
:
FileMatchOrMatch
,
preserveFocus
?:
boolean
,
sideBySide
?:
boolean
,
pinned
?:
boolean
):
T
Promis
e
<
any
>
{
public
openReplacePreview
(
element
:
FileMatchOrMatch
,
preserveFocus
?:
boolean
,
sideBySide
?:
boolean
,
pinned
?:
boolean
):
T
henabl
e
<
any
>
{
const
fileMatch
=
element
instanceof
Match
?
element
.
parent
()
:
element
;
return
this
.
editorService
.
openEditor
({
...
...
@@ -139,13 +138,13 @@ export class ReplaceService implements IReplaceService {
},
errors
.
onUnexpectedError
);
}
public
updateReplacePreview
(
fileMatch
:
FileMatch
,
override
:
boolean
=
false
):
T
Promise
<
void
>
{
public
updateReplacePreview
(
fileMatch
:
FileMatch
,
override
:
boolean
=
false
):
Promise
<
void
>
{
const
replacePreviewUri
=
toReplaceResource
(
fileMatch
.
resource
());
return
TPromise
.
join
([
this
.
textModelResolverService
.
createModelReference
(
fileMatch
.
resource
()),
this
.
textModelResolverService
.
createModelReference
(
replacePreviewUri
)])
return
Promise
.
all
([
this
.
textModelResolverService
.
createModelReference
(
fileMatch
.
resource
()),
this
.
textModelResolverService
.
createModelReference
(
replacePreviewUri
)])
.
then
(([
sourceModelRef
,
replaceModelRef
])
=>
{
const
sourceModel
=
sourceModelRef
.
object
.
textEditorModel
;
const
replaceModel
=
replaceModelRef
.
object
.
textEditorModel
;
let
returnValue
=
TPromise
.
wrap
(
null
);
let
returnValue
=
Promise
.
resolve
(
null
);
// If model is disposed do not update
if
(
sourceModel
&&
replaceModel
)
{
if
(
override
)
{
...
...
src/vs/workbench/parts/search/browser/searchActions.ts
浏览文件 @
9bea4fae
...
...
@@ -11,7 +11,6 @@ import { normalizeDriveLetter } from 'vs/base/common/labels';
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
isWindows
,
OS
}
from
'
vs/base/common/platform
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ITree
}
from
'
vs/base/parts/tree/browser/tree
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
IClipboardService
}
from
'
vs/platform/clipboard/common/clipboardService
'
;
...
...
@@ -45,7 +44,7 @@ export function appendKeyBindingLabel(label: string, keyBinding: number | Resolv
}
}
export
function
openSearchView
(
viewletService
:
IViewletService
,
panelService
:
IPanelService
,
focus
?:
boolean
):
T
Promis
e
<
SearchView
>
{
export
function
openSearchView
(
viewletService
:
IViewletService
,
panelService
:
IPanelService
,
focus
?:
boolean
):
T
henabl
e
<
SearchView
>
{
if
(
viewletService
.
getViewlets
().
filter
(
v
=>
v
.
id
===
VIEW_ID
).
length
)
{
return
viewletService
.
openViewlet
(
VIEW_ID
,
focus
).
then
(
viewlet
=>
<
SearchView
>
viewlet
);
}
...
...
@@ -97,10 +96,10 @@ export class FocusNextInputAction extends Action {
super
(
id
,
label
);
}
public
run
():
T
Promis
e
<
any
>
{
public
run
():
T
henabl
e
<
any
>
{
const
searchView
=
getSearchView
(
this
.
viewletService
,
this
.
panelService
);
searchView
.
focusNextInputBox
();
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
}
...
...
@@ -115,10 +114,10 @@ export class FocusPreviousInputAction extends Action {
super
(
id
,
label
);
}
public
run
():
T
Promis
e
<
any
>
{
public
run
():
T
henabl
e
<
any
>
{
const
searchView
=
getSearchView
(
this
.
viewletService
,
this
.
panelService
);
searchView
.
focusPreviousInputBox
();
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
}
...
...
@@ -130,7 +129,7 @@ export abstract class FindOrReplaceInFilesAction extends Action {
super
(
id
,
label
);
}
public
run
():
T
Promis
e
<
any
>
{
public
run
():
T
henabl
e
<
any
>
{
return
openSearchView
(
this
.
viewletService
,
this
.
panelService
,
false
).
then
(
openedView
=>
{
const
searchAndReplaceWidget
=
openedView
.
searchAndReplaceWidget
;
searchAndReplaceWidget
.
toggleReplace
(
this
.
expandSearchReplaceWidget
);
...
...
@@ -165,7 +164,7 @@ export class OpenSearchViewletAction extends FindOrReplaceInFilesAction {
super
(
id
,
label
,
viewletService
,
panelService
,
/*expandSearchReplaceWidget=*/
false
);
}
public
run
():
T
Promis
e
<
any
>
{
public
run
():
T
henabl
e
<
any
>
{
// Pass focus to viewlet if not open or focused
if
(
this
.
otherViewletShowing
()
||
!
isSearchViewFocused
(
this
.
viewletService
,
this
.
panelService
))
{
...
...
@@ -175,7 +174,7 @@ export class OpenSearchViewletAction extends FindOrReplaceInFilesAction {
// Otherwise pass focus to editor group
this
.
editorGroupService
.
activeGroup
.
focus
();
return
TPromise
.
as
(
true
);
return
Promise
.
resolve
(
true
);
}
private
otherViewletShowing
():
boolean
{
...
...
@@ -205,11 +204,11 @@ export class CloseReplaceAction extends Action {
super
(
id
,
label
);
}
public
run
():
T
Promis
e
<
any
>
{
public
run
():
T
henabl
e
<
any
>
{
const
searchView
=
getSearchView
(
this
.
viewletService
,
this
.
panelService
);
searchView
.
searchAndReplaceWidget
.
toggleReplace
(
false
);
searchView
.
searchAndReplaceWidget
.
focus
();
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
}
...
...
@@ -231,12 +230,12 @@ export class RefreshAction extends Action {
this
.
enabled
=
searchView
&&
searchView
.
isSearchSubmitted
();
}
public
run
():
T
Promis
e
<
void
>
{
public
run
():
T
henabl
e
<
void
>
{
const
searchView
=
getSearchView
(
this
.
viewletService
,
this
.
panelService
);
if
(
searchView
)
{
searchView
.
onQueryChanged
();
}
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
}
...
...
@@ -258,12 +257,12 @@ export class CollapseDeepestExpandedLevelAction extends Action {
this
.
enabled
=
searchView
&&
searchView
.
hasSearchResults
();
}
public
run
():
T
Promis
e
<
void
>
{
public
run
():
T
henabl
e
<
void
>
{
const
searchView
=
getSearchView
(
this
.
viewletService
,
this
.
panelService
);
if
(
searchView
)
{
const
viewer
=
searchView
.
getControl
();
if
(
viewer
.
getHighlight
())
{
return
TPromise
.
as
(
null
);
// Global action disabled if user is in edit mode from another action
return
Promise
.
resolve
(
null
);
// Global action disabled if user is in edit mode from another action
}
/**
...
...
@@ -299,7 +298,7 @@ export class CollapseDeepestExpandedLevelAction extends Action {
viewer
.
domFocus
();
viewer
.
focusFirst
();
}
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
}
...
...
@@ -321,12 +320,12 @@ export class ClearSearchResultsAction extends Action {
this
.
enabled
=
searchView
&&
searchView
.
isSearchSubmitted
();
}
public
run
():
T
Promis
e
<
void
>
{
public
run
():
T
henabl
e
<
void
>
{
const
searchView
=
getSearchView
(
this
.
viewletService
,
this
.
panelService
);
if
(
searchView
)
{
searchView
.
clearSearchResults
();
}
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
}
...
...
@@ -348,13 +347,13 @@ export class CancelSearchAction extends Action {
this
.
enabled
=
searchView
&&
searchView
.
isSearching
();
}
public
run
():
T
Promis
e
<
void
>
{
public
run
():
T
henabl
e
<
void
>
{
const
searchView
=
getSearchView
(
this
.
viewletService
,
this
.
panelService
);
if
(
searchView
)
{
searchView
.
cancelSearch
();
}
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
}
...
...
@@ -369,7 +368,7 @@ export class FocusNextSearchResultAction extends Action {
super
(
id
,
label
);
}
public
run
():
T
Promis
e
<
any
>
{
public
run
():
T
henabl
e
<
any
>
{
return
openSearchView
(
this
.
viewletService
,
this
.
panelService
).
then
(
searchView
=>
{
searchView
.
selectNextMatch
();
});
...
...
@@ -387,7 +386,7 @@ export class FocusPreviousSearchResultAction extends Action {
super
(
id
,
label
);
}
public
run
():
T
Promis
e
<
any
>
{
public
run
():
T
henabl
e
<
any
>
{
return
openSearchView
(
this
.
viewletService
,
this
.
panelService
).
then
(
searchView
=>
{
searchView
.
selectPreviousMatch
();
});
...
...
@@ -470,7 +469,7 @@ export class RemoveAction extends AbstractSearchAndReplaceAction {
super
(
'
remove
'
,
RemoveAction
.
LABEL
,
'
action-remove
'
);
}
public
run
():
T
Promis
e
<
any
>
{
public
run
():
T
henabl
e
<
any
>
{
const
currentFocusElement
=
this
.
viewer
.
getFocus
();
const
nextFocusElement
=
!
currentFocusElement
||
currentFocusElement
instanceof
SearchResult
||
elementIsEqualOrParent
(
currentFocusElement
,
this
.
element
)
?
this
.
getElementToFocusAfterRemoved
(
this
.
viewer
,
this
.
element
)
:
...
...
@@ -521,7 +520,7 @@ export class ReplaceAllAction extends AbstractSearchAndReplaceAction {
super
(
Constants
.
ReplaceAllInFileActionId
,
appendKeyBindingLabel
(
ReplaceAllAction
.
LABEL
,
keyBindingService
.
lookupKeybinding
(
Constants
.
ReplaceAllInFileActionId
),
keyBindingService
),
'
action-replace-all
'
);
}
public
run
():
T
Promis
e
<
any
>
{
public
run
():
T
henabl
e
<
any
>
{
let
nextFocusElement
=
this
.
getElementToFocusAfterRemoved
(
this
.
viewer
,
this
.
fileMatch
);
return
this
.
fileMatch
.
parent
().
replace
(
this
.
fileMatch
).
then
(()
=>
{
if
(
nextFocusElement
)
{
...
...
@@ -543,7 +542,7 @@ export class ReplaceAllInFolderAction extends AbstractSearchAndReplaceAction {
super
(
Constants
.
ReplaceAllInFolderActionId
,
appendKeyBindingLabel
(
ReplaceAllInFolderAction
.
LABEL
,
keyBindingService
.
lookupKeybinding
(
Constants
.
ReplaceAllInFolderActionId
),
keyBindingService
),
'
action-replace-all
'
);
}
public
run
():
T
Promis
e
<
any
>
{
public
run
():
T
henabl
e
<
any
>
{
let
nextFocusElement
=
this
.
getElementToFocusAfterRemoved
(
this
.
viewer
,
this
.
folderMatch
);
return
this
.
folderMatch
.
replaceAll
()
.
then
(()
=>
{
...
...
@@ -567,7 +566,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
super
(
Constants
.
ReplaceActionId
,
appendKeyBindingLabel
(
ReplaceAction
.
LABEL
,
keyBindingService
.
lookupKeybinding
(
Constants
.
ReplaceActionId
),
keyBindingService
),
'
action-replace
'
);
}
public
run
():
T
Promis
e
<
any
>
{
public
run
():
T
henabl
e
<
any
>
{
this
.
enabled
=
false
;
return
this
.
element
.
parent
().
replace
(
this
.
element
).
then
(()
=>
{
...
...
src/vs/workbench/parts/search/browser/searchResultsView.ts
浏览文件 @
9bea4fae
...
...
@@ -10,7 +10,6 @@ import { IAction } from 'vs/base/common/actions';
import
{
Disposable
,
dispose
,
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
*
as
resources
from
'
vs/base/common/resources
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ContextMenuEvent
,
IAccessibilityProvider
,
IDataSource
,
IFilter
,
IRenderer
,
ISorter
,
ITree
}
from
'
vs/base/parts/tree/browser/tree
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
fillInContextMenuActions
}
from
'
vs/platform/actions/browser/menuItemActionItem
'
;
...
...
@@ -80,15 +79,15 @@ export class SearchDataSource implements IDataSource {
return
[];
}
public
getChildren
(
tree
:
ITree
,
element
:
any
):
T
Promis
e
<
any
[]
>
{
return
TPromise
.
as
(
this
.
_getChildren
(
element
));
public
getChildren
(
tree
:
ITree
,
element
:
any
):
T
henabl
e
<
any
[]
>
{
return
Promise
.
resolve
(
this
.
_getChildren
(
element
));
}
public
hasChildren
(
tree
:
ITree
,
element
:
any
):
boolean
{
return
element
instanceof
FileMatch
||
element
instanceof
FolderMatch
||
element
instanceof
SearchResult
;
}
public
getParent
(
tree
:
ITree
,
element
:
any
):
T
Promis
e
<
any
>
{
public
getParent
(
tree
:
ITree
,
element
:
any
):
T
henabl
e
<
any
>
{
let
value
:
any
=
null
;
if
(
element
instanceof
Match
)
{
...
...
@@ -99,7 +98,7 @@ export class SearchDataSource implements IDataSource {
value
=
element
.
parent
();
}
return
TPromise
.
as
(
value
);
return
Promise
.
resolve
(
value
);
}
public
shouldAutoexpand
(
tree
:
ITree
,
element
:
any
):
boolean
{
...
...
@@ -425,7 +424,7 @@ export class SearchTreeController extends WorkbenchTreeController {
getActions
:
()
=>
{
const
actions
:
IAction
[]
=
[];
fillInContextMenuActions
(
this
.
contextMenu
,
{
shouldForwardArgs
:
true
},
actions
,
this
.
contextMenuService
);
return
actions
;
return
Promise
.
resolve
(
actions
)
;
},
getActionsContext
:
()
=>
element
...
...
src/vs/workbench/parts/search/browser/searchView.ts
浏览文件 @
9bea4fae
...
...
@@ -18,7 +18,6 @@ import * as paths from 'vs/base/common/paths';
import
*
as
env
from
'
vs/base/common/platform
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
ITree
}
from
'
vs/base/parts/tree/browser/tree
'
;
import
'
vs/css!./media/searchview
'
;
import
{
ICodeEditor
,
isCodeEditor
,
isDiffEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
...
...
@@ -368,23 +367,23 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this
.
layout
(
this
.
size
);
}
private
onSearchResultsChanged
(
event
?:
IChangeEvent
):
T
Promis
e
<
any
>
{
private
onSearchResultsChanged
(
event
?:
IChangeEvent
):
T
henabl
e
<
any
>
{
if
(
this
.
isVisible
())
{
return
this
.
refreshAndUpdateCount
(
event
);
}
else
{
this
.
changedWhileHidden
=
true
;
return
TPromise
.
wrap
(
null
);
return
Promise
.
resolve
(
null
);
}
}
private
refreshAndUpdateCount
(
event
?:
IChangeEvent
):
T
Promis
e
<
void
>
{
private
refreshAndUpdateCount
(
event
?:
IChangeEvent
):
T
henabl
e
<
void
>
{
return
this
.
refreshTree
(
event
).
then
(()
=>
{
this
.
searchWidget
.
setReplaceAllActionState
(
!
this
.
viewModel
.
searchResult
.
isEmpty
());
this
.
updateSearchResultCount
();
});
}
private
refreshTree
(
event
?:
IChangeEvent
):
T
Promis
e
<
any
>
{
private
refreshTree
(
event
?:
IChangeEvent
):
T
henabl
e
<
any
>
{
if
(
!
event
||
event
.
added
||
event
.
removed
)
{
return
this
.
tree
.
refresh
(
this
.
viewModel
.
searchResult
);
}
else
{
...
...
@@ -1087,14 +1086,14 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
},
onQueryValidationError
);
}
private
validateQuery
(
query
:
ITextQuery
):
T
Promis
e
<
void
>
{
private
validateQuery
(
query
:
ITextQuery
):
T
henabl
e
<
void
>
{
// Validate folderQueries
const
folderQueriesExistP
=
query
.
folderQueries
.
map
(
fq
=>
{
return
this
.
fileService
.
existsFile
(
fq
.
folder
);
});
return
TPromise
.
join
(
folderQueriesExistP
).
then
(
existResults
=>
{
return
Promise
.
resolve
(
folderQueriesExistP
).
then
(
existResults
=>
{
// If no folders exist, show an error message about the first one
const
existingFolderQueries
=
query
.
folderQueries
.
filter
((
folderQuery
,
i
)
=>
existResults
[
i
]);
if
(
!
query
.
folderQueries
.
length
||
existingFolderQueries
.
length
)
{
...
...
@@ -1102,7 +1101,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
}
else
{
const
nonExistantPath
=
query
.
folderQueries
[
0
].
folder
.
fsPath
;
const
searchPathNotFoundError
=
nls
.
localize
(
'
searchPathNotFoundError
'
,
"
Search path not found: {0}
"
,
nonExistantPath
);
return
TPromise
.
wrapError
(
new
Error
(
searchPathNotFoundError
));
return
Promise
.
reject
(
new
Error
(
searchPathNotFoundError
));
}
return
undefined
;
...
...
@@ -1349,7 +1348,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this
.
openSettings
(
'
.exclude
'
);
}
private
openSettings
(
query
:
string
):
T
Promis
e
<
IEditor
>
{
private
openSettings
(
query
:
string
):
T
henabl
e
<
IEditor
>
{
const
options
:
ISettingsEditorOptions
=
{
query
};
return
this
.
contextService
.
getWorkbenchState
()
!==
WorkbenchState
.
EMPTY
?
this
.
preferencesService
.
openWorkspaceSettings
(
undefined
,
options
)
:
...
...
@@ -1427,10 +1426,10 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this
.
currentSelectedFileMatch
=
null
;
}
private
onFocus
(
lineMatch
:
any
,
preserveFocus
?:
boolean
,
sideBySide
?:
boolean
,
pinned
?:
boolean
):
T
Promis
e
<
any
>
{
private
onFocus
(
lineMatch
:
any
,
preserveFocus
?:
boolean
,
sideBySide
?:
boolean
,
pinned
?:
boolean
):
T
henabl
e
<
any
>
{
if
(
!
(
lineMatch
instanceof
Match
))
{
this
.
viewModel
.
searchResult
.
rangeHighlightDecorations
.
removeHighlightRange
();
return
TPromise
.
as
(
true
);
return
Promise
.
resolve
(
true
);
}
const
useReplacePreview
=
this
.
configurationService
.
getValue
<
ISearchConfiguration
>
().
search
.
useReplacePreview
;
...
...
@@ -1439,7 +1438,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this
.
open
(
lineMatch
,
preserveFocus
,
sideBySide
,
pinned
);
}
public
open
(
element
:
FileMatchOrMatch
,
preserveFocus
?:
boolean
,
sideBySide
?:
boolean
,
pinned
?:
boolean
):
T
Promis
e
<
any
>
{
public
open
(
element
:
FileMatchOrMatch
,
preserveFocus
?:
boolean
,
sideBySide
?:
boolean
,
pinned
?:
boolean
):
T
henabl
e
<
any
>
{
const
selection
=
this
.
getSelectionFrom
(
element
);
const
resource
=
element
instanceof
Match
?
element
.
parent
().
resource
()
:
(
<
FileMatch
>
element
).
resource
();
return
this
.
editorService
.
openEditor
({
...
...
@@ -1463,7 +1462,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
if
(
editor
)
{
return
this
.
editorGroupsService
.
activateGroup
(
editor
.
group
);
}
else
{
return
TPromise
.
wrap
(
null
);
return
Promise
.
resolve
(
null
);
}
},
errors
.
onUnexpectedError
);
}
...
...
src/vs/workbench/parts/search/browser/searchWidget.ts
浏览文件 @
9bea4fae
...
...
@@ -17,7 +17,6 @@ import { Emitter, Event } from 'vs/base/common/event';
import
{
KeyCode
,
KeyMod
}
from
'
vs/base/common/keyCodes
'
;
import
*
as
env
from
'
vs/base/common/platform
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
CONTEXT_FIND_WIDGET_NOT_VISIBLE
}
from
'
vs/editor/contrib/find/findModel
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
IClipboardService
}
from
'
vs/platform/clipboard/common/clipboardService
'
;
...
...
@@ -67,11 +66,11 @@ class ReplaceAllAction extends Action {
this
.
_searchWidget
=
searchWidget
;
}
run
():
T
Promise
<
any
>
{
run
():
Promise
<
any
>
{
if
(
this
.
_searchWidget
)
{
return
this
.
_searchWidget
.
triggerReplaceAll
();
}
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
}
...
...
@@ -349,9 +348,9 @@ export class SearchWidget extends Widget {
this
.
_register
(
this
.
replaceInputFocusTracker
.
onDidBlur
(()
=>
this
.
replaceInputBoxFocused
.
set
(
false
)));
}
triggerReplaceAll
():
T
Promise
<
any
>
{
triggerReplaceAll
():
Promise
<
any
>
{
this
.
_onReplaceAll
.
fire
();
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
private
onToggleReplaceButton
():
void
{
...
...
src/vs/workbench/parts/search/common/replace.ts
浏览文件 @
9bea4fae
...
...
@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
Match
,
FileMatch
,
FileMatchOrMatch
}
from
'
vs/workbench/parts/search/common/searchModel
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IProgressRunner
}
from
'
vs/platform/progress/common/progress
'
;
...
...
@@ -17,22 +16,22 @@ export interface IReplaceService {
/**
* Replaces the given match in the file that match belongs to
*/
replace
(
match
:
Match
):
T
Promis
e
<
any
>
;
replace
(
match
:
Match
):
T
henabl
e
<
any
>
;
/**
* Replace all the matches from the given file matches in the files
* You can also pass the progress runner to update the progress of replacing.
*/
replace
(
files
:
FileMatch
[],
progress
?:
IProgressRunner
):
T
Promis
e
<
any
>
;
replace
(
files
:
FileMatch
[],
progress
?:
IProgressRunner
):
T
henabl
e
<
any
>
;
/**
* Opens the replace preview for given file match or match
*/
openReplacePreview
(
element
:
FileMatchOrMatch
,
preserveFocus
?:
boolean
,
sideBySide
?:
boolean
,
pinned
?:
boolean
):
T
Promis
e
<
any
>
;
openReplacePreview
(
element
:
FileMatchOrMatch
,
preserveFocus
?:
boolean
,
sideBySide
?:
boolean
,
pinned
?:
boolean
):
T
henabl
e
<
any
>
;
/**
* Update the replace preview for the given file.
* If `override` is `true`, then replace preview is constructed from source model
*/
updateReplacePreview
(
file
:
FileMatch
,
override
?:
boolean
):
T
Promis
e
<
void
>
;
updateReplacePreview
(
file
:
FileMatch
,
override
?:
boolean
):
T
henabl
e
<
void
>
;
}
src/vs/workbench/parts/search/common/searchModel.ts
浏览文件 @
9bea4fae
...
...
@@ -13,7 +13,6 @@ import { ResourceMap, TernarySearchTree, values } from 'vs/base/common/map';
import
*
as
objects
from
'
vs/base/common/objects
'
;
import
{
lcut
}
from
'
vs/base/common/strings
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
FindMatch
,
IModelDeltaDecoration
,
ITextModel
,
OverviewRulerLane
,
TrackedRangeStickiness
}
from
'
vs/editor/common/model
'
;
import
{
ModelDecorationOptions
}
from
'
vs/editor/common/model/textModel
'
;
...
...
@@ -293,7 +292,7 @@ export class FileMatch extends Disposable {
this
.
_onChange
.
fire
(
false
);
}
public
replace
(
toReplace
:
Match
):
T
Promis
e
<
void
>
{
public
replace
(
toReplace
:
Match
):
T
henabl
e
<
void
>
{
return
this
.
replaceService
.
replace
(
toReplace
)
.
then
(()
=>
this
.
updatesMatchesForLineAfterReplace
(
toReplace
.
range
().
startLineNumber
,
false
));
}
...
...
@@ -455,13 +454,13 @@ export class FolderMatch extends Disposable {
this
.
doRemove
(
match
);
}
public
replace
(
match
:
FileMatch
):
T
Promis
e
<
any
>
{
public
replace
(
match
:
FileMatch
):
T
henabl
e
<
any
>
{
return
this
.
replaceService
.
replace
([
match
]).
then
(()
=>
{
this
.
doRemove
(
match
,
false
,
true
);
});
}
public
replaceAll
():
T
Promis
e
<
any
>
{
public
replaceAll
():
T
henabl
e
<
any
>
{
const
matches
=
this
.
matches
();
return
this
.
replaceService
.
replace
(
matches
).
then
(()
=>
{
matches
.
forEach
(
match
=>
this
.
doRemove
(
match
,
false
,
true
));
...
...
@@ -641,11 +640,11 @@ export class SearchResult extends Disposable {
}
}
public
replace
(
match
:
FileMatch
):
T
Promis
e
<
any
>
{
public
replace
(
match
:
FileMatch
):
T
henabl
e
<
any
>
{
return
this
.
getFolderMatch
(
match
.
resource
()).
replace
(
match
);
}
public
replaceAll
(
progressRunner
:
IProgressRunner
):
T
Promis
e
<
any
>
{
public
replaceAll
(
progressRunner
:
IProgressRunner
):
T
henabl
e
<
any
>
{
this
.
replacingAll
=
true
;
const
promise
=
this
.
replaceService
.
replace
(
this
.
matches
(),
progressRunner
);
...
...
@@ -797,7 +796,7 @@ export class SearchModel extends Disposable {
return
this
.
_searchResult
;
}
public
search
(
query
:
ITextQuery
,
onProgress
?:
(
result
:
ISearchProgressItem
)
=>
void
):
T
Promis
e
<
ISearchComplete
>
{
public
search
(
query
:
ITextQuery
,
onProgress
?:
(
result
:
ISearchProgressItem
)
=>
void
):
T
henabl
e
<
ISearchComplete
>
{
this
.
cancelSearch
();
this
.
_searchQuery
=
query
;
...
...
src/vs/workbench/parts/search/electron-browser/search.contribution.ts
浏览文件 @
9bea4fae
...
...
@@ -9,7 +9,6 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import
{
ViewletRegistry
,
Extensions
as
ViewletExtensions
,
ViewletDescriptor
}
from
'
vs/workbench/browser/viewlet
'
;
import
{
IConfigurationRegistry
,
Extensions
as
ConfigurationExtensions
,
ConfigurationScope
}
from
'
vs/platform/configuration/common/configurationRegistry
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
Action
}
from
'
vs/base/common/actions
'
;
import
*
as
objects
from
'
vs/base/common/objects
'
;
import
*
as
platform
from
'
vs/base/common/platform
'
;
...
...
@@ -430,7 +429,7 @@ class ShowAllSymbolsAction extends Action {
this
.
enabled
=
!!
this
.
quickOpenService
;
}
public
run
(
context
?:
any
):
T
Promise
<
void
>
{
public
run
(
context
?:
any
):
Promise
<
void
>
{
let
prefix
=
ShowAllSymbolsAction
.
ALL_SYMBOLS_PREFIX
;
let
inputSelection
:
{
start
:
number
;
end
:
number
;
}
=
void
0
;
...
...
@@ -443,7 +442,7 @@ class ShowAllSymbolsAction extends Action {
this
.
quickOpenService
.
show
(
prefix
,
{
inputSelection
});
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
}
...
...
src/vs/workbench/parts/search/test/common/searchModel.test.ts
浏览文件 @
9bea4fae
...
...
@@ -5,20 +5,19 @@
import
*
as
assert
from
'
assert
'
;
import
*
as
sinon
from
'
sinon
'
;
import
{
timeout
}
from
'
vs/base/common/async
'
;
import
{
CancellationToken
,
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
DeferredTPromise
}
from
'
vs/base/test/common/utils
'
;
import
{
DeferredPromise
}
from
'
vs/base/test/common/utils
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
ModelServiceImpl
}
from
'
vs/editor/common/services/modelServiceImpl
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
TestConfigurationService
}
from
'
vs/platform/configuration/test/common/testConfigurationService
'
;
import
{
TestInstantiationService
}
from
'
vs/platform/instantiation/test/common/instantiationServiceMock
'
;
import
{
IFileMatch
,
IFileSearchStats
,
IFolderQuery
,
ISearchComplete
,
ISearchProgressItem
,
ISearchQuery
,
ISearchService
,
ITextSearchMatch
,
TextSearchMatch
,
OneLineRange
}
from
'
vs/platform/search/common/search
'
;
import
{
IFileMatch
,
IFileSearchStats
,
IFolderQuery
,
ISearchComplete
,
ISearchProgressItem
,
ISearchQuery
,
ISearchService
,
ITextSearchMatch
,
OneLineRange
,
TextSearchMatch
}
from
'
vs/platform/search/common/search
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
NullTelemetryService
}
from
'
vs/platform/telemetry/common/telemetryUtils
'
;
import
{
SearchModel
}
from
'
vs/workbench/parts/search/common/searchModel
'
;
import
{
CancellationToken
,
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
const
nullEvent
=
new
class
{
...
...
@@ -71,7 +70,7 @@ suite('SearchModel', () => {
instantiationService
.
stub
(
ITelemetryService
,
NullTelemetryService
);
instantiationService
.
stub
(
IModelService
,
stubModelService
(
instantiationService
));
instantiationService
.
stub
(
ISearchService
,
{});
instantiationService
.
stub
(
ISearchService
,
'
textSearch
'
,
TPromise
.
as
({
results
:
[]
}));
instantiationService
.
stub
(
ISearchService
,
'
textSearch
'
,
Promise
.
resolve
({
results
:
[]
}));
});
teardown
(()
=>
{
...
...
@@ -82,8 +81,8 @@ suite('SearchModel', () => {
function
searchServiceWithResults
(
results
:
IFileMatch
[],
complete
:
ISearchComplete
|
null
=
null
):
ISearchService
{
return
<
ISearchService
>
{
textSearch
(
query
:
ISearchQuery
,
token
?:
CancellationToken
,
onProgress
?:
(
result
:
ISearchProgressItem
)
=>
void
):
T
Promis
e
<
ISearchComplete
>
{
return
new
T
Promise
(
resolve
=>
{
textSearch
(
query
:
ISearchQuery
,
token
?:
CancellationToken
,
onProgress
?:
(
result
:
ISearchProgressItem
)
=>
void
):
T
henabl
e
<
ISearchComplete
>
{
return
new
Promise
(
resolve
=>
{
process
.
nextTick
(()
=>
{
results
.
forEach
(
onProgress
);
resolve
(
complete
);
...
...
@@ -95,8 +94,8 @@ suite('SearchModel', () => {
function
searchServiceWithError
(
error
:
Error
):
ISearchService
{
return
<
ISearchService
>
{
textSearch
(
query
:
ISearchQuery
,
token
?:
CancellationToken
,
onProgress
?:
(
result
:
ISearchProgressItem
)
=>
void
):
T
Promis
e
<
ISearchComplete
>
{
return
new
T
Promise
((
resolve
,
reject
)
=>
{
textSearch
(
query
:
ISearchQuery
,
token
?:
CancellationToken
,
onProgress
?:
(
result
:
ISearchProgressItem
)
=>
void
):
T
henabl
e
<
ISearchComplete
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
reject
(
error
);
});
}
...
...
@@ -105,12 +104,12 @@ suite('SearchModel', () => {
function
canceleableSearchService
(
tokenSource
:
CancellationTokenSource
):
ISearchService
{
return
<
ISearchService
>
{
textSearch
(
query
:
ISearchQuery
,
token
?:
CancellationToken
,
onProgress
?:
(
result
:
ISearchProgressItem
)
=>
void
):
T
Promis
e
<
ISearchComplete
>
{
textSearch
(
query
:
ISearchQuery
,
token
?:
CancellationToken
,
onProgress
?:
(
result
:
ISearchProgressItem
)
=>
void
):
T
henabl
e
<
ISearchComplete
>
{
if
(
token
)
{
token
.
onCancellationRequested
(()
=>
tokenSource
.
cancel
());
}
return
new
T
Promise
(
resolve
=>
{
return
new
Promise
(
resolve
=>
{
process
.
nextTick
(()
=>
{
resolve
(
<
any
>
{});
});
...
...
@@ -236,13 +235,13 @@ suite('SearchModel', () => {
let
target1
=
sinon
.
stub
().
returns
(
nullEvent
);
instantiationService
.
stub
(
ITelemetryService
,
'
publicLog
'
,
target1
);
let
promise
=
new
DeferredT
Promise
<
ISearchComplete
>
();
instantiationService
.
stub
(
ISearchService
,
'
textSearch
'
,
promise
);
let
deferredPromise
=
new
Deferred
Promise
<
ISearchComplete
>
();
instantiationService
.
stub
(
ISearchService
,
'
textSearch
'
,
deferredPromise
.
p
);
let
testObject
=
instantiationService
.
createInstance
(
SearchModel
);
let
result
=
testObject
.
search
({
contentPattern
:
{
pattern
:
'
somestring
'
},
type
:
1
,
folderQueries
});
p
romise
.
cancel
();
deferredP
romise
.
cancel
();
return
timeout
(
1
).
then
(()
=>
{
return
result
.
then
(()
=>
{
},
()
=>
{
...
...
src/vs/workbench/services/search/node/fileSearchManager.ts
浏览文件 @
9bea4fae
...
...
@@ -10,7 +10,6 @@ import * as glob from 'vs/base/common/glob';
import
*
as
resources
from
'
vs/base/common/resources
'
;
import
{
StopWatch
}
from
'
vs/base/common/stopwatch
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IFileMatch
,
IFileSearchProviderStats
,
IFolderQuery
,
ISearchCompleteStats
,
IFileQuery
}
from
'
vs/platform/search/common/search
'
;
import
{
QueryGlobTester
,
resolvePatternsForProvider
}
from
'
vs/workbench/services/search/node/search
'
;
import
*
as
vscode
from
'
vscode
'
;
...
...
@@ -64,10 +63,10 @@ class FileSearchEngine {
this
.
activeCancellationTokens
=
new
Set
();
}
public
search
(
_onResult
:
(
match
:
IInternalFileMatch
)
=>
void
):
T
Promise
<
IInternalSearchComplete
>
{
public
search
(
_onResult
:
(
match
:
IInternalFileMatch
)
=>
void
):
Promise
<
IInternalSearchComplete
>
{
const
folderQueries
=
this
.
config
.
folderQueries
||
[];
return
new
T
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
onResult
=
(
match
:
IInternalFileMatch
)
=>
{
this
.
resultCount
++
;
_onResult
(
match
);
...
...
@@ -94,7 +93,7 @@ class FileSearchEngine {
}
// For each root folder
TPromise
.
join
(
folderQueries
.
map
(
fq
=>
{
Promise
.
all
(
folderQueries
.
map
(
fq
=>
{
return
this
.
searchInFolder
(
fq
,
onResult
);
})).
then
(
stats
=>
{
resolve
({
...
...
@@ -111,9 +110,9 @@ class FileSearchEngine {
});
}
private
searchInFolder
(
fq
:
IFolderQuery
<
URI
>
,
onResult
:
(
match
:
IInternalFileMatch
)
=>
void
):
T
Promise
<
IFileSearchProviderStats
|
null
>
{
private
searchInFolder
(
fq
:
IFolderQuery
<
URI
>
,
onResult
:
(
match
:
IInternalFileMatch
)
=>
void
):
Promise
<
IFileSearchProviderStats
|
null
>
{
let
cancellation
=
new
CancellationTokenSource
();
return
new
T
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
options
=
this
.
getSearchOptionsForFolder
(
fq
);
const
tree
=
this
.
initDirectoryTree
();
...
...
@@ -121,7 +120,7 @@ class FileSearchEngine {
const
noSiblingsClauses
=
!
queryTester
.
hasSiblingExcludeClauses
();
let
providerSW
:
StopWatch
;
new
T
Promise
(
_resolve
=>
process
.
nextTick
(
_resolve
))
new
Promise
(
_resolve
=>
process
.
nextTick
(
_resolve
))
.
then
(()
=>
{
this
.
activeCancellationTokens
.
add
(
cancellation
);
...
...
@@ -287,7 +286,7 @@ export class FileSearchManager {
private
static
readonly
BATCH_SIZE
=
512
;
fileSearch
(
config
:
IFileQuery
,
provider
:
vscode
.
FileSearchProvider
,
onBatch
:
(
matches
:
IFileMatch
[])
=>
void
,
token
:
CancellationToken
):
T
Promise
<
ISearchCompleteStats
>
{
fileSearch
(
config
:
IFileQuery
,
provider
:
vscode
.
FileSearchProvider
,
onBatch
:
(
matches
:
IFileMatch
[])
=>
void
,
token
:
CancellationToken
):
Promise
<
ISearchCompleteStats
>
{
const
engine
=
new
FileSearchEngine
(
config
,
provider
);
let
resultCount
=
0
;
...
...
@@ -323,7 +322,7 @@ export class FileSearchManager {
}
}
private
doSearch
(
engine
:
FileSearchEngine
,
batchSize
:
number
,
onResultBatch
:
(
matches
:
IInternalFileMatch
[])
=>
void
,
token
:
CancellationToken
):
T
Promise
<
IInternalSearchComplete
>
{
private
doSearch
(
engine
:
FileSearchEngine
,
batchSize
:
number
,
onResultBatch
:
(
matches
:
IInternalFileMatch
[])
=>
void
,
token
:
CancellationToken
):
Promise
<
IInternalSearchComplete
>
{
token
.
onCancellationRequested
(()
=>
{
engine
.
cancel
();
});
...
...
@@ -350,7 +349,7 @@ export class FileSearchManager {
onResultBatch
(
batch
);
}
return
TPromise
.
wrapError
(
error
);
return
Promise
.
reject
(
error
);
});
}
}
src/vs/workbench/services/search/node/legacy/worker/searchWorker.ts
浏览文件 @
9bea4fae
...
...
@@ -7,7 +7,6 @@ import * as fs from 'fs';
import
*
as
gracefulFs
from
'
graceful-fs
'
;
import
{
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
bomLength
,
decode
,
detectEncodingFromBuffer
,
encodingExists
,
UTF16be
,
UTF16le
,
UTF8
,
UTF8_with_bom
}
from
'
vs/base/node/encoding
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
import
{
ITextSearchPreviewOptions
,
TextSearchMatch
}
from
'
vs/platform/search/common/search
'
;
...
...
@@ -32,21 +31,21 @@ function onError(error: any): void {
export
class
SearchWorker
implements
ISearchWorker
{
private
currentSearchEngine
:
SearchWorkerEngine
;
initialize
():
T
Promise
<
void
>
{
initialize
():
Promise
<
void
>
{
this
.
currentSearchEngine
=
new
SearchWorkerEngine
();
return
TPromise
.
wrap
<
void
>
(
undefined
);
return
Promise
.
resolve
<
void
>
(
undefined
);
}
cancel
():
T
Promise
<
void
>
{
cancel
():
Promise
<
void
>
{
// Cancel the current search. It will stop searching and close its open files.
if
(
this
.
currentSearchEngine
)
{
this
.
currentSearchEngine
.
cancel
();
}
return
TPromise
.
wrap
<
void
>
(
null
);
return
Promise
.
resolve
<
void
>
(
null
);
}
search
(
args
:
ISearchWorkerSearchArgs
):
T
Promise
<
ISearchWorkerSearchResult
>
{
search
(
args
:
ISearchWorkerSearchArgs
):
Promise
<
ISearchWorkerSearchResult
>
{
if
(
!
this
.
currentSearchEngine
)
{
// Worker timed out during search
this
.
initialize
();
...
...
@@ -66,13 +65,13 @@ const LF = 0x0a;
const
CR
=
0x0d
;
export
class
SearchWorkerEngine
{
private
nextSearch
=
TPromise
.
wrap
(
null
);
private
nextSearch
=
Promise
.
resolve
(
null
);
private
isCanceled
=
false
;
/**
* Searches some number of the given paths concurrently, and starts searches in other paths when those complete.
*/
searchBatch
(
args
:
ISearchWorkerSearchArgs
):
T
Promise
<
ISearchWorkerSearchResult
>
{
searchBatch
(
args
:
ISearchWorkerSearchArgs
):
Promise
<
ISearchWorkerSearchResult
>
{
const
contentPattern
=
strings
.
createRegExp
(
args
.
pattern
.
pattern
,
args
.
pattern
.
isRegExp
,
{
matchCase
:
args
.
pattern
.
isCaseSensitive
,
wholeWord
:
args
.
pattern
.
isWordMatch
,
multiline
:
false
,
global
:
true
});
const
fileEncoding
=
encodingExists
(
args
.
fileEncoding
)
?
args
.
fileEncoding
:
UTF8
;
return
this
.
nextSearch
=
...
...
@@ -80,12 +79,12 @@ export class SearchWorkerEngine {
}
private
_searchBatch
(
args
:
ISearchWorkerSearchArgs
,
contentPattern
:
RegExp
,
fileEncoding
:
string
):
T
Promise
<
ISearchWorkerSearchResult
>
{
private
_searchBatch
(
args
:
ISearchWorkerSearchArgs
,
contentPattern
:
RegExp
,
fileEncoding
:
string
):
Promise
<
ISearchWorkerSearchResult
>
{
if
(
this
.
isCanceled
)
{
return
TPromise
.
wrap
<
ISearchWorkerSearchResult
>
(
null
);
return
Promise
.
resolve
<
ISearchWorkerSearchResult
>
(
null
);
}
return
new
T
Promise
<
ISearchWorkerSearchResult
>
(
batchDone
=>
{
return
new
Promise
<
ISearchWorkerSearchResult
>
(
batchDone
=>
{
const
result
:
ISearchWorkerSearchResult
=
{
matches
:
[],
numMatches
:
0
,
...
...
@@ -93,7 +92,7 @@ export class SearchWorkerEngine {
};
// Search in the given path, and when it's finished, search in the next path in absolutePaths
const
startSearchInFile
=
(
absolutePath
:
string
):
T
Promise
<
void
>
=>
{
const
startSearchInFile
=
(
absolutePath
:
string
):
Promise
<
void
>
=>
{
return
this
.
searchInFile
(
absolutePath
,
contentPattern
,
fileEncoding
,
args
.
maxResults
&&
(
args
.
maxResults
-
result
.
numMatches
),
args
.
previewOptions
).
then
(
fileResult
=>
{
// Finish early if search is canceled
if
(
this
.
isCanceled
)
{
...
...
@@ -113,7 +112,7 @@ export class SearchWorkerEngine {
},
onError
);
};
TPromise
.
join
(
args
.
absolutePaths
.
map
(
startSearchInFile
)).
then
(()
=>
{
Promise
.
all
(
args
.
absolutePaths
.
map
(
startSearchInFile
)).
then
(()
=>
{
batchDone
(
result
);
});
});
...
...
@@ -123,7 +122,7 @@ export class SearchWorkerEngine {
this
.
isCanceled
=
true
;
}
private
searchInFile
(
absolutePath
:
string
,
contentPattern
:
RegExp
,
fileEncoding
:
string
,
maxResults
?:
number
,
previewOptions
?:
ITextSearchPreviewOptions
):
T
Promise
<
IFileSearchResult
>
{
private
searchInFile
(
absolutePath
:
string
,
contentPattern
:
RegExp
,
fileEncoding
:
string
,
maxResults
?:
number
,
previewOptions
?:
ITextSearchPreviewOptions
):
Promise
<
IFileSearchResult
>
{
let
fileMatch
:
FileMatch
|
null
=
null
;
let
limitReached
=
false
;
let
numMatches
=
0
;
...
...
@@ -154,8 +153,8 @@ export class SearchWorkerEngine {
()
=>
fileMatch
?
{
match
:
fileMatch
,
limitReached
,
numMatches
}
:
null
);
}
private
readlinesAsync
(
filename
:
string
,
perLineCallback
:
(
line
:
string
,
lineNumber
:
number
)
=>
void
,
options
:
ReadLinesOptions
):
T
Promise
<
void
>
{
return
new
T
Promise
<
void
>
((
resolve
,
reject
)
=>
{
private
readlinesAsync
(
filename
:
string
,
perLineCallback
:
(
line
:
string
,
lineNumber
:
number
)
=>
void
,
options
:
ReadLinesOptions
):
Promise
<
void
>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
fs
.
open
(
filename
,
'
r
'
,
null
,
(
error
:
Error
,
fd
:
number
)
=>
{
if
(
error
)
{
return
resolve
(
null
);
...
...
src/vs/workbench/services/search/node/legacy/worker/searchWorkerIpc.ts
浏览文件 @
9bea4fae
...
...
@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IChannel
}
from
'
vs/base/parts/ipc/node/ipc
'
;
import
{
IPatternInfo
,
ITextSearchPreviewOptions
}
from
'
vs/platform/search/common/search
'
;
import
{
SearchWorker
}
from
'
./searchWorker
'
;
...
...
@@ -25,16 +24,16 @@ export interface ISearchWorkerSearchResult {
}
export
interface
ISearchWorker
{
initialize
():
T
Promise
<
void
>
;
search
(
args
:
ISearchWorkerSearchArgs
):
T
Promise
<
ISearchWorkerSearchResult
>
;
cancel
():
T
Promise
<
void
>
;
initialize
():
Promise
<
void
>
;
search
(
args
:
ISearchWorkerSearchArgs
):
Promise
<
ISearchWorkerSearchResult
>
;
cancel
():
Promise
<
void
>
;
}
export
interface
ISearchWorkerChannel
extends
IChannel
{
call
(
command
:
'
initialize
'
):
T
Promise
<
void
>
;
call
(
command
:
'
search
'
,
args
:
ISearchWorkerSearchArgs
):
T
Promise
<
ISearchWorkerSearchResult
>
;
call
(
command
:
'
cancel
'
):
T
Promise
<
void
>
;
call
(
command
:
string
,
arg
?:
any
):
T
Promise
<
any
>
;
call
(
command
:
'
initialize
'
):
Promise
<
void
>
;
call
(
command
:
'
search
'
,
args
:
ISearchWorkerSearchArgs
):
Promise
<
ISearchWorkerSearchResult
>
;
call
(
command
:
'
cancel
'
):
Promise
<
void
>
;
call
(
command
:
string
,
arg
?:
any
):
Promise
<
any
>
;
}
export
class
SearchWorkerChannel
implements
ISearchWorkerChannel
{
...
...
@@ -45,7 +44,7 @@ export class SearchWorkerChannel implements ISearchWorkerChannel {
throw
new
Error
(
'
No events
'
);
}
call
(
command
:
string
,
arg
?:
any
):
T
Promise
<
any
>
{
call
(
command
:
string
,
arg
?:
any
):
Promise
<
any
>
{
switch
(
command
)
{
case
'
initialize
'
:
return
this
.
worker
.
initialize
();
case
'
search
'
:
return
this
.
worker
.
search
(
arg
);
...
...
@@ -58,15 +57,15 @@ export class SearchWorkerChannel implements ISearchWorkerChannel {
export
class
SearchWorkerChannelClient
implements
ISearchWorker
{
constructor
(
private
channel
:
ISearchWorkerChannel
)
{
}
initialize
():
T
Promise
<
void
>
{
initialize
():
Promise
<
void
>
{
return
this
.
channel
.
call
(
'
initialize
'
);
}
search
(
args
:
ISearchWorkerSearchArgs
):
T
Promise
<
ISearchWorkerSearchResult
>
{
search
(
args
:
ISearchWorkerSearchArgs
):
Promise
<
ISearchWorkerSearchResult
>
{
return
this
.
channel
.
call
(
'
search
'
,
args
);
}
cancel
():
T
Promise
<
void
>
{
cancel
():
Promise
<
void
>
{
return
this
.
channel
.
call
(
'
cancel
'
);
}
}
src/vs/workbench/services/search/node/textSearchManager.ts
浏览文件 @
9bea4fae
...
...
@@ -66,12 +66,9 @@ export class TextSearchManager {
type
:
'
textSearchProvider
'
}
});
},
(
err
s
:
Error
[]
)
=>
{
},
(
err
:
Error
)
=>
{
tokenSource
.
dispose
();
const
errMsg
=
errs
.
map
(
err
=>
toErrorMessage
(
err
))
.
filter
(
msg
=>
!!
msg
)[
0
];
const
errMsg
=
toErrorMessage
(
err
);
reject
(
new
Error
(
errMsg
));
});
});
...
...
src/vs/workbench/services/search/test/node/textSearch.integrationTest.ts
浏览文件 @
9bea4fae
...
...
@@ -9,7 +9,6 @@ import { getPathFromAmdModule } from 'vs/base/common/amd';
import
{
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
import
*
as
glob
from
'
vs/base/common/glob
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IFolderQuery
,
ISearchRange
,
ITextQuery
,
ITextSearchMatch
,
QueryType
,
ITextSearchContext
,
deserializeSearchError
,
SearchErrorCode
}
from
'
vs/platform/search/common/search
'
;
import
{
LegacyTextSearchService
}
from
'
vs/workbench/services/search/node/legacy/rawLegacyTextSearchService
'
;
import
{
ISerializedFileMatch
}
from
'
vs/workbench/services/search/node/search
'
;
...
...
@@ -32,7 +31,7 @@ const MULTIROOT_QUERIES: IFolderQuery[] = [
{
folder
:
URI
.
file
(
MORE_FIXTURES
)
}
];
function
doLegacySearchTest
(
config
:
ITextQuery
,
expectedResultCount
:
number
|
Function
):
T
Promise
<
void
>
{
function
doLegacySearchTest
(
config
:
ITextQuery
,
expectedResultCount
:
number
|
Function
):
Promise
<
void
>
{
const
engine
=
new
LegacyTextSearchService
();
let
c
=
0
;
...
...
@@ -49,7 +48,7 @@ function doLegacySearchTest(config: ITextQuery, expectedResultCount: number | Fu
});
}
function
doRipgrepSearchTest
(
query
:
ITextQuery
,
expectedResultCount
:
number
|
Function
):
T
Promise
<
ISerializedFileMatch
[]
>
{
function
doRipgrepSearchTest
(
query
:
ITextQuery
,
expectedResultCount
:
number
|
Function
):
Promise
<
ISerializedFileMatch
[]
>
{
let
engine
=
new
TextSearchEngineAdapter
(
query
);
let
c
=
0
;
...
...
src/vs/workbench/test/electron-browser/api/extHostSearch.test.ts
浏览文件 @
9bea4fae
...
...
@@ -690,8 +690,8 @@ suite('ExtHostSearch', () => {
const
makeComparable
=
(
results
:
vscode
.
TextSearchResult
[])
=>
results
.
sort
((
a
,
b
)
=>
{
const
compareKeyA
=
extensionResultIsMatch
(
a
)
?
a
.
preview
.
text
:
a
.
text
;
const
compareKeyB
=
extensionResultIsMatch
(
b
)
?
b
.
preview
.
text
:
b
.
text
;
const
compareKeyA
=
a
.
uri
.
toString
()
+
'
:
'
+
(
extensionResultIsMatch
(
a
)
?
a
.
preview
.
text
:
a
.
text
)
;
const
compareKeyB
=
b
.
uri
.
toString
()
+
'
:
'
+
(
extensionResultIsMatch
(
b
)
?
b
.
preview
.
text
:
b
.
text
)
;
return
compareKeyB
.
localeCompare
(
compareKeyA
);
})
.
map
(
r
=>
extensionResultIsMatch
(
r
)
?
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录