Commit Graph

60 Commits

Author SHA1 Message Date
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
Matt Bierner
4546a07196 Working on basic save for custom editors 2019-09-13 22:24:35 -07:00
Matt Bierner
54ac29790e Make sure asWebviewUri also handles replacing commit 2019-09-12 16:07:47 -07:00
Matt Bierner
7a219ab632 Adding concept of a state for webview editors
#77131

This information will be used to show the dirty indicator and also enable/disable save
2019-09-12 14:04:54 -07:00
Matt Bierner
011836a150 Prototyping custom editors (#77789)
* Custom Editor exploration

For #77131

Adds a prototype of custom editors contributed by extensions. This change does the following:

- Introduces a new contribution point for the declarative parts of a custom editor
- Adds API for registering a webview editor provider. This lets VS Code decided when to create a webview editor
- Adds an `openWith` command that lets you select which editor to use to open a resource from the file explorer
- Adds a setting that lets you say that you always want to use a custom editor for a given file extension
- Hooks up auto opening of a custom editor when opening a file from quick open or explorer
- Adds a new extension that contributes a custom image preview for png and jpg files

Still needs a lot of UX work and testing. We are also going to explore a more generic "open handler" based approach for supporting custom editors

Revert

* Re-use existing custom editor if one is already open

* Don't re-create custom editor webview when clicking on already visible custom editor

* Move customEditorInput to own file

* First draft of serializing custom editor inputs

* Use glob patterns instead of simple file extensions for matching custom resoruces for custom editors

* Add descriptions

* Try opening standard editor while prompting for custom editor

* Make sure we hide image status on dispose

* Make sure we restore editor group too

* Use glob patterns for workbench.editor.custom

* Allow users to configure custom editors for additional file types

* Use filename glob instead of glob on full resource path

* Adding placeholder for prompt open with

* Add enableByDefault setting for editor contributions

* Enable custom editors by default and add `discretion` enum

Changes `enableByDefault` boolean to a `discretion` enum. This should give more flexibility if we want other options (such as forcing a given custom editor to always be used even if there are other default ones)

* Allow custom editors to specify both a scheme and filenamePattern they are active for

* Rework custom editor setting

* Don't allow custom editors to be enabled for all resources by a config mistake

* Replace built-in image editor with one from extension

* Adding reopen with command

* Improve comment

* Remove commented code

* Localize package.json and remove image

* Remove extra lib setting from tsconfig
2019-09-10 17:56:57 -07:00
Matt Bierner
78879b6a81 Log missing csp on extension host instead of main window 2019-08-26 15:42:16 -07:00
Matt Bierner
4b93194b76 Make sure we notify webview of view state changes in a consistent order
Send events in the following order:
- Non-visible
- Visible
- Active

This matches the old notification order for webviews
2019-08-23 22:27:51 -05:00
Matt Bierner
b1dd95c883 Fire a single batched event internally to update all webview view states
Previously we fired one event per webview. This change switches to fire on event per update
2019-08-20 16:20:42 -07:00
Matt Bierner
5e57212107 Better handle cases where webview view state in api can get out sync with real view state
Fixes #79492

Simplifies view state management logic in `mainThreadWebviews` to:

* Not be stateful
* Handle cases where a webview's view state changes through a more complex means (see #79492 for an example of this)
2019-08-20 15:57:06 -07:00