mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-15 12:51:00 +01:00
fire up extHostDocumentParticipant and vscode.d.ts, #239
This commit is contained in:
Vendored
+51
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user