Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9aebfa2c
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,发现更多精彩内容 >>
提交
9aebfa2c
编写于
11月 08, 2018
作者:
C
Christof Marti
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use ES6 promises
上级
be4e8491
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
101 addition
and
107 deletion
+101
-107
src/vs/base/test/common/utils.ts
src/vs/base/test/common/utils.ts
+12
-32
src/vs/platform/quickinput/common/quickInput.ts
src/vs/platform/quickinput/common/quickInput.ts
+8
-9
src/vs/workbench/browser/parts/quickinput/quickInput.ts
src/vs/workbench/browser/parts/quickinput/quickInput.ts
+15
-16
src/vs/workbench/browser/parts/quickopen/quickOpenController.ts
.../workbench/browser/parts/quickopen/quickOpenController.ts
+12
-11
src/vs/workbench/parts/search/test/browser/openFileHandler.test.ts
...rkbench/parts/search/test/browser/openFileHandler.test.ts
+51
-35
src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts
...ts/welcome/walkThrough/node/walkThroughContentProvider.ts
+3
-4
未找到文件。
src/vs/base/test/common/utils.ts
浏览文件 @
9aebfa2c
...
...
@@ -5,39 +5,13 @@
import
*
as
paths
from
'
vs/base/common/paths
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
,
TValueCallback
}
from
'
vs/base/common/winjs.base
'
;
import
{
canceled
}
from
'
vs/base/common/errors
'
;
export
class
DeferredTPromise
<
T
>
extends
TPromise
<
T
>
{
private
completeCallback
:
TValueCallback
<
T
>
;
private
errorCallback
:
(
err
:
any
)
=>
void
;
constructor
()
{
let
captured
:
any
;
super
((
c
,
e
)
=>
{
captured
=
{
c
,
e
};
});
this
.
completeCallback
=
captured
.
c
;
this
.
errorCallback
=
captured
.
e
;
}
public
complete
(
value
:
T
)
{
this
.
completeCallback
(
value
);
}
public
error
(
err
:
any
)
{
this
.
errorCallback
(
err
);
}
public
cancel
()
{
this
.
errorCallback
(
canceled
());
}
}
export
type
ValueCallback
<
T
=
any
>
=
(
value
:
T
|
Thenable
<
T
>
)
=>
void
;
export
class
DeferredPromise
<
T
>
{
private
completeCallback
:
T
ValueCallback
<
T
>
;
private
completeCallback
:
ValueCallback
<
T
>
;
private
errorCallback
:
(
err
:
any
)
=>
void
;
public
p
:
Promise
<
any
>
;
...
...
@@ -50,14 +24,20 @@ export class DeferredPromise<T> {
}
public
complete
(
value
:
T
)
{
return
new
Promise
(
resolve
=>
{
process
.
nextTick
(()
=>
{
this
.
completeCallback
(
value
);
resolve
();
});
});
}
public
error
(
err
:
any
)
{
return
new
Promise
(
resolve
=>
{
process
.
nextTick
(()
=>
{
this
.
errorCallback
(
err
);
resolve
();
});
});
}
...
...
src/vs/platform/quickinput/common/quickInput.ts
浏览文件 @
9aebfa2c
...
...
@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
ResolvedKeybinding
}
from
'
vs/base/common/keyCodes
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
...
...
@@ -76,7 +75,7 @@ export interface IPickOptions<T extends IQuickPickItem> {
/**
* an optional property for the item to focus initially.
*/
activeItem
?:
T
Promise
<
T
>
|
T
;
activeItem
?:
Promise
<
T
>
|
T
;
onKeyMods
?:
(
keyMods
:
IKeyMods
)
=>
void
;
onDidFocus
?:
(
entry
:
T
)
=>
void
;
...
...
@@ -231,14 +230,14 @@ export interface IQuickInputService {
/**
* Opens the quick input box for selecting items and returns a promise with the user selected item(s) if any.
*/
pick
<
T
extends
IQuickPickItem
>
(
picks
:
T
Promise
<
QuickPickInput
<
T
>
[]
>
|
QuickPickInput
<
T
>
[],
options
?:
IPickOptions
<
T
>
&
{
canPickMany
:
true
},
token
?:
CancellationToken
):
T
Promise
<
T
[]
>
;
pick
<
T
extends
IQuickPickItem
>
(
picks
:
T
Promise
<
QuickPickInput
<
T
>
[]
>
|
QuickPickInput
<
T
>
[],
options
?:
IPickOptions
<
T
>
&
{
canPickMany
:
false
},
token
?:
CancellationToken
):
T
Promise
<
T
>
;
pick
<
T
extends
IQuickPickItem
>
(
picks
:
T
Promise
<
QuickPickInput
<
T
>
[]
>
|
QuickPickInput
<
T
>
[],
options
?:
Omit
<
IPickOptions
<
T
>
,
'
canPickMany
'
>
,
token
?:
CancellationToken
):
T
Promise
<
T
>
;
pick
<
T
extends
IQuickPickItem
>
(
picks
:
T
henable
<
QuickPickInput
<
T
>
[]
>
|
QuickPickInput
<
T
>
[],
options
?:
IPickOptions
<
T
>
&
{
canPickMany
:
true
},
token
?:
CancellationToken
):
Promise
<
T
[]
>
;
pick
<
T
extends
IQuickPickItem
>
(
picks
:
T
henable
<
QuickPickInput
<
T
>
[]
>
|
QuickPickInput
<
T
>
[],
options
?:
IPickOptions
<
T
>
&
{
canPickMany
:
false
},
token
?:
CancellationToken
):
Promise
<
T
>
;
pick
<
T
extends
IQuickPickItem
>
(
picks
:
T
henable
<
QuickPickInput
<
T
>
[]
>
|
QuickPickInput
<
T
>
[],
options
?:
Omit
<
IPickOptions
<
T
>
,
'
canPickMany
'
>
,
token
?:
CancellationToken
):
Promise
<
T
>
;
/**
* Opens the quick input box for text input and returns a promise with the user typed value if any.
*/
input
(
options
?:
IInputOptions
,
token
?:
CancellationToken
):
T
Promise
<
string
>
;
input
(
options
?:
IInputOptions
,
token
?:
CancellationToken
):
Promise
<
string
>
;
backButton
:
IQuickInputButton
;
...
...
@@ -251,9 +250,9 @@ export interface IQuickInputService {
navigate
(
next
:
boolean
,
quickNavigate
?:
IQuickNavigateConfiguration
):
void
;
accept
():
T
Promise
<
void
>
;
accept
():
Promise
<
void
>
;
back
():
T
Promise
<
void
>
;
back
():
Promise
<
void
>
;
cancel
():
T
Promise
<
void
>
;
cancel
():
Promise
<
void
>
;
}
src/vs/workbench/browser/parts/quickinput/quickInput.ts
浏览文件 @
9aebfa2c
...
...
@@ -13,7 +13,6 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
import
{
contrastBorder
,
widgetShadow
}
from
'
vs/platform/theme/common/colorRegistry
'
;
import
{
SIDE_BAR_BACKGROUND
,
SIDE_BAR_FOREGROUND
}
from
'
vs/workbench/common/theme
'
;
import
{
IQuickOpenService
}
from
'
vs/platform/quickOpen/common/quickOpen
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
QuickInputList
}
from
'
./quickInputList
'
;
import
{
QuickInputBox
}
from
'
./quickInputBox
'
;
...
...
@@ -1041,8 +1040,8 @@ export class QuickInputService extends Component implements IQuickInputService {
this
.
updateStyles
();
}
pick
<
T
extends
IQuickPickItem
,
O
extends
IPickOptions
<
T
>>
(
picks
:
TPromise
<
QuickPickInput
<
T
>
[]
>
|
QuickPickInput
<
T
>
[],
options
:
O
=
<
O
>
{},
token
:
CancellationToken
=
CancellationToken
.
None
):
T
Promise
<
O
extends
{
canPickMany
:
true
}
?
T
[]
:
T
>
{
return
new
T
Promise
<
O
extends
{
canPickMany
:
true
}
?
T
[]
:
T
>
((
doResolve
,
reject
)
=>
{
pick
<
T
extends
IQuickPickItem
,
O
extends
IPickOptions
<
T
>>
(
picks
:
Promise
<
QuickPickInput
<
T
>
[]
>
|
QuickPickInput
<
T
>
[],
options
:
O
=
<
O
>
{},
token
:
CancellationToken
=
CancellationToken
.
None
):
Promise
<
O
extends
{
canPickMany
:
true
}
?
T
[]
:
T
>
{
return
new
Promise
<
O
extends
{
canPickMany
:
true
}
?
T
[]
:
T
>
((
doResolve
,
reject
)
=>
{
let
resolve
=
(
result
:
any
)
=>
{
resolve
=
doResolve
;
if
(
options
.
onKeyMods
)
{
...
...
@@ -1117,7 +1116,7 @@ export class QuickInputService extends Component implements IQuickInputService {
input
.
quickNavigate
=
options
.
quickNavigate
;
input
.
contextKey
=
options
.
contextKey
;
input
.
busy
=
true
;
TPromise
.
join
([
picks
,
options
.
activeItem
])
Promise
.
all
([
picks
,
options
.
activeItem
])
.
then
(([
items
,
_activeItem
])
=>
{
activeItem
=
_activeItem
;
input
.
busy
=
false
;
...
...
@@ -1130,29 +1129,29 @@ export class QuickInputService extends Component implements IQuickInputService {
}
});
input
.
show
();
TPromise
.
wrap
(
picks
).
then
(
null
,
err
=>
{
Promise
.
resolve
(
picks
).
then
(
null
,
err
=>
{
reject
(
err
);
input
.
hide
();
});
});
}
input
(
options
:
IInputOptions
=
{},
token
:
CancellationToken
=
CancellationToken
.
None
):
T
Promise
<
string
>
{
return
new
T
Promise
<
string
>
((
resolve
,
reject
)
=>
{
input
(
options
:
IInputOptions
=
{},
token
:
CancellationToken
=
CancellationToken
.
None
):
Promise
<
string
>
{
return
new
Promise
<
string
>
((
resolve
,
reject
)
=>
{
if
(
token
.
isCancellationRequested
)
{
resolve
(
undefined
);
return
;
}
const
input
=
this
.
createInputBox
();
const
validateInput
=
options
.
validateInput
||
(()
=>
TPromise
.
as
(
undefined
));
const
validateInput
=
options
.
validateInput
||
(()
=>
<
Thenable
<
undefined
>>
Promise
.
resolve
(
undefined
));
const
onDidValueChange
=
debounceEvent
(
input
.
onDidChangeValue
,
(
last
,
cur
)
=>
cur
,
100
);
let
validationValue
=
options
.
value
||
''
;
let
validation
=
TPromise
.
wrap
(
validateInput
(
validationValue
));
let
validation
=
Promise
.
resolve
(
validateInput
(
validationValue
));
const
disposables
=
[
input
,
onDidValueChange
(
value
=>
{
if
(
value
!==
validationValue
)
{
validation
=
TPromise
.
wrap
(
validateInput
(
value
));
validation
=
Promise
.
resolve
(
validateInput
(
value
));
validationValue
=
value
;
}
validation
.
then
(
result
=>
{
...
...
@@ -1164,7 +1163,7 @@ export class QuickInputService extends Component implements IQuickInputService {
input
.
onDidAccept
(()
=>
{
const
value
=
input
.
value
;
if
(
value
!==
validationValue
)
{
validation
=
TPromise
.
wrap
(
validateInput
(
value
));
validation
=
Promise
.
resolve
(
validateInput
(
value
));
validationValue
=
value
;
}
validation
.
then
(
result
=>
{
...
...
@@ -1335,17 +1334,17 @@ export class QuickInputService extends Component implements IQuickInputService {
accept
()
{
this
.
onDidAcceptEmitter
.
fire
();
return
TPromise
.
as
(
undefined
);
return
Promise
.
resolve
(
undefined
);
}
back
()
{
this
.
onDidTriggerButtonEmitter
.
fire
(
this
.
backButton
);
return
TPromise
.
as
(
undefined
);
return
Promise
.
resolve
(
undefined
);
}
cancel
()
{
this
.
hide
();
return
TPromise
.
as
(
undefined
);
return
Promise
.
resolve
(
undefined
);
}
layout
(
dimension
:
dom
.
Dimension
):
void
{
...
...
@@ -1411,8 +1410,8 @@ export class BackAction extends Action {
super
(
id
,
label
);
}
public
run
():
T
Promise
<
any
>
{
public
run
():
Promise
<
any
>
{
this
.
quickInputService
.
back
();
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
}
src/vs/workbench/browser/parts/quickopen/quickOpenController.ts
浏览文件 @
9aebfa2c
...
...
@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import
'
vs/css!./media/quickopen
'
;
import
{
TPromise
,
ValueCallback
}
from
'
vs/base/common/winjs.base
'
;
import
*
as
nls
from
'
vs/nls
'
;
import
*
as
browser
from
'
vs/base/browser/browser
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
...
...
@@ -54,6 +53,8 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
const
HELP_PREFIX
=
'
?
'
;
type
ValueCallback
<
T
=
any
>
=
(
value
:
T
|
Thenable
<
T
>
)
=>
void
;
export
class
QuickOpenController
extends
Component
implements
IQuickOpenService
{
private
static
readonly
MAX_SHORT_RESPONSE_TIME
=
500
;
...
...
@@ -73,7 +74,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
private
lastSubmittedInputValue
:
string
;
private
quickOpenWidget
:
QuickOpenWidget
;
private
dimension
:
Dimension
;
private
mapResolvedHandlersToPrefix
:
{
[
prefix
:
string
]:
T
Promise
<
QuickOpenHandler
>
;
}
=
Object
.
create
(
null
);
private
mapResolvedHandlersToPrefix
:
{
[
prefix
:
string
]:
Promise
<
QuickOpenHandler
>
;
}
=
Object
.
create
(
null
);
private
mapContextKeyToContext
:
{
[
id
:
string
]:
IContextKey
<
boolean
>
;
}
=
Object
.
create
(
null
);
private
handlerOnOpenCalled
:
{
[
prefix
:
string
]:
boolean
;
}
=
Object
.
create
(
null
);
private
promisesToCompleteOnHide
:
ValueCallback
[]
=
[];
...
...
@@ -153,12 +154,12 @@ export class QuickOpenController extends Component implements IQuickOpenService
}
}
show
(
prefix
?:
string
,
options
?:
IShowOptions
):
T
Promise
<
void
>
{
show
(
prefix
?:
string
,
options
?:
IShowOptions
):
Promise
<
void
>
{
let
quickNavigateConfiguration
=
options
?
options
.
quickNavigateConfiguration
:
void
0
;
let
inputSelection
=
options
?
options
.
inputSelection
:
void
0
;
let
autoFocus
=
options
?
options
.
autoFocus
:
void
0
;
const
promiseCompletedOnHide
=
new
T
Promise
<
void
>
(
c
=>
{
const
promiseCompletedOnHide
=
new
Promise
<
void
>
(
c
=>
{
this
.
promisesToCompleteOnHide
.
push
(
c
);
});
...
...
@@ -381,7 +382,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
return
;
}
let
resultPromise
:
T
Promise
<
void
>
;
let
resultPromise
:
Promise
<
void
>
;
let
resultPromiseDone
=
false
;
if
(
handlerDescriptor
)
{
...
...
@@ -426,7 +427,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
});
}
private
handleDefaultHandler
(
handler
:
QuickOpenHandlerDescriptor
,
value
:
string
,
token
:
CancellationToken
):
T
Promise
<
void
>
{
private
handleDefaultHandler
(
handler
:
QuickOpenHandlerDescriptor
,
value
:
string
,
token
:
CancellationToken
):
Promise
<
void
>
{
// Fill in history results if matching and we are configured to search in history
let
matchingHistoryEntries
:
QuickOpenEntry
[];
...
...
@@ -514,7 +515,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
}
}
private
handleSpecificHandler
(
handlerDescriptor
:
QuickOpenHandlerDescriptor
,
value
:
string
,
token
:
CancellationToken
):
T
Promise
<
void
>
{
private
handleSpecificHandler
(
handlerDescriptor
:
QuickOpenHandlerDescriptor
,
value
:
string
,
token
:
CancellationToken
):
Promise
<
void
>
{
return
this
.
resolveHandler
(
handlerDescriptor
).
then
((
resolvedHandler
:
QuickOpenHandler
)
=>
{
// Remove handler prefix from search value
...
...
@@ -585,7 +586,7 @@ export class QuickOpenController extends Component implements IQuickOpenService
return
mapEntryToPath
;
}
private
resolveHandler
(
handler
:
QuickOpenHandlerDescriptor
):
T
Promise
<
QuickOpenHandler
>
{
private
resolveHandler
(
handler
:
QuickOpenHandlerDescriptor
):
Promise
<
QuickOpenHandler
>
{
let
result
=
this
.
_resolveHandler
(
handler
);
const
id
=
handler
.
getId
();
...
...
@@ -603,11 +604,11 @@ export class QuickOpenController extends Component implements IQuickOpenService
return
result
.
then
<
QuickOpenHandler
>
(
null
,
(
error
)
=>
{
delete
this
.
mapResolvedHandlersToPrefix
[
id
];
return
TPromise
.
wrapError
(
new
Error
(
`Unable to instantiate quick open handler
${
handler
.
getId
()}
:
${
JSON
.
stringify
(
error
)}
`
));
return
Promise
.
reject
(
new
Error
(
`Unable to instantiate quick open handler
${
handler
.
getId
()}
:
${
JSON
.
stringify
(
error
)}
`
));
});
}
private
_resolveHandler
(
handler
:
QuickOpenHandlerDescriptor
):
T
Promise
<
QuickOpenHandler
>
{
private
_resolveHandler
(
handler
:
QuickOpenHandlerDescriptor
):
Promise
<
QuickOpenHandler
>
{
const
id
=
handler
.
getId
();
// Return Cached
...
...
@@ -835,7 +836,7 @@ export class RemoveFromEditorHistoryAction extends Action {
super
(
id
,
label
);
}
run
():
T
Promis
e
<
any
>
{
run
():
T
henabl
e
<
any
>
{
interface
IHistoryPickEntry
extends
IQuickPickItem
{
input
:
IEditorInput
|
IResourceInput
;
}
...
...
src/vs/workbench/parts/search/test/browser/openFileHandler.test.ts
浏览文件 @
9aebfa2c
...
...
@@ -6,14 +6,13 @@
import
*
as
assert
from
'
assert
'
;
import
*
as
errors
from
'
vs/base/common/errors
'
;
import
*
as
objects
from
'
vs/base/common/objects
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
CacheState
}
from
'
vs/workbench/parts/search/browser/openFileHandler
'
;
import
{
Deferred
T
Promise
}
from
'
vs/base/test/common/utils
'
;
import
{
DeferredPromise
}
from
'
vs/base/test/common/utils
'
;
import
{
QueryType
,
IFileQuery
}
from
'
vs/platform/search/common/search
'
;
suite
(
'
CacheState
'
,
()
=>
{
test
(
'
reuse old cacheKey until new cache is loaded
'
,
function
()
{
test
(
'
reuse old cacheKey until new cache is loaded
'
,
async
function
()
{
const
cache
=
new
MockCache
();
...
...
@@ -26,7 +25,7 @@ suite('CacheState', () => {
assert
.
strictEqual
(
first
.
isLoaded
,
false
);
assert
.
strictEqual
(
first
.
isUpdating
,
true
);
cache
.
loading
[
firstKey
].
complete
(
null
);
await
cache
.
loading
[
firstKey
].
complete
(
null
);
assert
.
strictEqual
(
first
.
isLoaded
,
true
);
assert
.
strictEqual
(
first
.
isUpdating
,
false
);
...
...
@@ -34,18 +33,18 @@ suite('CacheState', () => {
second
.
load
();
assert
.
strictEqual
(
second
.
isLoaded
,
true
);
assert
.
strictEqual
(
second
.
isUpdating
,
true
);
a
ssert
.
strictEqual
(
Object
.
keys
(
cache
.
disposing
).
length
,
0
);
a
wait
cache
.
awaitDisposal
(
0
);
assert
.
strictEqual
(
second
.
cacheKey
,
firstKey
);
// still using old cacheKey
const
secondKey
=
cache
.
cacheKeys
[
1
];
cache
.
loading
[
secondKey
].
complete
(
null
);
await
cache
.
loading
[
secondKey
].
complete
(
null
);
assert
.
strictEqual
(
second
.
isLoaded
,
true
);
assert
.
strictEqual
(
second
.
isUpdating
,
false
);
a
ssert
.
strictEqual
(
Object
.
keys
(
cache
.
disposing
).
length
,
1
);
a
wait
cache
.
awaitDisposal
(
1
);
assert
.
strictEqual
(
second
.
cacheKey
,
secondKey
);
});
test
(
'
do not spawn additional load if previous is still loading
'
,
function
()
{
test
(
'
do not spawn additional load if previous is still loading
'
,
async
function
()
{
const
cache
=
new
MockCache
();
...
...
@@ -64,29 +63,29 @@ suite('CacheState', () => {
assert
.
strictEqual
(
Object
.
keys
(
cache
.
loading
).
length
,
1
);
// still only one loading
assert
.
strictEqual
(
second
.
cacheKey
,
firstKey
);
cache
.
loading
[
firstKey
].
complete
(
null
);
await
cache
.
loading
[
firstKey
].
complete
(
null
);
assert
.
strictEqual
(
second
.
isLoaded
,
true
);
assert
.
strictEqual
(
second
.
isUpdating
,
false
);
a
ssert
.
strictEqual
(
Object
.
keys
(
cache
.
disposing
).
length
,
0
);
a
wait
cache
.
awaitDisposal
(
0
);
});
test
(
'
do not use previous cacheKey if query changed
'
,
function
()
{
test
(
'
do not use previous cacheKey if query changed
'
,
async
function
()
{
const
cache
=
new
MockCache
();
const
first
=
createCacheState
(
cache
);
const
firstKey
=
first
.
cacheKey
;
first
.
load
();
cache
.
loading
[
firstKey
].
complete
(
null
);
await
cache
.
loading
[
firstKey
].
complete
(
null
);
assert
.
strictEqual
(
first
.
isLoaded
,
true
);
assert
.
strictEqual
(
first
.
isUpdating
,
false
);
a
ssert
.
strictEqual
(
Object
.
keys
(
cache
.
disposing
).
length
,
0
);
a
wait
cache
.
awaitDisposal
(
0
);
cache
.
baseQuery
.
excludePattern
=
{
'
**/node_modules
'
:
true
};
const
second
=
createCacheState
(
cache
,
first
);
assert
.
strictEqual
(
second
.
isLoaded
,
false
);
assert
.
strictEqual
(
second
.
isUpdating
,
false
);
a
ssert
.
strictEqual
(
Object
.
keys
(
cache
.
disposing
).
length
,
1
);
a
wait
cache
.
awaitDisposal
(
1
);
second
.
load
();
assert
.
strictEqual
(
second
.
isLoaded
,
false
);
...
...
@@ -95,40 +94,40 @@ suite('CacheState', () => {
const
secondKey
=
cache
.
cacheKeys
[
1
];
assert
.
strictEqual
(
second
.
cacheKey
,
secondKey
);
cache
.
loading
[
secondKey
].
complete
(
null
);
await
cache
.
loading
[
secondKey
].
complete
(
null
);
assert
.
strictEqual
(
second
.
isLoaded
,
true
);
assert
.
strictEqual
(
second
.
isUpdating
,
false
);
a
ssert
.
strictEqual
(
Object
.
keys
(
cache
.
disposing
).
length
,
1
);
a
wait
cache
.
awaitDisposal
(
1
);
});
test
(
'
dispose propagates
'
,
function
()
{
test
(
'
dispose propagates
'
,
async
function
()
{
const
cache
=
new
MockCache
();
const
first
=
createCacheState
(
cache
);
const
firstKey
=
first
.
cacheKey
;
first
.
load
();
cache
.
loading
[
firstKey
].
complete
(
null
);
await
cache
.
loading
[
firstKey
].
complete
(
null
);
const
second
=
createCacheState
(
cache
,
first
);
assert
.
strictEqual
(
second
.
isLoaded
,
true
);
assert
.
strictEqual
(
second
.
isUpdating
,
false
);
a
ssert
.
strictEqual
(
Object
.
keys
(
cache
.
disposing
).
length
,
0
);
a
wait
cache
.
awaitDisposal
(
0
);
second
.
dispose
();
assert
.
strictEqual
(
second
.
isLoaded
,
false
);
assert
.
strictEqual
(
second
.
isUpdating
,
false
);
a
ssert
.
strictEqual
(
Object
.
keys
(
cache
.
disposing
).
length
,
1
);
a
wait
cache
.
awaitDisposal
(
1
);
assert
.
ok
(
cache
.
disposing
[
firstKey
]);
});
test
(
'
keep using old cacheKey when loading fails
'
,
function
()
{
test
(
'
keep using old cacheKey when loading fails
'
,
async
function
()
{
const
cache
=
new
MockCache
();
const
first
=
createCacheState
(
cache
);
const
firstKey
=
first
.
cacheKey
;
first
.
load
();
cache
.
loading
[
firstKey
].
complete
(
null
);
await
cache
.
loading
[
firstKey
].
complete
(
null
);
const
second
=
createCacheState
(
cache
,
first
);
second
.
load
();
...
...
@@ -136,14 +135,14 @@ suite('CacheState', () => {
const
origErrorHandler
=
errors
.
errorHandler
.
getUnexpectedErrorHandler
();
try
{
errors
.
setUnexpectedErrorHandler
(()
=>
null
);
cache
.
loading
[
secondKey
].
error
(
'
loading failed
'
);
await
cache
.
loading
[
secondKey
].
error
(
'
loading failed
'
);
}
finally
{
errors
.
setUnexpectedErrorHandler
(
origErrorHandler
);
}
assert
.
strictEqual
(
second
.
isLoaded
,
true
);
assert
.
strictEqual
(
second
.
isUpdating
,
false
);
assert
.
strictEqual
(
Object
.
keys
(
cache
.
loading
).
length
,
2
);
a
ssert
.
strictEqual
(
Object
.
keys
(
cache
.
disposing
).
length
,
0
);
a
wait
cache
.
awaitDisposal
(
0
);
assert
.
strictEqual
(
second
.
cacheKey
,
firstKey
);
// keep using old cacheKey
const
third
=
createCacheState
(
cache
,
second
);
...
...
@@ -151,15 +150,15 @@ suite('CacheState', () => {
assert
.
strictEqual
(
third
.
isLoaded
,
true
);
assert
.
strictEqual
(
third
.
isUpdating
,
true
);
assert
.
strictEqual
(
Object
.
keys
(
cache
.
loading
).
length
,
3
);
a
ssert
.
strictEqual
(
Object
.
keys
(
cache
.
disposing
).
length
,
0
);
a
wait
cache
.
awaitDisposal
(
0
);
assert
.
strictEqual
(
third
.
cacheKey
,
firstKey
);
const
thirdKey
=
cache
.
cacheKeys
[
2
];
cache
.
loading
[
thirdKey
].
complete
(
null
);
await
cache
.
loading
[
thirdKey
].
complete
(
null
);
assert
.
strictEqual
(
third
.
isLoaded
,
true
);
assert
.
strictEqual
(
third
.
isUpdating
,
false
);
assert
.
strictEqual
(
Object
.
keys
(
cache
.
loading
).
length
,
3
);
a
ssert
.
strictEqual
(
Object
.
keys
(
cache
.
disposing
).
length
,
2
);
a
wait
cache
.
awaitDisposal
(
2
);
assert
.
strictEqual
(
third
.
cacheKey
,
thirdKey
);
// recover with next successful load
});
...
...
@@ -175,8 +174,10 @@ suite('CacheState', () => {
class
MockCache
{
public
cacheKeys
:
string
[]
=
[];
public
loading
:
{
[
cacheKey
:
string
]:
DeferredTPromise
<
any
>
}
=
{};
public
disposing
:
{
[
cacheKey
:
string
]:
DeferredTPromise
<
void
>
}
=
{};
public
loading
:
{
[
cacheKey
:
string
]:
DeferredPromise
<
any
>
}
=
{};
public
disposing
:
{
[
cacheKey
:
string
]:
DeferredPromise
<
void
>
}
=
{};
private
_awaitDisposal
:
(()
=>
void
)[][]
=
[];
public
baseQuery
:
IFileQuery
=
{
type
:
QueryType
.
File
...
...
@@ -187,16 +188,31 @@ suite('CacheState', () => {
return
objects
.
assign
({
cacheKey
:
cacheKey
},
this
.
baseQuery
);
}
public
load
(
query
:
IFileQuery
):
T
Promise
<
any
>
{
const
promise
=
new
Deferred
T
Promise
<
any
>
();
public
load
(
query
:
IFileQuery
):
Promise
<
any
>
{
const
promise
=
new
DeferredPromise
<
any
>
();
this
.
loading
[
query
.
cacheKey
]
=
promise
;
return
promise
;
return
promise
.
p
;
}
public
dispose
(
cacheKey
:
string
):
T
Promise
<
void
>
{
const
promise
=
new
Deferred
T
Promise
<
void
>
();
public
dispose
(
cacheKey
:
string
):
Promise
<
void
>
{
const
promise
=
new
DeferredPromise
<
void
>
();
this
.
disposing
[
cacheKey
]
=
promise
;
return
promise
;
const
n
=
Object
.
keys
(
this
.
disposing
).
length
;
for
(
const
done
of
this
.
_awaitDisposal
[
n
]
||
[])
{
done
();
}
delete
this
.
_awaitDisposal
[
n
];
return
promise
.
p
;
}
public
awaitDisposal
(
n
:
number
)
{
return
new
Promise
(
resolve
=>
{
if
(
n
===
Object
.
keys
(
this
.
disposing
).
length
)
{
resolve
();
}
else
{
(
this
.
_awaitDisposal
[
n
]
||
(
this
.
_awaitDisposal
[
n
]
=
[])).
push
(
resolve
);
}
});
}
}
});
src/vs/workbench/parts/welcome/walkThrough/node/walkThroughContentProvider.ts
浏览文件 @
9aebfa2c
...
...
@@ -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
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
ITextModelService
,
ITextModelContentProvider
}
from
'
vs/editor/common/services/resolverService
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
...
...
@@ -26,9 +25,9 @@ export class WalkThroughContentProvider implements ITextModelContentProvider, IW
this
.
textModelResolverService
.
registerTextModelContentProvider
(
Schemas
.
walkThrough
,
this
);
}
public
provideTextContent
(
resource
:
URI
):
T
Promis
e
<
ITextModel
>
{
public
provideTextContent
(
resource
:
URI
):
T
henabl
e
<
ITextModel
>
{
const
query
=
resource
.
query
?
JSON
.
parse
(
resource
.
query
)
:
{};
const
content
:
T
Promise
<
string
|
ITextBufferFactory
>
=
(
query
.
moduleId
?
new
T
Promise
<
string
>
((
resolve
,
reject
)
=>
{
const
content
:
T
henable
<
string
|
ITextBufferFactory
>
=
(
query
.
moduleId
?
new
Promise
<
string
>
((
resolve
,
reject
)
=>
{
require
([
query
.
moduleId
],
content
=>
{
try
{
resolve
(
content
.
default
());
...
...
@@ -61,7 +60,7 @@ export class WalkThroughSnippetContentProvider implements ITextModelContentProvi
this
.
textModelResolverService
.
registerTextModelContentProvider
(
Schemas
.
walkThroughSnippet
,
this
);
}
public
provideTextContent
(
resource
:
URI
):
T
Promis
e
<
ITextModel
>
{
public
provideTextContent
(
resource
:
URI
):
T
henabl
e
<
ITextModel
>
{
return
this
.
textFileService
.
resolveTextContent
(
URI
.
file
(
resource
.
fsPath
)).
then
(
content
=>
{
let
codeEditorModel
=
this
.
modelService
.
getModel
(
resource
);
if
(
!
codeEditorModel
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录