Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
53ff2cf4
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
53ff2cf4
编写于
9月 22, 2016
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fire up extHostDocumentParticipant and vscode.d.ts, #239
上级
e61e74f5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
61 addition
and
11 deletion
+61
-11
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+51
-0
src/vs/workbench/api/node/extHost.api.impl.ts
src/vs/workbench/api/node/extHost.api.impl.ts
+4
-1
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
+2
-6
src/vs/workbench/test/node/api/extHostDocumentSaveParticipant.test.ts
...ench/test/node/api/extHostDocumentSaveParticipant.test.ts
+4
-4
未找到文件。
src/vs/vscode.d.ts
浏览文件 @
53ff2cf4
...
...
@@ -3557,6 +3557,52 @@ declare namespace vscode {
contentChanges
:
TextDocumentContentChangeEvent
[];
}
/**
* An event that is fired when a [document](#TextDocument) will be saved.
*
* To make modifications to the document before it is being saved, call the
* [`waitUntil`](#TextDocumentWillSaveEvent.waitUntil)-function with a thenable
* that resolves to an array of [text edits](#TextEdit).
*/
export
interface
TextDocumentWillSaveEvent
{
/**
* The document that will be saved.
*/
document
:
vscode
.
TextDocument
;
/**
* Allows to pause the event loop and to apply [pre-save-edits](#TextEdit).
* Edits of subsequent calls to this function will be applied in order. The
* edits will be *ignored* if concurrent modifications of the document happened.
*
* *Note:* This function can only be called during event dispatch and not
* in an asynchronous manner:
*
* ```ts
* workspace.onWillSaveTextDocument(event => {
// async, will *throw* an error
setTimeout(() => event.waitUntil(promise));
// sync, OK
* event.waitUntil(promise);
* })
* ```
*
* @param thenable A thenable that resolves to [pre-save-edits](#TextEdit).
*/
waitUntil
(
thenable
:
Thenable
<
vscode
.
TextEdit
[]
>
):
void
;
/**
* Allows to pause the event loop until the provided thenable resolved.
*
* *Note:* This function can only be called during event dispatch.
*
* @param thenable A thenable that delays saving.
*/
waitUntil
(
thenable
:
Thenable
<
any
>
):
void
;
}
/**
* Namespace for dealing with the current workspace. A workspace is the representation
* of the folder that has been opened. There is no workspace when just a file but not a
...
...
@@ -3692,6 +3738,11 @@ declare namespace vscode {
*/
export
const
onDidChangeTextDocument
:
Event
<
TextDocumentChangeEvent
>
;
/**
* An event that is emitted when a [text document](#TextDocument) will be saved to disk.
*/
export
const
onWillSaveTextDocument
:
Event
<
TextDocumentWillSaveEvent
>
;
/**
* An event that is emitted when a [text document](#TextDocument) is saved to disk.
*/
...
...
src/vs/workbench/api/node/extHost.api.impl.ts
浏览文件 @
53ff2cf4
...
...
@@ -103,6 +103,7 @@ export class ExtHostAPIImplementation {
const
extHostHeapMonitor
=
col
.
define
(
ExtHostContext
.
ExtHostHeapService
).
set
<
ExtHostHeapService
>
(
new
ExtHostHeapService
());
const
extHostDocuments
=
col
.
define
(
ExtHostContext
.
ExtHostDocuments
).
set
<
ExtHostDocuments
>
(
new
ExtHostDocuments
(
threadService
));
const
estHostDocumentSaveParticipant
=
col
.
define
(
ExtHostContext
.
ExtHostDocumentSaveParticipant
).
set
<
ExtHostDocumentSaveParticipant
>
(
new
ExtHostDocumentSaveParticipant
(
extHostDocuments
,
threadService
.
get
(
MainContext
.
MainThreadWorkspace
)));
const
extHostEditors
=
col
.
define
(
ExtHostContext
.
ExtHostEditors
).
set
<
ExtHostEditors
>
(
new
ExtHostEditors
(
threadService
,
extHostDocuments
));
const
extHostCommands
=
col
.
define
(
ExtHostContext
.
ExtHostCommands
).
set
<
ExtHostCommands
>
(
new
ExtHostCommands
(
threadService
,
extHostEditors
));
const
extHostConfiguration
=
col
.
define
(
ExtHostContext
.
ExtHostConfiguration
).
set
<
ExtHostConfiguration
>
(
new
ExtHostConfiguration
(
threadService
.
get
(
MainContext
.
MainThreadConfiguration
)));
...
...
@@ -111,7 +112,6 @@ export class ExtHostAPIImplementation {
const
extHostFileSystemEvent
=
col
.
define
(
ExtHostContext
.
ExtHostFileSystemEventService
).
set
<
ExtHostFileSystemEventService
>
(
new
ExtHostFileSystemEventService
());
const
extHostQuickOpen
=
col
.
define
(
ExtHostContext
.
ExtHostQuickOpen
).
set
<
ExtHostQuickOpen
>
(
new
ExtHostQuickOpen
(
threadService
));
const
extHostTerminalService
=
col
.
define
(
ExtHostContext
.
ExtHostTerminalService
).
set
<
ExtHostTerminalService
>
(
new
ExtHostTerminalService
(
threadService
));
col
.
define
(
ExtHostContext
.
ExtHostDocumentSaveParticipant
).
set
<
ExtHostDocumentSaveParticipant
>
(
new
ExtHostDocumentSaveParticipant
(
extHostDocuments
,
threadService
.
get
(
MainContext
.
MainThreadWorkspace
)));
col
.
define
(
ExtHostContext
.
ExtHostExtensionService
).
set
(
extensionService
);
col
.
finish
(
false
,
threadService
);
...
...
@@ -325,6 +325,9 @@ export class ExtHostAPIImplementation {
onDidSaveTextDocument
:
(
listener
,
thisArgs
?,
disposables
?)
=>
{
return
extHostDocuments
.
onDidSaveDocument
(
listener
,
thisArgs
,
disposables
);
},
onWillSaveTextDocument
:
(
listener
,
thisArgs
?,
disposables
?)
=>
{
return
estHostDocumentSaveParticipant
.
onWillSaveTextDocumentEvent
(
listener
,
thisArgs
,
disposables
);
},
onDidChangeConfiguration
:
(
listener
:
()
=>
any
,
thisArgs
?:
any
,
disposables
?:
extHostTypes
.
Disposable
[])
=>
{
return
extHostConfiguration
.
onDidChangeConfiguration
(
listener
,
thisArgs
,
disposables
);
},
...
...
src/vs/workbench/api/node/extHostDocumentSaveParticipant.ts
浏览文件 @
53ff2cf4
...
...
@@ -16,10 +16,6 @@ import {fromRange} from 'vs/workbench/api/node/extHostTypeConverters';
import
{
IResourceEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
import
{
ExtHostDocuments
}
from
'
vs/workbench/api/node/extHostDocuments
'
;
export
interface
TextDocumentWillSaveEvent
{
document
:
vscode
.
TextDocument
;
waitUntil
(
t
:
Thenable
<
any
|
vscode
.
TextEdit
[]
>
):
void
;
}
export
class
ExtHostDocumentSaveParticipant
extends
ExtHostDocumentSaveParticipantShape
{
...
...
@@ -37,7 +33,7 @@ export class ExtHostDocumentSaveParticipant extends ExtHostDocumentSaveParticipa
this
.
_callbacks
.
dispose
();
}
get
onWillSaveTextDocumentEvent
():
Event
<
TextDocumentWillSaveEvent
>
{
get
onWillSaveTextDocumentEvent
():
Event
<
vscode
.
TextDocumentWillSaveEvent
>
{
return
(
listener
,
thisArg
,
disposables
)
=>
{
this
.
_callbacks
.
add
(
listener
,
thisArg
);
const
result
=
{
dispose
:
()
=>
this
.
_callbacks
.
remove
(
listener
,
thisArg
)
};
...
...
@@ -65,7 +61,7 @@ export class ExtHostDocumentSaveParticipant extends ExtHostDocumentSaveParticipa
const
{
version
}
=
document
;
const
event
=
Object
.
freeze
(
<
TextDocumentWillSaveEvent
>
{
const
event
=
Object
.
freeze
(
<
vscode
.
TextDocumentWillSaveEvent
>
{
document
,
waitUntil
(
p
:
Thenable
<
any
|
vscode
.
TextEdit
[]
>
)
{
if
(
Object
.
isFrozen
(
promises
))
{
...
...
src/vs/workbench/test/node/api/extHostDocumentSaveParticipant.test.ts
浏览文件 @
53ff2cf4
...
...
@@ -10,7 +10,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
import
{
ExtHostDocuments
}
from
'
vs/workbench/api/node/extHostDocuments
'
;
import
{
TextEdit
,
Position
}
from
'
vs/workbench/api/node/extHostTypes
'
;
import
{
MainThreadWorkspaceShape
}
from
'
vs/workbench/api/node/extHost.protocol
'
;
import
{
ExtHostDocumentSaveParticipant
,
TextDocumentWillSaveEvent
}
from
'
vs/workbench/api/node/extHostDocumentSaveParticipant
'
;
import
{
ExtHostDocumentSaveParticipant
}
from
'
vs/workbench/api/node/extHostDocumentSaveParticipant
'
;
import
{
OneGetThreadService
}
from
'
./testThreadService
'
;
import
*
as
EditorCommon
from
'
vs/editor/common/editorCommon
'
;
import
{
IResourceEdit
}
from
'
vs/editor/common/services/bulkEdit
'
;
...
...
@@ -52,7 +52,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
test
(
'
event delivery
'
,
()
=>
{
const
participant
=
new
ExtHostDocumentSaveParticipant
(
documents
,
workspace
);
let
event
:
TextDocumentWillSaveEvent
;
let
event
:
vscode
.
TextDocumentWillSaveEvent
;
let
sub
=
participant
.
onWillSaveTextDocumentEvent
(
function
(
e
)
{
event
=
e
;
});
...
...
@@ -68,7 +68,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
test
(
'
event delivery, immutable
'
,
()
=>
{
const
participant
=
new
ExtHostDocumentSaveParticipant
(
documents
,
workspace
);
let
event
:
TextDocumentWillSaveEvent
;
let
event
:
vscode
.
TextDocumentWillSaveEvent
;
let
sub
=
participant
.
onWillSaveTextDocumentEvent
(
function
(
e
)
{
event
=
e
;
});
...
...
@@ -145,7 +145,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
e
.
waitUntil
(
TPromise
.
wrapError
(
'
dddd
'
));
});
let
event
:
TextDocumentWillSaveEvent
;
let
event
:
vscode
.
TextDocumentWillSaveEvent
;
let
sub2
=
participant
.
onWillSaveTextDocumentEvent
(
function
(
e
)
{
event
=
e
;
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录