-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes needed for VSCode webview extension #186
Changes needed for VSCode webview extension #186
Conversation
…ebviewUri" function if it's available The VSCode extension will put this function on "window" when starting the editor, and calling it will return the proper URI to get an asset from the "public" folder.
@@ -76,6 +76,8 @@ input[type='checkbox'] { | |||
|
|||
#app { | |||
position: absolute; | |||
top: 0px; | |||
left: 0px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, in the VSCode webview, #app
was a shifted few pixels to the right which was causing issues like arrows not rendering in the right spot.
Adding this gets it to the right spot, and doesn't seem to have any effect on the web app.
4564968
to
4012451
Compare
src/js/classes/app.js
Outdated
// This should be called whenever we want to mark the document that the VSCcode | ||
// extension has opened as changed. If we're not in the extension, this is a no-op. | ||
// This should be called after every action that will result in a changed text document. | ||
this.updateVsCodeExtensionDocument = function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extension relies on this being called to update its internal document and mark the document as "dirty" so that it can be saved.
I think I got all the places that this needs to be called...
- Node added/removed
- Node dragged
- Node text editor closed
- Node color changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can benefit from this documentIsDirty in the electron version to add an * to the window title after a file has been edited.
Can we perhaps refactor this so yarn in general knows when a document is dirty (when running in electron or vscode).
If not, thats fine :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually can you just rename this function from
this.updateVsCodeExtensionDocument
to
this.setYarnDocumentIsDirty
later on we can use it to handle the electron case
@daviddq do you think it would be a good idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
Okay, I think this is finished! Check out this comment on the other PR for instructions to download/install and test it: YarnSpinnerTool/VSCodeExtension#1 (comment) |
src/js/classes/data.js
Outdated
// if we're editing a file in the VSCode extension, it handles | ||
// saving the file on its end so we do nothing here | ||
return; | ||
} else if (self.editingPath()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the else is redundant here, having that return there will prevent if (self.editingPath() from being evaluated anyway
I gave this a test and am quite impressed. Some notes are due however
Are those thing you need fixing at the other PR? |
Settings: Originally, I had added a bunch of messaging to sync the settings when they're changed in the editor but it ended up being pretty weird; it would create a In the end I opted for just having VSCode handle all the settings and removing the options from the editor altogether. Night mode: If you want to go back to not-night mode (day mode?) there's another option called "Override Dark Theme Night Mode" that you have to turn on. If this is too confusing, it can be removed and just have the user be able to change the setting. Markup language: |
Other stuff seems to be missing too - if thats where you apply it. Can you make sure those work? @daviddq is this right? Should it be applied at another place for those? |
First of all, let me say I find this feature impressively wonderful, @TranquilMarmot. I won't be using anything different but this extension when it's fully ready. Thanks a lot. I tested the extension some commits ago and settings were not fully working. I'll give it a try this afternoon. I find removing the "File/Settings" menu absolutely the way to go inside VSCode.I wish something similar was possible for the "search" box. @blurymind Those settings you mention don't need to be "applied" since they are queried when needed. toogleNightMode() is needed the same way setTheme() is. Nice catch! |
…ranquilmarmot/vscode-yarn-spinner
…ranquilmarmot/vscode-yarn-spinner
Sorry to ask again, but can you update this to the latest version of yarnEditor please? @daviddq fixed a couple of nasty ones |
…ranquilmarmot/vscode-yarn-spinner
@blurymind alright, updated this and the extension PR! |
Do you feel confident this is ready to merge? Testing it, I couldn't find any regressions to Yarn |
I missed your comment about renaming |
Okay @blurymind this should be good to go now! |
Thank you for working on this 👍 Merged now 🎉 |
What is this?
This PR contains changes needed for the VSCode extension to have an embedded webview of the editor.
Checkout out the VSCode extension PR here: YarnSpinnerTool/VSCodeExtension#1
The goal of this PR was to leave the editor intact for current use cases (in-browser app and Electron app) but still allow for it to be embedded in a VSCode webview.
This is my first time working with anything Knockout related, so bear with me! I might have done some silly things.
All in all, it was surprisingly easy to shove this into a VSCode extension. The way that the events and everything are hooked up worked nicely for this use case!
Changes
Assets in the
public
folderFor more info on this read the "Loading local content" section of the VSCode webview docs.
Basically, for security reasons, the webview only has access to specific assets. These specific assets need to be loaded with a URI that is generated by the webview with a scheme of
vscode-resource:
. As you can imagine, there are a lot of hoops to jump through here.As far as this PR is concerned, this means a new function in
Utils
calledgetPublicPath
that can be used to get the path for an asset that would normally be acessible in thepublic
folder. Any assets that were referring topublic
are now piped through this (with the exception of some assets inindex.html
that are find-and-replace'd with the proper URI by the extension when it renders the HTML).localStorage
and settingsAccessing
window.localStorage
at all within a webview will immediately throw an exception and cause the app to stop executing. It will now fake an object with noops for getting/setting values.All settings from inside the extension are instead handled by VSCode's built-in settings mechanisms; see the other PR for more info.
The "Start" node
This one was a bit of a doozy; you'll see that I added in
app.js
:This is for the use case of opening an existing file in VSCode. If opening a file, the extension will set
window.openingVsCodeFile
totrue
so that the "Start" node will not be created.This has to be done because the extension listens for the
yarnReady
and then calls out to (among other things)data.loadData
. At this point,app
would be trying to callworkspace.updateArrows();
but the "Start" node would be null (since we tellloadData
to empty the node list) which would throw an exception and kill the app.