Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
6daba771
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,发现更多精彩内容 >>
提交
6daba771
编写于
10月 09, 2018
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Migrate to native Promise in web worker related code (#53526)
上级
99d97b5d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
104 addition
and
110 deletion
+104
-110
src/vs/base/common/worker/simpleWorker.ts
src/vs/base/common/worker/simpleWorker.ts
+41
-42
src/vs/editor/common/services/editorSimpleWorker.ts
src/vs/editor/common/services/editorSimpleWorker.ts
+23
-24
src/vs/editor/common/services/editorWorkerService.ts
src/vs/editor/common/services/editorWorkerService.ts
+5
-6
src/vs/editor/common/services/editorWorkerServiceImpl.ts
src/vs/editor/common/services/editorWorkerServiceImpl.ts
+24
-25
src/vs/editor/common/services/webWorker.ts
src/vs/editor/common/services/webWorker.ts
+8
-9
src/vs/workbench/parts/output/common/outputLinkComputer.ts
src/vs/workbench/parts/output/common/outputLinkComputer.ts
+2
-2
src/vs/workbench/parts/output/common/outputLinkProvider.ts
src/vs/workbench/parts/output/common/outputLinkProvider.ts
+1
-2
未找到文件。
src/vs/base/common/worker/simpleWorker.ts
浏览文件 @
6daba771
...
...
@@ -5,7 +5,6 @@
import
{
transformErrorForSerialization
}
from
'
vs/base/common/errors
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
ErrorCallback
,
TPromise
,
ValueCallback
}
from
'
vs/base/common/winjs.base
'
;
import
{
isWeb
}
from
'
vs/base/common/platform
'
;
const
INITIALIZE
=
'
$initialize
'
;
...
...
@@ -56,13 +55,13 @@ interface IReplyMessage extends IMessage {
}
interface
IMessageReply
{
c
:
ValueCallback
;
e
:
ErrorCallback
;
resolve
:
(
value
?:
any
)
=>
void
;
reject
:
(
error
?:
any
)
=>
void
;
}
interface
IMessageHandler
{
sendMessage
(
msg
:
string
):
void
;
handleMessage
(
method
:
string
,
args
:
any
[]):
T
Promise
<
any
>
;
handleMessage
(
method
:
string
,
args
:
any
[]):
Promise
<
any
>
;
}
class
SimpleWorkerProtocol
{
...
...
@@ -83,15 +82,15 @@ class SimpleWorkerProtocol {
this
.
_workerId
=
workerId
;
}
public
sendMessage
(
method
:
string
,
args
:
any
[]):
T
Promise
<
any
>
{
public
sendMessage
(
method
:
string
,
args
:
any
[]):
Promise
<
any
>
{
let
req
=
String
(
++
this
.
_lastSentReq
);
let
reply
:
IMessageReply
=
{
c
:
null
,
e
:
null
resolve
:
null
,
reject
:
null
};
let
result
=
new
TPromise
<
any
>
((
c
,
e
)
=>
{
reply
.
c
=
c
;
reply
.
e
=
e
;
let
result
=
new
Promise
<
any
>
((
resolve
,
reject
)
=>
{
reply
.
resolve
=
resolve
;
reply
.
reject
=
reject
;
});
this
.
_pendingReplies
[
req
]
=
reply
;
...
...
@@ -140,11 +139,11 @@ class SimpleWorkerProtocol {
err
.
message
=
replyMessage
.
err
.
message
;
err
.
stack
=
replyMessage
.
err
.
stack
;
}
reply
.
e
(
err
);
reply
.
reject
(
err
);
return
;
}
reply
.
c
(
replyMessage
.
res
);
reply
.
resolve
(
replyMessage
.
res
);
return
;
}
...
...
@@ -185,14 +184,14 @@ class SimpleWorkerProtocol {
export
class
SimpleWorkerClient
<
T
>
extends
Disposable
{
private
_worker
:
IWorker
;
private
_onModuleLoaded
:
T
Promise
<
string
[]
>
;
private
_onModuleLoaded
:
Promise
<
string
[]
>
;
private
_protocol
:
SimpleWorkerProtocol
;
private
_lazyProxy
:
T
Promise
<
T
>
;
private
_lazyProxy
:
Promise
<
T
>
;
constructor
(
workerFactory
:
IWorkerFactory
,
moduleId
:
string
)
{
super
();
let
lazyProxy
Fulfill
:
(
v
:
T
)
=>
void
=
null
;
let
lazyProxy
Resolve
:
(
v
:
T
)
=>
void
=
null
;
let
lazyProxyReject
:
(
err
:
any
)
=>
void
=
null
;
this
.
_worker
=
this
.
_register
(
workerFactory
.
create
(
...
...
@@ -211,9 +210,9 @@ export class SimpleWorkerClient<T> extends Disposable {
sendMessage
:
(
msg
:
string
):
void
=>
{
this
.
_worker
.
postMessage
(
msg
);
},
handleMessage
:
(
method
:
string
,
args
:
any
[]):
T
Promise
<
any
>
=>
{
handleMessage
:
(
method
:
string
,
args
:
any
[]):
Promise
<
any
>
=>
{
// Intentionally not supporting worker -> main requests
return
TPromise
.
as
(
null
);
return
Promise
.
resolve
(
null
);
}
});
this
.
_protocol
.
setWorkerId
(
this
.
_worker
.
getId
());
...
...
@@ -228,9 +227,9 @@ export class SimpleWorkerClient<T> extends Disposable {
loaderConfiguration
=
(
<
any
>
self
).
requirejs
.
s
.
contexts
.
_
.
config
;
}
this
.
_lazyProxy
=
new
TPromise
<
T
>
((
c
,
e
)
=>
{
lazyProxy
Fulfill
=
c
;
lazyProxyReject
=
e
;
this
.
_lazyProxy
=
new
Promise
<
T
>
((
resolve
,
reject
)
=>
{
lazyProxy
Resolve
=
resolve
;
lazyProxyReject
=
reject
;
});
// Send initialize message
...
...
@@ -244,18 +243,18 @@ export class SimpleWorkerClient<T> extends Disposable {
for
(
let
i
=
0
;
i
<
availableMethods
.
length
;
i
++
)
{
(
proxy
as
any
)[
availableMethods
[
i
]]
=
createProxyMethod
(
availableMethods
[
i
],
proxyMethodRequest
);
}
lazyProxy
Fulfill
(
proxy
);
lazyProxy
Resolve
(
proxy
);
},
(
e
)
=>
{
lazyProxyReject
(
e
);
this
.
_onError
(
'
Worker failed to load
'
+
moduleId
,
e
);
});
// Create proxy to loaded code
let
proxyMethodRequest
=
(
method
:
string
,
args
:
any
[]):
T
Promise
<
any
>
=>
{
let
proxyMethodRequest
=
(
method
:
string
,
args
:
any
[]):
Promise
<
any
>
=>
{
return
this
.
_request
(
method
,
args
);
};
let
createProxyMethod
=
(
method
:
string
,
proxyMethodRequest
:
(
method
:
string
,
args
:
any
[])
=>
T
Promise
<
any
>
):
Function
=>
{
let
createProxyMethod
=
(
method
:
string
,
proxyMethodRequest
:
(
method
:
string
,
args
:
any
[])
=>
Promise
<
any
>
):
Function
=>
{
return
function
()
{
let
args
=
Array
.
prototype
.
slice
.
call
(
arguments
,
0
);
return
proxyMethodRequest
(
method
,
args
);
...
...
@@ -263,15 +262,15 @@ export class SimpleWorkerClient<T> extends Disposable {
};
}
public
getProxyObject
():
T
Promise
<
T
>
{
public
getProxyObject
():
Promise
<
T
>
{
return
this
.
_lazyProxy
;
}
private
_request
(
method
:
string
,
args
:
any
[]):
T
Promise
<
any
>
{
return
new
TPromise
<
any
>
((
c
,
e
)
=>
{
private
_request
(
method
:
string
,
args
:
any
[]):
Promise
<
any
>
{
return
new
Promise
<
any
>
((
resolve
,
reject
)
=>
{
this
.
_onModuleLoaded
.
then
(()
=>
{
this
.
_protocol
.
sendMessage
(
method
,
args
).
then
(
c
,
e
);
},
e
);
this
.
_protocol
.
sendMessage
(
method
,
args
).
then
(
resolve
,
reject
);
},
reject
);
});
}
...
...
@@ -300,7 +299,7 @@ export class SimpleWorkerServer {
sendMessage
:
(
msg
:
string
):
void
=>
{
postSerializedMessage
(
msg
);
},
handleMessage
:
(
method
:
string
,
args
:
any
[]):
T
Promise
<
any
>
=>
this
.
_handleMessage
(
method
,
args
)
handleMessage
:
(
method
:
string
,
args
:
any
[]):
Promise
<
any
>
=>
this
.
_handleMessage
(
method
,
args
)
});
}
...
...
@@ -308,23 +307,23 @@ export class SimpleWorkerServer {
this
.
_protocol
.
handleMessage
(
msg
);
}
private
_handleMessage
(
method
:
string
,
args
:
any
[]):
T
Promise
<
any
>
{
private
_handleMessage
(
method
:
string
,
args
:
any
[]):
Promise
<
any
>
{
if
(
method
===
INITIALIZE
)
{
return
this
.
initialize
(
<
number
>
args
[
0
],
<
string
>
args
[
1
],
<
any
>
args
[
2
]);
}
if
(
!
this
.
_requestHandler
||
typeof
this
.
_requestHandler
[
method
]
!==
'
function
'
)
{
return
TPromise
.
wrapError
(
new
Error
(
'
Missing requestHandler or method:
'
+
method
));
return
Promise
.
reject
(
new
Error
(
'
Missing requestHandler or method:
'
+
method
));
}
try
{
return
TPromise
.
as
(
this
.
_requestHandler
[
method
].
apply
(
this
.
_requestHandler
,
args
));
return
Promise
.
resolve
(
this
.
_requestHandler
[
method
].
apply
(
this
.
_requestHandler
,
args
));
}
catch
(
e
)
{
return
TPromise
.
wrapError
(
e
);
return
Promise
.
reject
(
e
);
}
}
private
initialize
(
workerId
:
number
,
moduleId
:
string
,
loaderConfig
:
any
):
TPromise
<
any
>
{
private
initialize
(
workerId
:
number
,
moduleId
:
string
,
loaderConfig
:
any
):
Promise
<
string
[]
>
{
this
.
_protocol
.
setWorkerId
(
workerId
);
if
(
this
.
_requestHandler
)
{
...
...
@@ -335,7 +334,7 @@ export class SimpleWorkerServer {
methods
.
push
(
prop
);
}
}
return
TPromise
.
as
(
methods
);
return
Promise
.
resolve
(
methods
);
}
if
(
loaderConfig
)
{
...
...
@@ -354,11 +353,11 @@ export class SimpleWorkerServer {
(
<
any
>
self
).
require
.
config
(
loaderConfig
);
}
let
cc
:
ValueCallback
;
let
ee
:
ErrorCallback
;
let
r
=
new
TPromise
<
any
>
((
c
,
e
)
=>
{
cc
=
c
;
ee
=
e
;
let
resolve
:
(
value
?:
string
[])
=>
void
;
let
reject
:
(
error
?:
any
)
=>
void
;
let
r
=
new
Promise
<
string
[]
>
((
_resolve
,
_reject
)
=>
{
resolve
=
_resolve
;
reject
=
_reject
;
});
// Use the global require to be sure to get the global config
...
...
@@ -373,8 +372,8 @@ export class SimpleWorkerServer {
}
}
cc
(
methods
);
},
ee
);
resolve
(
methods
);
},
reject
);
return
r
;
}
...
...
src/vs/editor/common/services/editorSimpleWorker.ts
浏览文件 @
6daba771
...
...
@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IRequestHandler
}
from
'
vs/base/common/worker/simpleWorker
'
;
import
{
Range
,
IRange
}
from
'
vs/editor/common/core/range
'
;
...
...
@@ -336,7 +335,7 @@ export abstract class BaseEditorSimpleWorker {
// ---- BEGIN diff --------------------------------------------------------------------------
public
computeDiff
(
originalUrl
:
string
,
modifiedUrl
:
string
,
ignoreTrimWhitespace
:
boolean
):
T
Promise
<
editorCommon
.
ILineChange
[]
>
{
public
computeDiff
(
originalUrl
:
string
,
modifiedUrl
:
string
,
ignoreTrimWhitespace
:
boolean
):
Promise
<
editorCommon
.
ILineChange
[]
>
{
let
original
=
this
.
_getModel
(
originalUrl
);
let
modified
=
this
.
_getModel
(
modifiedUrl
);
if
(
!
original
||
!
modified
)
{
...
...
@@ -351,10 +350,10 @@ export abstract class BaseEditorSimpleWorker {
shouldIgnoreTrimWhitespace
:
ignoreTrimWhitespace
,
shouldMakePrettyDiff
:
true
});
return
TPromise
.
as
(
diffComputer
.
computeDiff
());
return
Promise
.
resolve
(
diffComputer
.
computeDiff
());
}
public
computeDirtyDiff
(
originalUrl
:
string
,
modifiedUrl
:
string
,
ignoreTrimWhitespace
:
boolean
):
T
Promise
<
editorCommon
.
IChange
[]
>
{
public
computeDirtyDiff
(
originalUrl
:
string
,
modifiedUrl
:
string
,
ignoreTrimWhitespace
:
boolean
):
Promise
<
editorCommon
.
IChange
[]
>
{
let
original
=
this
.
_getModel
(
originalUrl
);
let
modified
=
this
.
_getModel
(
modifiedUrl
);
if
(
!
original
||
!
modified
)
{
...
...
@@ -369,7 +368,7 @@ export abstract class BaseEditorSimpleWorker {
shouldIgnoreTrimWhitespace
:
ignoreTrimWhitespace
,
shouldMakePrettyDiff
:
true
});
return
TPromise
.
as
(
diffComputer
.
computeDiff
());
return
Promise
.
resolve
(
diffComputer
.
computeDiff
());
}
// ---- END diff --------------------------------------------------------------------------
...
...
@@ -379,10 +378,10 @@ export abstract class BaseEditorSimpleWorker {
private
static
readonly
_diffLimit
=
10000
;
public
computeMoreMinimalEdits
(
modelUrl
:
string
,
edits
:
TextEdit
[]):
T
Promise
<
TextEdit
[]
>
{
public
computeMoreMinimalEdits
(
modelUrl
:
string
,
edits
:
TextEdit
[]):
Promise
<
TextEdit
[]
>
{
const
model
=
this
.
_getModel
(
modelUrl
);
if
(
!
model
)
{
return
TPromise
.
as
(
edits
);
return
Promise
.
resolve
(
edits
);
}
const
result
:
TextEdit
[]
=
[];
...
...
@@ -437,25 +436,25 @@ export abstract class BaseEditorSimpleWorker {
result
.
push
({
eol
:
lastEol
,
text
:
undefined
,
range
:
undefined
});
}
return
TPromise
.
as
(
result
);
return
Promise
.
resolve
(
result
);
}
// ---- END minimal edits ---------------------------------------------------------------
public
computeLinks
(
modelUrl
:
string
):
T
Promise
<
ILink
[]
>
{
public
computeLinks
(
modelUrl
:
string
):
Promise
<
ILink
[]
>
{
let
model
=
this
.
_getModel
(
modelUrl
);
if
(
!
model
)
{
return
null
;
}
return
TPromise
.
as
(
computeLinks
(
model
));
return
Promise
.
resolve
(
computeLinks
(
model
));
}
// ---- BEGIN suggest --------------------------------------------------------------------------
private
static
readonly
_suggestionsLimit
=
10000
;
public
textualSuggest
(
modelUrl
:
string
,
position
:
IPosition
,
wordDef
:
string
,
wordDefFlags
:
string
):
T
Promise
<
CompletionList
>
{
public
textualSuggest
(
modelUrl
:
string
,
position
:
IPosition
,
wordDef
:
string
,
wordDefFlags
:
string
):
Promise
<
CompletionList
>
{
const
model
=
this
.
_getModel
(
modelUrl
);
if
(
model
)
{
const
suggestions
:
CompletionItem
[]
=
[];
...
...
@@ -488,7 +487,7 @@ export abstract class BaseEditorSimpleWorker {
});
}
return
TPromise
.
as
({
suggestions
});
return
Promise
.
resolve
({
suggestions
});
}
return
undefined
;
}
...
...
@@ -529,7 +528,7 @@ export abstract class BaseEditorSimpleWorker {
//#endregion
public
navigateValueSet
(
modelUrl
:
string
,
range
:
IRange
,
up
:
boolean
,
wordDef
:
string
,
wordDefFlags
:
string
):
T
Promise
<
IInplaceReplaceSupportResult
>
{
public
navigateValueSet
(
modelUrl
:
string
,
range
:
IRange
,
up
:
boolean
,
wordDef
:
string
,
wordDefFlags
:
string
):
Promise
<
IInplaceReplaceSupportResult
>
{
let
model
=
this
.
_getModel
(
modelUrl
);
if
(
!
model
)
{
return
null
;
...
...
@@ -555,12 +554,12 @@ export abstract class BaseEditorSimpleWorker {
}
let
result
=
BasicInplaceReplace
.
INSTANCE
.
navigateValueSet
(
range
,
selectionText
,
wordRange
,
word
,
up
);
return
TPromise
.
as
(
result
);
return
Promise
.
resolve
(
result
);
}
// ---- BEGIN foreign module support --------------------------------------------------------------------------
public
loadForeignModule
(
moduleId
:
string
,
createData
:
any
):
T
Promise
<
string
[]
>
{
public
loadForeignModule
(
moduleId
:
string
,
createData
:
any
):
Promise
<
string
[]
>
{
let
ctx
:
IWorkerContext
=
{
getMirrorModels
:
():
IMirrorModel
[]
=>
{
return
this
.
_getModels
();
...
...
@@ -576,10 +575,10 @@ export abstract class BaseEditorSimpleWorker {
methods
.
push
(
prop
);
}
}
return
TPromise
.
as
(
methods
);
return
Promise
.
resolve
(
methods
);
}
// ESM-comment-begin
return
new
TPromise
<
any
>
((
c
,
e
)
=>
{
return
new
Promise
<
any
>
((
resolve
,
reject
)
=>
{
require
([
moduleId
],
(
foreignModule
:
{
create
:
IForeignModuleFactory
})
=>
{
this
.
_foreignModule
=
foreignModule
.
create
(
ctx
,
createData
);
...
...
@@ -590,27 +589,27 @@ export abstract class BaseEditorSimpleWorker {
}
}
c
(
methods
);
resolve
(
methods
);
},
e
);
},
reject
);
});
// ESM-comment-end
// ESM-uncomment-begin
// return
TPromise.wrapError
(new Error(`Unexpected usage`));
// return
Promise.reject
(new Error(`Unexpected usage`));
// ESM-uncomment-end
}
// foreign method request
public
fmr
(
method
:
string
,
args
:
any
[]):
T
Promise
<
any
>
{
public
fmr
(
method
:
string
,
args
:
any
[]):
Promise
<
any
>
{
if
(
!
this
.
_foreignModule
||
typeof
this
.
_foreignModule
[
method
]
!==
'
function
'
)
{
return
TPromise
.
wrapError
(
new
Error
(
'
Missing requestHandler or method:
'
+
method
));
return
Promise
.
reject
(
new
Error
(
'
Missing requestHandler or method:
'
+
method
));
}
try
{
return
TPromise
.
as
(
this
.
_foreignModule
[
method
].
apply
(
this
.
_foreignModule
,
args
));
return
Promise
.
resolve
(
this
.
_foreignModule
[
method
].
apply
(
this
.
_foreignModule
,
args
));
}
catch
(
e
)
{
return
TPromise
.
wrapError
(
e
);
return
Promise
.
reject
(
e
);
}
}
...
...
src/vs/editor/common/services/editorWorkerService.ts
浏览文件 @
6daba771
...
...
@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IChange
,
ILineChange
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IInplaceReplaceSupportResult
,
TextEdit
}
from
'
vs/editor/common/modes
'
;
...
...
@@ -17,16 +16,16 @@ export interface IEditorWorkerService {
_serviceBrand
:
any
;
canComputeDiff
(
original
:
URI
,
modified
:
URI
):
boolean
;
computeDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
T
Promise
<
ILineChange
[]
>
;
computeDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
Promise
<
ILineChange
[]
>
;
canComputeDirtyDiff
(
original
:
URI
,
modified
:
URI
):
boolean
;
computeDirtyDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
T
Promise
<
IChange
[]
>
;
computeDirtyDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
Promise
<
IChange
[]
>
;
computeMoreMinimalEdits
(
resource
:
URI
,
edits
:
TextEdit
[]):
T
Promise
<
TextEdit
[]
>
;
computeMoreMinimalEdits
(
resource
:
URI
,
edits
:
TextEdit
[]):
Promise
<
TextEdit
[]
>
;
canComputeWordRanges
(
resource
:
URI
):
boolean
;
computeWordRanges
(
resource
:
URI
,
range
:
IRange
):
T
Promise
<
{
[
word
:
string
]:
IRange
[]
}
>
;
computeWordRanges
(
resource
:
URI
,
range
:
IRange
):
Promise
<
{
[
word
:
string
]:
IRange
[]
}
>
;
canNavigateValueSet
(
resource
:
URI
):
boolean
;
navigateValueSet
(
resource
:
URI
,
range
:
IRange
,
up
:
boolean
):
T
Promise
<
IInplaceReplaceSupportResult
>
;
navigateValueSet
(
resource
:
URI
,
range
:
IRange
,
up
:
boolean
):
Promise
<
IInplaceReplaceSupportResult
>
;
}
src/vs/editor/common/services/editorWorkerServiceImpl.ts
浏览文件 @
6daba771
...
...
@@ -6,7 +6,6 @@
import
{
IntervalTimer
}
from
'
vs/base/common/async
'
;
import
{
Disposable
,
IDisposable
,
dispose
,
toDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
SimpleWorkerClient
,
logOnceWebWorkerWarning
}
from
'
vs/base/common/worker/simpleWorker
'
;
import
{
DefaultWorkerFactory
}
from
'
vs/base/worker/defaultWorkerFactory
'
;
import
*
as
editorCommon
from
'
vs/editor/common/editorCommon
'
;
...
...
@@ -60,7 +59,7 @@ export class EditorWorkerServiceImpl extends Disposable implements IEditorWorker
this
.
_register
(
modes
.
LinkProviderRegistry
.
register
(
'
*
'
,
<
modes
.
LinkProvider
>
{
provideLinks
:
(
model
,
token
)
=>
{
if
(
!
canSyncModel
(
this
.
_modelService
,
model
.
uri
))
{
return
TPromise
.
as
([]);
// File too large
return
Promise
.
resolve
([]);
// File too large
}
return
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
computeLinks
(
model
.
uri
));
}
...
...
@@ -76,7 +75,7 @@ export class EditorWorkerServiceImpl extends Disposable implements IEditorWorker
return
(
canSyncModel
(
this
.
_modelService
,
original
)
&&
canSyncModel
(
this
.
_modelService
,
modified
));
}
public
computeDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
T
Promise
<
editorCommon
.
ILineChange
[]
>
{
public
computeDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
Promise
<
editorCommon
.
ILineChange
[]
>
{
return
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
computeDiff
(
original
,
modified
,
ignoreTrimWhitespace
));
}
...
...
@@ -84,16 +83,16 @@ export class EditorWorkerServiceImpl extends Disposable implements IEditorWorker
return
(
canSyncModel
(
this
.
_modelService
,
original
)
&&
canSyncModel
(
this
.
_modelService
,
modified
));
}
public
computeDirtyDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
T
Promise
<
editorCommon
.
IChange
[]
>
{
public
computeDirtyDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
Promise
<
editorCommon
.
IChange
[]
>
{
return
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
computeDirtyDiff
(
original
,
modified
,
ignoreTrimWhitespace
));
}
public
computeMoreMinimalEdits
(
resource
:
URI
,
edits
:
modes
.
TextEdit
[]):
T
Promise
<
modes
.
TextEdit
[]
>
{
public
computeMoreMinimalEdits
(
resource
:
URI
,
edits
:
modes
.
TextEdit
[]):
Promise
<
modes
.
TextEdit
[]
>
{
if
(
!
Array
.
isArray
(
edits
)
||
edits
.
length
===
0
)
{
return
TPromise
.
as
(
edits
);
return
Promise
.
resolve
(
edits
);
}
else
{
if
(
!
canSyncModel
(
this
.
_modelService
,
resource
))
{
return
TPromise
.
as
(
edits
);
// File too large
return
Promise
.
resolve
(
edits
);
// File too large
}
return
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
computeMoreMinimalEdits
(
resource
,
edits
));
}
...
...
@@ -103,7 +102,7 @@ export class EditorWorkerServiceImpl extends Disposable implements IEditorWorker
return
(
canSyncModel
(
this
.
_modelService
,
resource
));
}
public
navigateValueSet
(
resource
:
URI
,
range
:
IRange
,
up
:
boolean
):
T
Promise
<
modes
.
IInplaceReplaceSupportResult
>
{
public
navigateValueSet
(
resource
:
URI
,
range
:
IRange
,
up
:
boolean
):
Promise
<
modes
.
IInplaceReplaceSupportResult
>
{
return
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
navigateValueSet
(
resource
,
range
,
up
));
}
...
...
@@ -111,7 +110,7 @@ export class EditorWorkerServiceImpl extends Disposable implements IEditorWorker
return
canSyncModel
(
this
.
_modelService
,
resource
);
}
computeWordRanges
(
resource
:
URI
,
range
:
IRange
):
T
Promise
<
{
[
word
:
string
]:
IRange
[]
}
>
{
computeWordRanges
(
resource
:
URI
,
range
:
IRange
):
Promise
<
{
[
word
:
string
]:
IRange
[]
}
>
{
return
this
.
_workerManager
.
withWorker
().
then
(
client
=>
client
.
computeWordRanges
(
resource
,
range
));
}
}
...
...
@@ -132,7 +131,7 @@ class WordBasedCompletionItemProvider implements modes.CompletionItemProvider {
this
.
_modelService
=
modelService
;
}
provideCompletionItems
(
model
:
ITextModel
,
position
:
Position
):
T
Promise
<
modes
.
CompletionList
>
{
provideCompletionItems
(
model
:
ITextModel
,
position
:
Position
):
Promise
<
modes
.
CompletionList
>
{
const
{
wordBasedSuggestions
}
=
this
.
_configurationService
.
getValue
<
IEditorOptions
>
(
model
.
uri
,
position
,
'
editor
'
);
if
(
!
wordBasedSuggestions
)
{
return
undefined
;
...
...
@@ -200,12 +199,12 @@ class WorkerManager extends Disposable {
}
}
public
withWorker
():
T
Promise
<
EditorWorkerClient
>
{
public
withWorker
():
Promise
<
EditorWorkerClient
>
{
this
.
_lastWorkerUsedTime
=
(
new
Date
()).
getTime
();
if
(
!
this
.
_editorWorkerClient
)
{
this
.
_editorWorkerClient
=
new
EditorWorkerClient
(
this
.
_modelService
,
'
editorWorkerService
'
);
}
return
TPromise
.
as
(
this
.
_editorWorkerClient
);
return
Promise
.
resolve
(
this
.
_editorWorkerClient
);
}
}
...
...
@@ -308,17 +307,17 @@ class EditorModelManager extends Disposable {
}
interface
IWorkerClient
<
T
>
{
getProxyObject
():
T
Promise
<
T
>
;
getProxyObject
():
Promise
<
T
>
;
dispose
():
void
;
}
class
SynchronousWorkerClient
<
T
extends
IDisposable
>
implements
IWorkerClient
<
T
>
{
private
_instance
:
T
;
private
_proxyObj
:
T
Promise
<
T
>
;
private
_proxyObj
:
Promise
<
T
>
;
constructor
(
instance
:
T
)
{
this
.
_instance
=
instance
;
this
.
_proxyObj
=
TPromise
.
as
(
this
.
_instance
);
this
.
_proxyObj
=
Promise
.
resolve
(
this
.
_instance
);
}
public
dispose
():
void
{
...
...
@@ -327,7 +326,7 @@ class SynchronousWorkerClient<T extends IDisposable> implements IWorkerClient<T>
this
.
_proxyObj
=
null
;
}
public
getProxyObject
():
T
Promise
<
T
>
{
public
getProxyObject
():
Promise
<
T
>
{
return
this
.
_proxyObj
;
}
}
...
...
@@ -362,7 +361,7 @@ export class EditorWorkerClient extends Disposable {
return
this
.
_worker
;
}
protected
_getProxy
():
T
Promise
<
EditorSimpleWorkerImpl
>
{
protected
_getProxy
():
Promise
<
EditorSimpleWorkerImpl
>
{
return
this
.
_getOrCreateWorker
().
getProxyObject
().
then
(
null
,
(
err
)
=>
{
logOnceWebWorkerWarning
(
err
);
this
.
_worker
=
new
SynchronousWorkerClient
(
new
EditorSimpleWorkerImpl
(
null
));
...
...
@@ -377,38 +376,38 @@ export class EditorWorkerClient extends Disposable {
return
this
.
_modelManager
;
}
protected
_withSyncedResources
(
resources
:
URI
[]):
T
Promise
<
EditorSimpleWorkerImpl
>
{
protected
_withSyncedResources
(
resources
:
URI
[]):
Promise
<
EditorSimpleWorkerImpl
>
{
return
this
.
_getProxy
().
then
((
proxy
)
=>
{
this
.
_getOrCreateModelManager
(
proxy
).
esureSyncedResources
(
resources
);
return
proxy
;
});
}
public
computeDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
T
Promise
<
editorCommon
.
ILineChange
[]
>
{
public
computeDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
Promise
<
editorCommon
.
ILineChange
[]
>
{
return
this
.
_withSyncedResources
([
original
,
modified
]).
then
(
proxy
=>
{
return
proxy
.
computeDiff
(
original
.
toString
(),
modified
.
toString
(),
ignoreTrimWhitespace
);
});
}
public
computeDirtyDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
T
Promise
<
editorCommon
.
IChange
[]
>
{
public
computeDirtyDiff
(
original
:
URI
,
modified
:
URI
,
ignoreTrimWhitespace
:
boolean
):
Promise
<
editorCommon
.
IChange
[]
>
{
return
this
.
_withSyncedResources
([
original
,
modified
]).
then
(
proxy
=>
{
return
proxy
.
computeDirtyDiff
(
original
.
toString
(),
modified
.
toString
(),
ignoreTrimWhitespace
);
});
}
public
computeMoreMinimalEdits
(
resource
:
URI
,
edits
:
modes
.
TextEdit
[]):
T
Promise
<
modes
.
TextEdit
[]
>
{
public
computeMoreMinimalEdits
(
resource
:
URI
,
edits
:
modes
.
TextEdit
[]):
Promise
<
modes
.
TextEdit
[]
>
{
return
this
.
_withSyncedResources
([
resource
]).
then
(
proxy
=>
{
return
proxy
.
computeMoreMinimalEdits
(
resource
.
toString
(),
edits
);
});
}
public
computeLinks
(
resource
:
URI
):
T
Promise
<
modes
.
ILink
[]
>
{
public
computeLinks
(
resource
:
URI
):
Promise
<
modes
.
ILink
[]
>
{
return
this
.
_withSyncedResources
([
resource
]).
then
(
proxy
=>
{
return
proxy
.
computeLinks
(
resource
.
toString
());
});
}
public
textualSuggest
(
resource
:
URI
,
position
:
IPosition
):
T
Promise
<
modes
.
CompletionList
>
{
public
textualSuggest
(
resource
:
URI
,
position
:
IPosition
):
Promise
<
modes
.
CompletionList
>
{
return
this
.
_withSyncedResources
([
resource
]).
then
(
proxy
=>
{
let
model
=
this
.
_modelService
.
getModel
(
resource
);
if
(
!
model
)
{
...
...
@@ -421,7 +420,7 @@ export class EditorWorkerClient extends Disposable {
});
}
computeWordRanges
(
resource
:
URI
,
range
:
IRange
):
T
Promise
<
{
[
word
:
string
]:
IRange
[]
}
>
{
computeWordRanges
(
resource
:
URI
,
range
:
IRange
):
Promise
<
{
[
word
:
string
]:
IRange
[]
}
>
{
return
this
.
_withSyncedResources
([
resource
]).
then
(
proxy
=>
{
let
model
=
this
.
_modelService
.
getModel
(
resource
);
if
(
!
model
)
{
...
...
@@ -434,7 +433,7 @@ export class EditorWorkerClient extends Disposable {
});
}
public
navigateValueSet
(
resource
:
URI
,
range
:
IRange
,
up
:
boolean
):
T
Promise
<
modes
.
IInplaceReplaceSupportResult
>
{
public
navigateValueSet
(
resource
:
URI
,
range
:
IRange
,
up
:
boolean
):
Promise
<
modes
.
IInplaceReplaceSupportResult
>
{
return
this
.
_withSyncedResources
([
resource
]).
then
(
proxy
=>
{
let
model
=
this
.
_modelService
.
getModel
(
resource
);
if
(
!
model
)
{
...
...
src/vs/editor/common/services/webWorker.ts
浏览文件 @
6daba771
...
...
@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
EditorWorkerClient
}
from
'
vs/editor/common/services/editorWorkerServiceImpl
'
;
...
...
@@ -27,12 +26,12 @@ export interface MonacoWebWorker<T> {
/**
* Get a proxy to the arbitrary loaded code.
*/
getProxy
():
T
Promise
<
T
>
;
getProxy
():
Promise
<
T
>
;
/**
* Synchronize (send) the models at `resources` to the web worker,
* making them available in the monaco.worker.getMirrorModels().
*/
withSyncedResources
(
resources
:
URI
[]):
T
Promise
<
T
>
;
withSyncedResources
(
resources
:
URI
[]):
Promise
<
T
>
;
}
export
interface
IWebWorkerOptions
{
...
...
@@ -55,7 +54,7 @@ class MonacoWebWorkerImpl<T> extends EditorWorkerClient implements MonacoWebWork
private
_foreignModuleId
:
string
;
private
_foreignModuleCreateData
:
any
;
private
_foreignProxy
:
T
Promise
<
T
>
;
private
_foreignProxy
:
Promise
<
T
>
;
constructor
(
modelService
:
IModelService
,
opts
:
IWebWorkerOptions
)
{
super
(
modelService
,
opts
.
label
);
...
...
@@ -64,18 +63,18 @@ class MonacoWebWorkerImpl<T> extends EditorWorkerClient implements MonacoWebWork
this
.
_foreignProxy
=
null
;
}
private
_getForeignProxy
():
T
Promise
<
T
>
{
private
_getForeignProxy
():
Promise
<
T
>
{
if
(
!
this
.
_foreignProxy
)
{
this
.
_foreignProxy
=
this
.
_getProxy
().
then
((
proxy
)
=>
{
return
proxy
.
loadForeignModule
(
this
.
_foreignModuleId
,
this
.
_foreignModuleCreateData
).
then
((
foreignMethods
)
=>
{
this
.
_foreignModuleId
=
null
;
this
.
_foreignModuleCreateData
=
null
;
let
proxyMethodRequest
=
(
method
:
string
,
args
:
any
[]):
T
Promise
<
any
>
=>
{
let
proxyMethodRequest
=
(
method
:
string
,
args
:
any
[]):
Promise
<
any
>
=>
{
return
proxy
.
fmr
(
method
,
args
);
};
let
createProxyMethod
=
(
method
:
string
,
proxyMethodRequest
:
(
method
:
string
,
args
:
any
[])
=>
T
Promise
<
any
>
):
Function
=>
{
let
createProxyMethod
=
(
method
:
string
,
proxyMethodRequest
:
(
method
:
string
,
args
:
any
[])
=>
Promise
<
any
>
):
Function
=>
{
return
function
()
{
let
args
=
Array
.
prototype
.
slice
.
call
(
arguments
,
0
);
return
proxyMethodRequest
(
method
,
args
);
...
...
@@ -94,11 +93,11 @@ class MonacoWebWorkerImpl<T> extends EditorWorkerClient implements MonacoWebWork
return
this
.
_foreignProxy
;
}
public
getProxy
():
T
Promise
<
T
>
{
public
getProxy
():
Promise
<
T
>
{
return
this
.
_getForeignProxy
();
}
public
withSyncedResources
(
resources
:
URI
[]):
T
Promise
<
T
>
{
public
withSyncedResources
(
resources
:
URI
[]):
Promise
<
T
>
{
return
this
.
_withSyncedResources
(
resources
).
then
(
_
=>
this
.
getProxy
());
}
}
src/vs/workbench/parts/output/common/outputLinkComputer.ts
浏览文件 @
6daba771
...
...
@@ -55,7 +55,7 @@ export class OutputLinkComputer {
return
null
;
}
public
computeLinks
(
uri
:
string
):
ILink
[]
{
public
computeLinks
(
uri
:
string
):
Promise
<
ILink
[]
>
{
const
model
=
this
.
getModel
(
uri
);
if
(
!
model
)
{
return
void
0
;
...
...
@@ -81,7 +81,7 @@ export class OutputLinkComputer {
}
});
return
links
;
return
Promise
.
resolve
(
links
)
;
}
public
static
createPatterns
(
workspaceFolder
:
URI
):
RegExp
[]
{
...
...
src/vs/workbench/parts/output/common/outputLinkProvider.ts
浏览文件 @
6daba771
...
...
@@ -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
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
...
...
@@ -75,7 +74,7 @@ export class OutputLinkProvider {
return
this
.
worker
;
}
private
provideLinks
(
modelUri
:
URI
):
T
Promise
<
ILink
[]
>
{
private
provideLinks
(
modelUri
:
URI
):
Promise
<
ILink
[]
>
{
return
this
.
getOrCreateWorker
().
withSyncedResources
([
modelUri
]).
then
(
linkComputer
=>
{
return
linkComputer
.
computeLinks
(
modelUri
.
toString
());
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录