@@ -1289,17 +1289,11 @@ declare module 'vscode' {
12891289
12901290 //#region Custom editors: https://github.com/microsoft/vscode/issues/77131
12911291
1292- // TODO:
1293- // - Think about where a rename would live.
1294- // - Think about handling go to line? (add other editor options? reveal?)
1295- // - Should we expose edits?
1296- // - More properties from `TextDocument`?
1297-
12981292 /**
12991293 * Defines the editing capability of a custom webview editor. This allows the webview editor to hook into standard
13001294 * editor events such as `undo` or `save`.
13011295 *
1302- * @param EditType Type of edits.
1296+ * @param EditType Type of edits used for the documents this delegate handles .
13031297 */
13041298 interface CustomEditorEditingDelegate < EditType = unknown > {
13051299 /**
@@ -1310,7 +1304,7 @@ declare module 'vscode' {
13101304 *
13111305 * @return Thenable signaling that the save has completed.
13121306 */
1313- save ( document : CustomDocument , cancellation : CancellationToken ) : Thenable < void > ;
1307+ save ( document : CustomDocument < EditType > , cancellation : CancellationToken ) : Thenable < void > ;
13141308
13151309 /**
13161310 * Save the existing resource at a new path.
@@ -1320,7 +1314,7 @@ declare module 'vscode' {
13201314 *
13211315 * @return Thenable signaling that the save has completed.
13221316 */
1323- saveAs ( document : CustomDocument , targetResource : Uri ) : Thenable < void > ;
1317+ saveAs ( document : CustomDocument < EditType > , targetResource : Uri ) : Thenable < void > ;
13241318
13251319 /**
13261320 * Event triggered by extensions to signal to VS Code that an edit has occurred.
@@ -1337,7 +1331,7 @@ declare module 'vscode' {
13371331 *
13381332 * @return Thenable signaling that the change has completed.
13391333 */
1340- applyEdits ( document : CustomDocument , edits : readonly EditType [ ] ) : Thenable < void > ;
1334+ applyEdits ( document : CustomDocument < EditType > , edits : readonly EditType [ ] ) : Thenable < void > ;
13411335
13421336 /**
13431337 * Undo a set of edits.
@@ -1349,7 +1343,7 @@ declare module 'vscode' {
13491343 *
13501344 * @return Thenable signaling that the change has completed.
13511345 */
1352- undoEdits ( document : CustomDocument , edits : readonly EditType [ ] ) : Thenable < void > ;
1346+ undoEdits ( document : CustomDocument < EditType > , edits : readonly EditType [ ] ) : Thenable < void > ;
13531347
13541348 /**
13551349 * Revert the file to its last saved state.
@@ -1359,7 +1353,7 @@ declare module 'vscode' {
13591353 *
13601354 * @return Thenable signaling that the change has completed.
13611355 */
1362- revert ( document : CustomDocument , edits : CustomDocumentRevert < EditType > ) : Thenable < void > ;
1356+ revert ( document : CustomDocument < EditType > , edits : CustomDocumentRevert < EditType > ) : Thenable < void > ;
13631357
13641358 /**
13651359 * Back up the resource in its current state.
@@ -1380,22 +1374,25 @@ declare module 'vscode' {
13801374 * in an operation that takes time to complete, your extension may decide to finish the ongoing backup rather
13811375 * than cancelling it to ensure that VS Code has some valid backup.
13821376 */
1383- backup ( document : CustomDocument , cancellation : CancellationToken ) : Thenable < void > ;
1377+ backup ( document : CustomDocument < EditType > , cancellation : CancellationToken ) : Thenable < void > ;
13841378 }
13851379
13861380 /**
1387- * Event triggered by extensions to signal to VS Code that an edit has occurred on a CustomDocument``.
1381+ * Event triggered by extensions to signal to VS Code that an edit has occurred on a `CustomDocument`.
1382+ *
1383+ * @param EditType Type of edits used for the document.
13881384 */
13891385 interface CustomDocumentEditEvent < EditType = unknown > {
13901386 /**
13911387 * Document the edit is for.
13921388 */
1393- readonly document : CustomDocument ;
1389+ readonly document : CustomDocument < EditType > ;
13941390
13951391 /**
13961392 * Object that describes the edit.
13971393 *
1398- * Edit objects are passed back to your extension in `undoEdits`, `applyEdits`, and `revert`.
1394+ * Edit objects are passed back to your extension in `CustomEditorEditingDelegate.undoEdits`,
1395+ * `CustomEditorEditingDelegate.applyEdits`, and `CustomEditorEditingDelegate.revert`.
13991396 */
14001397 readonly edit : EditType ;
14011398
@@ -1423,13 +1420,19 @@ declare module 'vscode' {
14231420 /**
14241421 * Represents a custom document used by a `CustomEditorProvider`.
14251422 *
1426- * Custom documents are only used within a given `CustomEditorProvider`. The lifecycle of a
1427- * `CustomDocument` is managed by VS Code. When no more references remain to a given `CustomDocument`,
1428- * then it is disposed of.
1423+ * All custom documents must subclass `CustomDocument`. Custom documents are only used within a given
1424+ * `CustomEditorProvider`. The lifecycle of a ` CustomDocument` is managed by VS Code. When no more references
1425+ * remain to a `CustomDocument`, it is disposed of.
14291426 *
1430- * @param UserDataType Type of custom object that extensions can store on the document.
1427+ * @param EditType Type of edits used in this document.
14311428 */
1432- interface CustomDocument < UserDataType = unknown > {
1429+ class CustomDocument < EditType = unknown > {
1430+ /**
1431+ * @param viewType The associated uri for this document.
1432+ * @param uri The associated viewType for this document.
1433+ */
1434+ constructor ( viewType : string , uri : Uri ) ;
1435+
14331436 /**
14341437 * The associated viewType for this document.
14351438 */
@@ -1446,12 +1449,17 @@ declare module 'vscode' {
14461449 readonly onDidDispose : Event < void > ;
14471450
14481451 /**
1449- * Custom data that an extension can store on the document.
1452+ * List of edits from document open to the document's current state .
14501453 */
1451- userData ?: UserDataType ;
1454+ readonly appliedEdits : ReadonlyArray < EditType > ;
14521455
1453- // TODO: Should we expose edits here?
1454- // This could be helpful for tracking the life cycle of edits
1456+ /**
1457+ * List of edits from document open to the document's last saved point.
1458+ *
1459+ * The save point will be behind `appliedEdits` if the user saves and then continues editing,
1460+ * or in front of the last entry in `appliedEdits` if the user saves and then hits undo.
1461+ */
1462+ readonly savedEdits : ReadonlyArray < EditType > ;
14551463 }
14561464
14571465 /**
@@ -1463,7 +1471,8 @@ declare module 'vscode' {
14631471 * You should use custom text based editors when dealing with binary files or more complex scenarios. For simple text
14641472 * based documents, use [`WebviewTextEditorProvider`](#WebviewTextEditorProvider) instead.
14651473 */
1466- export interface CustomEditorProvider {
1474+ export interface CustomEditorProvider < EditType = unknown > {
1475+
14671476 /**
14681477 * Resolve the model for a given resource.
14691478 *
@@ -1472,18 +1481,18 @@ declare module 'vscode' {
14721481 * If all editors for a given resource are closed, the `CustomDocument` is disposed of. Opening an editor at
14731482 * this point will trigger another call to `resolveCustomDocument`.
14741483 *
1475- * @param document Document to resolve .
1484+ * @param uri Uri of the document to open .
14761485 * @param token A cancellation token that indicates the result is no longer needed.
14771486 *
1478- * @return The capabilities of the resolved document.
1487+ * @return The custom document.
14791488 */
1480- resolveCustomDocument ( document : CustomDocument , token : CancellationToken ) : Thenable < void > ; // TODO: rename to open?
1489+ openCustomDocument ( uri : Uri , token : CancellationToken ) : Thenable < CustomDocument < EditType > > ;
14811490
14821491 /**
14831492 * Resolve a webview editor for a given resource.
14841493 *
1485- * This is called when a user first opens a resource for a `CustomTextEditorProvider `, or if they reopen an
1486- * existing editor using this `CustomTextEditorProvider `.
1494+ * This is called when a user first opens a resource for a `CustomEditorProvider `, or if they reopen an
1495+ * existing editor using this `CustomEditorProvider `.
14871496 *
14881497 * To resolve a webview editor, the provider must fill in its initial html content and hook up all
14891498 * the event listeners it is interested it. The provider can also hold onto the `WebviewPanel` to use later,
@@ -1495,14 +1504,14 @@ declare module 'vscode' {
14951504 *
14961505 * @return Thenable indicating that the webview editor has been resolved.
14971506 */
1498- resolveCustomEditor ( document : CustomDocument , webviewPanel : WebviewPanel , token : CancellationToken ) : Thenable < void > ;
1507+ resolveCustomEditor ( document : CustomDocument < EditType > , webviewPanel : WebviewPanel , token : CancellationToken ) : Thenable < void > ;
14991508
15001509 /**
15011510 * Defines the editing capability of a custom webview document.
15021511 *
15031512 * When not provided, the document is considered readonly.
15041513 */
1505- readonly editingDelegate ?: CustomEditorEditingDelegate ;
1514+ readonly editingDelegate ?: CustomEditorEditingDelegate < EditType > ;
15061515 }
15071516
15081517 /**
@@ -1516,6 +1525,7 @@ declare module 'vscode' {
15161525 * For binary files or more specialized use cases, see [CustomEditorProvider](#CustomEditorProvider).
15171526 */
15181527 export interface CustomTextEditorProvider {
1528+
15191529 /**
15201530 * Resolve a webview editor for a given text resource.
15211531 *
@@ -1549,8 +1559,6 @@ declare module 'vscode' {
15491559 * @return Thenable indicating that the webview editor has been moved.
15501560 */
15511561 moveCustomTextEditor ?( newDocument : TextDocument , existingWebviewPanel : WebviewPanel , token : CancellationToken ) : Thenable < void > ;
1552-
1553- // TODO: handlesMove?: boolean;
15541562 }
15551563
15561564 namespace window {
@@ -1560,14 +1568,16 @@ declare module 'vscode' {
15601568 * @param viewType Type of the webview editor provider. This should match the `viewType` from the
15611569 * `package.json` contributions.
15621570 * @param provider Provider that resolves editors.
1563- * @param webviewOptions Content settings for the webview panels that the provider is given.
1571+ * @param options Options for the provider
15641572 *
15651573 * @return Disposable that unregisters the provider.
15661574 */
15671575 export function registerCustomEditorProvider (
15681576 viewType : string ,
15691577 provider : CustomEditorProvider | CustomTextEditorProvider ,
1570- webviewOptions ?: WebviewPanelOptions , // TODO: move this onto provider?
1578+ options ?: {
1579+ readonly webviewOptions ?: WebviewPanelOptions ;
1580+ }
15711581 ) : Disposable ;
15721582 }
15731583
0 commit comments