Commit Graph

81 Commits

Author SHA1 Message Date
Matt Bierner
4fd7f660a4 Move webview views into own ext host class
Also fixes message passing for webview views
2020-08-20 16:45:45 -07:00
Matt Bierner
61f799f53b Add proposed webview view API (#104601)
Add proposed webview view API

For #46585

This adds a new `WebviewView` proposed api to VS Code that lets webview be used inside views. Webview views can be contributed using a contribution point such as :

```json
    "views": {
      "explorer": [
        {
          "type": "webview",
          "id": "cats.cat",
          "name": "Cats",
          "visibility": "visible"
        }
      ]
    },
```

* Use proper activation event

* Transparent background

* Fix resize observer

* Adding documentation

* Move webview view to new directory under workbench

* Remove resolver

By moving the webviews view into their own fodler, I was able to avoid the cycle the resolver was originally introduced for

* Use enum in more places

* Hook up title and visible properties for webview views

* Remove test view

* Prefer Thenable

* Add unknown view type error to collector
2020-08-20 13:59:22 -07:00
Johannes Rieken
43184b2bed add storageUri and globalStorageUri to ExtensionContext, https://github.com/microsoft/vscode/issues/101857 2020-07-09 12:48:03 +02:00
Matt Bierner
6fd6910527 Don't try getting a storage root for non-editable custom documents 2020-06-10 16:44:10 -07:00
Matt Bierner
50f907f0ba Add more strict typing for webview options
We can only send URI components over from the extension host to the renderer process. Make sure the typings reflect that

Follow up on #98746
2020-05-30 11:03:18 -07:00
Matt Bierner
4862602c4c Align custom editor API proposal with notebook API
Fixes #95854
Fixes #95849
For #77131

- Move all editing functionality back onto the provider. This better matches the notebook API.

- Rename `CustomEditorProvider` to `CustomReadonlyEditorProvider`.  `CustomEditorProvider` is now how editable custom editors are implemented

- Give extension a full suggested backup path instead of just a folder
2020-04-24 14:47:08 -07:00
Matt Bierner
f35758ab21 Rename supportsMultipleEditorsPerResource -> supportsMultipleEditorsPerDocument
For #77131
2020-04-23 17:33:06 -07:00
Matt Bierner
e0a4eec778 Rename some custom editor types/functions and introduce backup context
Fixes #95846
Fixes #95851
For #77131

- Rename `EditableCustomDocument` to `CustomEditableDocument`
- Rename `CustomDocumentBackup.dispose` to `CustomDocumentBackup.delete` to make it clearer how this is supposed to be used
- Rename `OpenCustomDocumentContext` to `CustomDocumentOpenContext`
- Add a context to backup. Pass in `workspaceStorageUri`
2020-04-23 16:32:56 -07:00
Matt Bierner
5913061e1b Allow a custom editor to opt out of supporting multiple instances for a single resource
#77131
2020-04-16 17:40:20 -07:00
Matt Bierner
5426f5ff70 Add CustomDocumentContentChangeEvent
For #77131

- Rename `onDidEdit` to `onDidChange`
- Allow custom editors to fire a `CustomDocumentContentChangeEvent` that only marks the editor as dirty but does not enable undo/redo. The only way for editor to get out of this dirty state is to either save or revert the file
2020-04-16 17:40:20 -07:00
Matt Bierner
d4ce7148dd New custom editor API proposal
For #77131

Fixes #93963
Fixes #94515
Fixes #94517
Fixes #94527
Fixes #94509
Fixes #94514
Fixes #93996
Fixes #93913

This removes explicit edits from the API and reshapes the API to more closely match VS Code's internal API. The change also tries to better express the lifecycle of backups
2020-04-08 17:53:39 -07:00
Matt Bierner
bd6ad5592f Check in saveAs cancellation 2020-04-01 17:22:37 -07:00
Matt Bierner
d41997790c Remove CustomDocument.viewType
Fixes #93867
For #77131

This property is no longer needed (or very helpful) with the current api design
2020-03-31 12:00:17 -07:00
Matt Bierner
f62784d7ac use private fields for webview panel
From #93608
2020-03-27 14:31:12 -07:00
Matt Bierner
2977047ebe Use private fields for most webview properties
#93608
2020-03-27 14:31:12 -07:00
Matt Bierner
ebb2030e1d Fixing some index bugs with edits api for custom editors 2020-03-23 14:54:47 -07:00
Matt Bierner
579dab3196 Update custom editor api
For #77131

- Use a class for `CustomDocument` instead of an interface. Extensions can now add their own data to a `CustomDocument` by sublassing

- Renamed `resolveCustomDocument` to `openCustomDocument` and require that extensions return a `CustomDocument`

- Exposed edits on `CustomDocument`

- Made the third parameter of `registerCustomEditorProvider` a generic options bag that takes a `webviewOptions`
2020-03-23 13:10:49 -07:00
Matt Bierner
7f6f3c28a6 Add cancellation parameter to custom editor resolve methods
Adds placeholder cancellation arguments to the custom editor api. These requests are currently never cancelled
2020-03-16 20:15:57 -07:00
Matt Bierner
041a5907b1 Add experimental moveCustomTextEditor hook
For #77131

Adds a hook that lets extensions preserve the webview for a custom editor across a rename
2020-03-13 17:49:52 -07:00
Matt Bierner
9dae408dc3 Switch webview api back to use delegate model
For #77131

Going back the the delegate based model for a few reasons:

- It gives us a better approach to add additional API hooks in the future (such as for rename)

- In practive, the capabilities were almost always the same as the `userData` on the document. It is rather confusing to have both `userData` and the capabilities 'on' the document
2020-03-12 16:54:48 -07:00
Matt Bierner
3ef02fe7b0 Use the UndoRedoService for CustomEditors (#92408)
* Use the UndoRedoService for CustomEditors

For #90110

Changes custom editors (the ones not based on text) to use the UndoRedoService. This involved:

- Moving edit lifecycle back into the main process again (this is actually the bulk of the changes)
- Removing the `undo`/`redo` methods on  `CustomEditorModel`
- Using the undoRedoService to trigger undo/redo
2020-03-12 11:34:40 -07:00
Matt Bierner
033a5d476f Add a revert method for custom editors
Fixes #91700
For #77131

Having an explicit revert method is a helpful signal that the extension should reload the changes from disk
2020-03-09 15:47:14 -07:00
Matt Bierner
077cd38d26 Add cancellation on CustomEditor.save
For #91702
2020-03-04 15:49:10 -08:00
Matt Bierner
44c76bd3b9 Rework management of custom editor custom models
Fixes #91670

- Move model type logic out of `CustomEditorInput` and into two different implementations of `ICustomEditorModel`
- Add `CustomTextEditorModel` that owns a proper model reference to a text document. This should ensure the text document is disposed of if there are no more references to it
- Move most of the previous `CustomEditorModel` into `mainThreadWebviews` directly. This removes some of the indirection that was previously required (such as using `waitUntil`)
2020-03-02 20:27:06 -08:00
Matt Bierner
4b046579d8 Using private fields for more in extHostWebviews 2020-02-28 14:45:35 -08:00
Matt Bierner
8ef18acdaf Don't require return value backup
Fixes #91703

All custom editors should implement backup or throw an exception if they cannot for some reason.
2020-02-27 11:55:39 -08:00
Matt Bierner
9d06f1bdd1 Better encapsulation of CustomDocument
- Prefer using private fields
- Explicitly mark internal hook method and prefix them with _
- Renaming
2020-02-26 10:59:36 -08:00
Matt Bierner
dc1e7871b8 Rename custom editor contribution point
Renaming to match new API proposal
2020-02-25 10:55:41 -08:00
Matt Bierner
8291f8c152 Polishing of custom editor api proposal for 1.43 release
For #77131
2020-02-25 10:55:41 -08:00
Matt Bierner
915089a8aa Fix silly error with toString for custom editors
Fixes #91317
2020-02-24 15:58:47 -08:00
Matt Bierner
99d5733e5f New iteration of webview editor API proposal
For #77131

**Motivation**
While our existing webview editor API proposal more or less works, building an editable webview editor is fairly tricky using it! This is especially true for simple text based editors.

It'd also be nice if we could get bi-directional live editing for text files. For example, if I open the same file in a webview editor and in VS Code's normal editor, edits on either side should be reflected in the other. While this can sort of be implemented using the existing API, it has some big limitations

**Overview of changes**
To address these problems, we've decided have two types of webview editors:

- Text based webview editors. These editors used a `TextDocument` as their data model, which considerably simplifies implementing an editable webview. In almost all cases, this should be what you use for text files

- Complex webview editors. This is basically the existing proposed API. This gives extension hooks into all the VS Code events, such as `save`, `undo`, and so on. These should be used for binary files or in very complex text editor cases.

Both editor types now have an explicit model layer based on documents. Text editor use `TextDocument` for this, while custom editors use `WebviewEditorCustomDocument`. This replaces the delegate based approach previously used.
2020-02-21 16:26:01 -08:00
Matt Bierner
adff1db8de Use deprecation service to report usage of vscode-resource uris 2020-02-20 21:33:55 -08:00
Matt Bierner
f3dbcea32a Adds a backup method (#88948)
Adds a backup method to the custom editor API proposal. This method allows custom editors to hook in to VS Code's hot exit behavior

If `backup` is not implemented, VS Code will assume that the custom editor cannot be hot exited.

When `backup` is implemented, VS Code will invoke the method after every edit (this is debounced). At this point, this extension should back up the current resource.  The result is a promise indicating if the backup was successful or not

VS Code will only hot exit if all backups were successful.
2020-01-23 16:14:27 -08:00
Matt Bierner
ff9fd2fa1a Custom Editors: pass original edit objects back to extensions
For #88719

With this change, instead of passing custom editor edit json back and forth with the extension host, we keep the original edit objects on the extension host. This means that we can pass extensions back the exact same edit object they first hand to us. It also means that edits no longer need to be json serializable.
2020-01-19 20:14:25 -08:00
Matt Bierner
1b70625f8c Use import type when importing vscode under src
When the core references `vscode`, we only want to import the types and never generate a real import (which will fail to load). Use `import type` to better enforce this
2020-01-10 14:25:21 -08:00
Matt Bierner
8e475f9b24 Implement draft 2 from #86802 (#87117) 2019-12-16 14:18:58 -08:00
Matt Bierner
e3fb9ceca1 Use single editable capability 2019-12-02 13:35:36 -08:00
Matt Bierner
e33be1b0af Explicitly register for save and saveAs 2019-12-02 13:35:35 -08:00
Matt Bierner
85d3ccfb9e Fix custom editor redo 2019-11-25 15:44:25 -08:00
Matt Bierner
750f28769d Sync custom editor edits
If multiple instances of the same  custom editor are opened for the same resource, the edit stack should be shared between them. This matches how we work with text files
2019-11-25 15:44:25 -08:00
Matt Bierner
f3d70dbf92 Working on sharing models for same custom editor 2019-11-25 15:44:25 -08:00
Matt Bierner
ffe3749d5a Working on hooking up custom editor saveAs 2019-11-25 15:44:25 -08:00
Matt Bierner
e4fc57dcd2 Don't convert json edit data tostring 2019-11-21 20:09:56 -08:00
Matt Bierner
7d120c2d3e Use chaining 2019-11-21 20:09:56 -08:00
Matt Bierner
8bbe3157f0 Trying to hook up basic save for custom editors 2019-11-18 11:27:45 -08:00
Matt Bierner
27a33ee6fe Hook up very basic undo/redo for webview editors
For #77131
2019-11-15 18:21:46 -08:00
Matt Bierner
fe7e4b231b Use log service instead of console.log in extHostwebview
For #84283
2019-11-12 23:00:29 -08:00
Matt Bierner
64489f331b Webview strict init #78168 2019-11-11 10:06:15 -08:00
Matt Bierner
278b4f8cfa Hookup experimental undo for customEditors
This currently is not connected to any actual actions in the editor
2019-11-07 17:22:21 -08:00
Matt Bierner
454eed71c2 💄 2019-11-07 15:57:47 -08:00