Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e9a9f991
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,发现更多精彩内容 >>
提交
e9a9f991
编写于
4月 10, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
debt - split extHostOutputService
上级
8863cdb1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
209 addition
and
182 deletion
+209
-182
src/vs/workbench/api/common/extHostOutput.ts
src/vs/workbench/api/common/extHostOutput.ts
+186
-0
src/vs/workbench/api/node/extHost.api.impl.ts
src/vs/workbench/api/node/extHost.api.impl.ts
+3
-2
src/vs/workbench/api/node/extHostOutputService.ts
src/vs/workbench/api/node/extHostOutputService.ts
+20
-180
未找到文件。
src/vs/workbench/api/common/extHostOutput.ts
0 → 100644
浏览文件 @
e9a9f991
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
MainContext
,
MainThreadOutputServiceShape
,
IMainContext
,
ExtHostOutputServiceShape
}
from
'
./extHost.protocol
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
Disposable
,
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
export
abstract
class
AbstractExtHostOutputChannel
extends
Disposable
implements
vscode
.
OutputChannel
{
readonly
_id
:
Promise
<
string
>
;
private
readonly
_name
:
string
;
protected
readonly
_proxy
:
MainThreadOutputServiceShape
;
private
_disposed
:
boolean
;
private
_offset
:
number
;
protected
readonly
_onDidAppend
:
Emitter
<
void
>
=
this
.
_register
(
new
Emitter
<
void
>
());
readonly
onDidAppend
:
Event
<
void
>
=
this
.
_onDidAppend
.
event
;
constructor
(
name
:
string
,
log
:
boolean
,
file
:
URI
|
undefined
,
proxy
:
MainThreadOutputServiceShape
)
{
super
();
this
.
_name
=
name
;
this
.
_proxy
=
proxy
;
this
.
_id
=
proxy
.
$register
(
this
.
name
,
log
,
file
);
this
.
_offset
=
0
;
}
get
name
():
string
{
return
this
.
_name
;
}
append
(
value
:
string
):
void
{
this
.
validate
();
this
.
_offset
+=
value
?
Buffer
.
from
(
value
).
byteLength
:
0
;
}
update
():
void
{
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$update
(
id
));
}
appendLine
(
value
:
string
):
void
{
this
.
validate
();
this
.
append
(
value
+
'
\n
'
);
}
clear
():
void
{
this
.
validate
();
const
till
=
this
.
_offset
;
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$clear
(
id
,
till
));
}
show
(
columnOrPreserveFocus
?:
vscode
.
ViewColumn
|
boolean
,
preserveFocus
?:
boolean
):
void
{
this
.
validate
();
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$reveal
(
id
,
!!
(
typeof
columnOrPreserveFocus
===
'
boolean
'
?
columnOrPreserveFocus
:
preserveFocus
)));
}
hide
():
void
{
this
.
validate
();
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$close
(
id
));
}
protected
validate
():
void
{
if
(
this
.
_disposed
)
{
throw
new
Error
(
'
Channel has been closed
'
);
}
}
dispose
():
void
{
super
.
dispose
();
if
(
!
this
.
_disposed
)
{
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$dispose
(
id
))
.
then
(()
=>
this
.
_disposed
=
true
);
}
}
}
export
class
ExtHostPushOutputChannel
extends
AbstractExtHostOutputChannel
{
constructor
(
name
:
string
,
proxy
:
MainThreadOutputServiceShape
)
{
super
(
name
,
false
,
undefined
,
proxy
);
}
append
(
value
:
string
):
void
{
super
.
append
(
value
);
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$append
(
id
,
value
));
this
.
_onDidAppend
.
fire
();
}
}
class
ExtHostLogFileOutputChannel
extends
AbstractExtHostOutputChannel
{
constructor
(
name
:
string
,
file
:
URI
,
proxy
:
MainThreadOutputServiceShape
)
{
super
(
name
,
true
,
file
,
proxy
);
}
append
(
value
:
string
):
void
{
throw
new
Error
(
'
Not supported
'
);
}
}
export
interface
IOutputChannelFactory
{
createOutputChannel
(
name
:
string
,
logsLocation
:
URI
,
proxy
:
MainThreadOutputServiceShape
):
Promise
<
AbstractExtHostOutputChannel
>
;
}
export
const
PushOutputChannelFactory
=
new
class
implements
IOutputChannelFactory
{
async
createOutputChannel
(
name
:
string
,
_logsLocation
:
URI
,
proxy
:
MainThreadOutputServiceShape
):
Promise
<
AbstractExtHostOutputChannel
>
{
return
new
ExtHostPushOutputChannel
(
name
,
proxy
);
}
};
export
class
ExtHostOutputService
implements
ExtHostOutputServiceShape
{
private
readonly
_factory
:
IOutputChannelFactory
;
private
readonly
_logsLocation
:
URI
;
private
readonly
_proxy
:
MainThreadOutputServiceShape
;
private
readonly
_channels
:
Map
<
string
,
AbstractExtHostOutputChannel
>
=
new
Map
<
string
,
AbstractExtHostOutputChannel
>
();
private
_visibleChannelDisposable
:
IDisposable
;
constructor
(
factory
:
IOutputChannelFactory
,
logsLocation
:
URI
,
mainContext
:
IMainContext
)
{
this
.
_factory
=
factory
;
this
.
_logsLocation
=
logsLocation
;
this
.
_proxy
=
mainContext
.
getProxy
(
MainContext
.
MainThreadOutputService
);
}
$setVisibleChannel
(
channelId
:
string
):
void
{
if
(
this
.
_visibleChannelDisposable
)
{
this
.
_visibleChannelDisposable
=
dispose
(
this
.
_visibleChannelDisposable
);
}
if
(
channelId
)
{
const
channel
=
this
.
_channels
.
get
(
channelId
);
if
(
channel
)
{
this
.
_visibleChannelDisposable
=
channel
.
onDidAppend
(()
=>
channel
.
update
());
}
}
}
createOutputChannel
(
name
:
string
):
vscode
.
OutputChannel
{
name
=
name
.
trim
();
if
(
!
name
)
{
throw
new
Error
(
'
illegal argument `name`. must not be falsy
'
);
}
else
{
const
extHostOutputChannel
=
this
.
_factory
.
createOutputChannel
(
name
,
this
.
_logsLocation
,
this
.
_proxy
);
extHostOutputChannel
.
then
(
channel
=>
channel
.
_id
.
then
(
id
=>
this
.
_channels
.
set
(
id
,
channel
)));
return
{
get
name
():
string
{
return
name
;
},
append
(
value
:
string
):
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
append
(
value
));
},
appendLine
(
value
:
string
):
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
appendLine
(
value
));
},
clear
():
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
clear
());
},
show
(
columnOrPreserveFocus
?:
vscode
.
ViewColumn
|
boolean
,
preserveFocus
?:
boolean
):
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
show
(
columnOrPreserveFocus
,
preserveFocus
));
},
hide
():
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
hide
());
},
dispose
():
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
dispose
());
}
};
}
}
createOutputChannelFromLogFile
(
name
:
string
,
file
:
URI
):
vscode
.
OutputChannel
{
name
=
name
.
trim
();
if
(
!
name
)
{
throw
new
Error
(
'
illegal argument `name`. must not be falsy
'
);
}
if
(
!
file
)
{
throw
new
Error
(
'
illegal argument `file`. must not be falsy
'
);
}
return
new
ExtHostLogFileOutputChannel
(
name
,
file
,
this
.
_proxy
);
}
}
src/vs/workbench/api/node/extHost.api.impl.ts
浏览文件 @
e9a9f991
...
...
@@ -39,7 +39,8 @@ import { ExtHostLanguageFeatures, ISchemeTransformer } from 'vs/workbench/api/co
import
{
ExtHostLanguages
}
from
'
vs/workbench/api/common/extHostLanguages
'
;
import
{
ExtHostLogService
}
from
'
vs/workbench/api/node/extHostLogService
'
;
import
{
ExtHostMessageService
}
from
'
vs/workbench/api/common/extHostMessageService
'
;
import
{
ExtHostOutputService
}
from
'
vs/workbench/api/node/extHostOutputService
'
;
import
{
ExtHostOutputService
}
from
'
vs/workbench/api/common/extHostOutput
'
;
import
{
LogOutputChannelFactory
}
from
'
vs/workbench/api/node/extHostOutputService
'
;
import
{
ExtHostProgress
}
from
'
vs/workbench/api/common/extHostProgress
'
;
import
{
ExtHostQuickOpen
}
from
'
vs/workbench/api/common/extHostQuickOpen
'
;
import
{
ExtHostSCM
}
from
'
vs/workbench/api/common/extHostSCM
'
;
...
...
@@ -122,7 +123,7 @@ export function createApiFactory(
const
extHostWindow
=
rpcProtocol
.
set
(
ExtHostContext
.
ExtHostWindow
,
new
ExtHostWindow
(
rpcProtocol
));
rpcProtocol
.
set
(
ExtHostContext
.
ExtHostExtensionService
,
extensionService
);
const
extHostProgress
=
rpcProtocol
.
set
(
ExtHostContext
.
ExtHostProgress
,
new
ExtHostProgress
(
rpcProtocol
.
getProxy
(
MainContext
.
MainThreadProgress
)));
const
extHostOutputService
=
rpcProtocol
.
set
(
ExtHostContext
.
ExtHostOutputService
,
new
ExtHostOutputService
(
initData
.
logsLocation
,
rpcProtocol
));
const
extHostOutputService
=
rpcProtocol
.
set
(
ExtHostContext
.
ExtHostOutputService
,
new
ExtHostOutputService
(
LogOutputChannelFactory
,
initData
.
logsLocation
,
rpcProtocol
));
rpcProtocol
.
set
(
ExtHostContext
.
ExtHostStorage
,
extHostStorage
);
if
(
initData
.
remoteAuthority
)
{
const
cliServer
=
new
CLIServer
(
extHostCommands
);
...
...
src/vs/workbench/api/node/extHostOutputService.ts
浏览文件 @
e9a9f991
...
...
@@ -3,101 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
Main
Context
,
MainThreadOutputServiceShape
,
IMainContext
,
ExtHost
OutputServiceShape
}
from
'
../common/extHost.protocol
'
;
import
{
Main
Thread
OutputServiceShape
}
from
'
../common/extHost.protocol
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
join
}
from
'
vs/base/common/path
'
;
import
{
OutputAppender
}
from
'
vs/workbench/services/output/node/outputAppender
'
;
import
{
toLocalISOString
}
from
'
vs/base/common/date
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
Disposable
,
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
dirExists
,
mkdirp
}
from
'
vs/base/node/pfs
'
;
import
{
AbstractExtHostOutputChannel
,
IOutputChannelFactory
,
ExtHostPushOutputChannel
}
from
'
vs/workbench/api/common/extHostOutput
'
;
abstract
class
AbstractExtHostOutputChannel
extends
Disposable
implements
vscode
.
OutputChannel
{
readonly
_id
:
Promise
<
string
>
;
private
readonly
_name
:
string
;
protected
readonly
_proxy
:
MainThreadOutputServiceShape
;
private
_disposed
:
boolean
;
private
_offset
:
number
;
protected
readonly
_onDidAppend
:
Emitter
<
void
>
=
this
.
_register
(
new
Emitter
<
void
>
());
readonly
onDidAppend
:
Event
<
void
>
=
this
.
_onDidAppend
.
event
;
constructor
(
name
:
string
,
log
:
boolean
,
file
:
URI
|
undefined
,
proxy
:
MainThreadOutputServiceShape
)
{
super
();
this
.
_name
=
name
;
this
.
_proxy
=
proxy
;
this
.
_id
=
proxy
.
$register
(
this
.
name
,
log
,
file
);
this
.
_offset
=
0
;
}
get
name
():
string
{
return
this
.
_name
;
}
append
(
value
:
string
):
void
{
this
.
validate
();
this
.
_offset
+=
value
?
Buffer
.
from
(
value
).
byteLength
:
0
;
}
update
():
void
{
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$update
(
id
));
}
appendLine
(
value
:
string
):
void
{
this
.
validate
();
this
.
append
(
value
+
'
\n
'
);
}
clear
():
void
{
this
.
validate
();
const
till
=
this
.
_offset
;
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$clear
(
id
,
till
));
}
show
(
columnOrPreserveFocus
?:
vscode
.
ViewColumn
|
boolean
,
preserveFocus
?:
boolean
):
void
{
this
.
validate
();
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$reveal
(
id
,
!!
(
typeof
columnOrPreserveFocus
===
'
boolean
'
?
columnOrPreserveFocus
:
preserveFocus
)));
}
hide
():
void
{
this
.
validate
();
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$close
(
id
));
}
protected
validate
():
void
{
if
(
this
.
_disposed
)
{
throw
new
Error
(
'
Channel has been closed
'
);
}
}
dispose
():
void
{
super
.
dispose
();
if
(
!
this
.
_disposed
)
{
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$dispose
(
id
))
.
then
(()
=>
this
.
_disposed
=
true
);
}
}
}
class
ExtHostPushOutputChannel
extends
AbstractExtHostOutputChannel
{
constructor
(
name
:
string
,
proxy
:
MainThreadOutputServiceShape
)
{
super
(
name
,
false
,
undefined
,
proxy
);
}
append
(
value
:
string
):
void
{
super
.
append
(
value
);
this
.
_id
.
then
(
id
=>
this
.
_proxy
.
$append
(
id
,
value
));
this
.
_onDidAppend
.
fire
();
}
}
class
ExtHostOutputChannelBackedByFile
extends
AbstractExtHostOutputChannel
{
export
class
ExtHostOutputChannelBackedByFile
extends
AbstractExtHostOutputChannel
{
private
_appender
:
OutputAppender
;
...
...
@@ -128,98 +43,23 @@ class ExtHostOutputChannelBackedByFile extends AbstractExtHostOutputChannel {
}
}
class
ExtHostLogFileOutputChannel
extends
AbstractExtHostOutputChannel
{
constructor
(
name
:
string
,
file
:
URI
,
proxy
:
MainThreadOutputServiceShape
)
{
super
(
name
,
true
,
file
,
proxy
);
}
append
(
value
:
string
):
void
{
throw
new
Error
(
'
Not supported
'
);
}
}
let
namePool
=
1
;
async
function
createExtHostOutputChannel
(
name
:
string
,
outputDirPromise
:
Promise
<
string
>
,
proxy
:
MainThreadOutputServiceShape
):
Promise
<
AbstractExtHostOutputChannel
>
{
try
{
const
outputDir
=
await
outputDirPromise
;
const
fileName
=
`
${
namePool
++
}
-
${
name
}
`
;
const
file
=
URI
.
file
(
join
(
outputDir
,
`
${
fileName
}
.log`
));
const
appender
=
new
OutputAppender
(
fileName
,
file
.
fsPath
);
return
new
ExtHostOutputChannelBackedByFile
(
name
,
appender
,
proxy
);
}
catch
(
error
)
{
// Do not crash if logger cannot be created
console
.
log
(
error
);
return
new
ExtHostPushOutputChannel
(
name
,
proxy
);
}
}
export
class
ExtHostOutputService
implements
ExtHostOutputServiceShape
{
private
readonly
_outputDir
:
Promise
<
string
>
;
private
_proxy
:
MainThreadOutputServiceShape
;
private
_channels
:
Map
<
string
,
AbstractExtHostOutputChannel
>
=
new
Map
<
string
,
AbstractExtHostOutputChannel
>
();
private
_visibleChannelDisposable
:
IDisposable
;
constructor
(
logsLocation
:
URI
,
mainContext
:
IMainContext
)
{
const
outputDirPath
=
join
(
logsLocation
.
fsPath
,
`output_logging_
${
toLocalISOString
(
new
Date
()).
replace
(
/-|:|
\.\d
+Z$/g
,
''
)}
`
);
this
.
_outputDir
=
dirExists
(
outputDirPath
).
then
(
exists
=>
exists
?
exists
:
mkdirp
(
outputDirPath
).
then
(()
=>
true
)).
then
(()
=>
outputDirPath
);
this
.
_proxy
=
mainContext
.
getProxy
(
MainContext
.
MainThreadOutputService
);
}
$setVisibleChannel
(
channelId
:
string
):
void
{
if
(
this
.
_visibleChannelDisposable
)
{
this
.
_visibleChannelDisposable
=
dispose
(
this
.
_visibleChannelDisposable
);
}
if
(
channelId
)
{
const
channel
=
this
.
_channels
.
get
(
channelId
);
if
(
channel
)
{
this
.
_visibleChannelDisposable
=
channel
.
onDidAppend
(()
=>
channel
.
update
());
}
export
const
LogOutputChannelFactory
=
new
class
implements
IOutputChannelFactory
{
_namePool
=
1
;
async
createOutputChannel
(
name
:
string
,
logsLocation
:
URI
,
proxy
:
MainThreadOutputServiceShape
):
Promise
<
AbstractExtHostOutputChannel
>
{
try
{
const
outputDirPath
=
join
(
logsLocation
.
fsPath
,
`output_logging_
${
toLocalISOString
(
new
Date
()).
replace
(
/-|:|
\.\d
+Z$/g
,
''
)}
`
);
const
outputDir
=
await
dirExists
(
outputDirPath
).
then
(
exists
=>
exists
?
exists
:
mkdirp
(
outputDirPath
).
then
(()
=>
true
)).
then
(()
=>
outputDirPath
);
const
fileName
=
`
${
this
.
_namePool
++
}
-
${
name
}
`
;
const
file
=
URI
.
file
(
join
(
outputDir
,
`
${
fileName
}
.log`
));
const
appender
=
new
OutputAppender
(
fileName
,
file
.
fsPath
);
return
new
ExtHostOutputChannelBackedByFile
(
name
,
appender
,
proxy
);
}
catch
(
error
)
{
// Do not crash if logger cannot be created
console
.
log
(
error
);
return
new
ExtHostPushOutputChannel
(
name
,
proxy
);
}
}
};
createOutputChannel
(
name
:
string
):
vscode
.
OutputChannel
{
name
=
name
.
trim
();
if
(
!
name
)
{
throw
new
Error
(
'
illegal argument `name`. must not be falsy
'
);
}
else
{
const
extHostOutputChannel
=
createExtHostOutputChannel
(
name
,
this
.
_outputDir
,
this
.
_proxy
);
extHostOutputChannel
.
then
(
channel
=>
channel
.
_id
.
then
(
id
=>
this
.
_channels
.
set
(
id
,
channel
)));
return
{
get
name
():
string
{
return
name
;
},
append
(
value
:
string
):
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
append
(
value
));
},
appendLine
(
value
:
string
):
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
appendLine
(
value
));
},
clear
():
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
clear
());
},
show
(
columnOrPreserveFocus
?:
vscode
.
ViewColumn
|
boolean
,
preserveFocus
?:
boolean
):
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
show
(
columnOrPreserveFocus
,
preserveFocus
));
},
hide
():
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
hide
());
},
dispose
():
void
{
extHostOutputChannel
.
then
(
channel
=>
channel
.
dispose
());
}
};
}
}
createOutputChannelFromLogFile
(
name
:
string
,
file
:
URI
):
vscode
.
OutputChannel
{
name
=
name
.
trim
();
if
(
!
name
)
{
throw
new
Error
(
'
illegal argument `name`. must not be falsy
'
);
}
if
(
!
file
)
{
throw
new
Error
(
'
illegal argument `file`. must not be falsy
'
);
}
return
new
ExtHostLogFileOutputChannel
(
name
,
file
,
this
.
_proxy
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录