Commit Graph

68 Commits

Author SHA1 Message Date
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
Matt Bierner
bca7206f59 Forward onEdit from webviewEditor to mainthread 2019-11-07 15:57:47 -08:00
Matt Bierner
dcecb9eea6 Documenting thoughts on direction for custom editor API
This documents the current thinking on the custom editor api. The current api proposal is not actually implemented yet
2019-11-04 15:11:54 -08:00
Matt Bierner
d6ab43118d Create WebviewExtensionDescription in extHostProtocol 2019-10-17 10:50:34 -07:00
Matt Bierner
721886ce10 Allow registerWebviewEditorProvider to pass in a set of initial webview options
Fixes #82128
2019-10-17 10:50:34 -07:00
Matt Bierner
31506b5899 Remove old portMapping api conversion logic 2019-10-15 11:31:25 -07:00
Matt Bierner
d4cebcd450 Move filling in of default localResourceRoots into extHost
The main VS Code process should not need to know about the default values for `localResourceRoots`. Leave this up to the extension instead
2019-10-15 11:31:25 -07:00
Matt Bierner
48195455a1 Remove the setExtension helper
Instead pass over the extension when resolving the extension itself
2019-10-15 11:31:24 -07:00
Matt Bierner
6fdd8d10dc Fixing strict init errors in webview code
#78168
2019-10-07 16:38:17 -07:00
Matt Bierner
313ede61cb Also remove extHostWebview side of the api proposal for webview editor state/save 2019-09-30 20:36:21 -07:00
Matt Bierner
e904a5f646 Warn development webview extensions that use vscode-resource uris directly
Fixes #81685
2019-09-30 14:22:47 -07:00
Matt Bierner
e0762af258 Move webview content state into webviewPanel instead of webviewEditor
Split out from #77131

The current webview editor api is very procedural. This model has some problems when it comes to supporting editing resources, but actually does make a lot of sense for webviews that aren't backed by real file system resources. For example, if you have a webview that edits some document in the cloud, you should not be required to implement a custom file system provider just to enable basic saving.

This change moves the `onWillSave` and `webviewEditorState` properties back onto `WebviewPanel` instead of keeping them specific to `WebviewEditor`. The save implementation does not fully work yet, as the will require #81521
2019-09-26 18:05:37 -07:00
Matt Bierner
0506f7f736 Make sure image views (and custom editors) work properly on the web
This fixes an issue where webviews for custom editors did not have any associated extension information, which caused them try reading `file:` uri resources instead of remote uri resources
2019-09-25 16:25:39 -07:00
Matt Bierner
1ee616d802 Don't duplicate external webview commit in so many places 2019-09-16 14:19:16 -07:00