-
Notifications
You must be signed in to change notification settings - Fork 42
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
Copy to and paste from system clipboard #260
Copy to and paste from system clipboard #260
Conversation
Hey @karlhorky - you might want to experiment with running this on top of the changes from #259 which upgrade the dependencies. I found that upgrading fixed some of the async weirdness i was experiencing with my work on the |
Ping @aioutecism @jackfranklin, could this PR be reviewed? |
@alisonatwork Thanks for the heads up. Depending on the feedback to both of the PRs, maybe it will make sense to rebase on your changes. |
Hey there @aioutecism @jackfranklin, would you have a chance to take a look at this soon? |
Hi @karlhorky I just had a first look at the code in this PR, and it seems okay to me on the face of it. To make it a bit easier to manage, could you rebase and force push the branch? Second question, did you attempt to write a test for this yet? I'm not sure if it's easy to do with the existing test setup, but it would be cool if you could preload the clipboard and config and run something like the Regarding your promise problem, I see what you mean by the awkward looking callback. It also makes the diff a bit ugly, having to indent everything. I tried to play around with the order of the code and came up with something like this: // snip
if (Configuration.useSystemClipboard === true) {
return env.clipboard
.readText()
.then((result) => {
// ...
return Promise.resolve(ActionRegister.stash);
})
.then((stash) => this._putAfter(args, activeTextEditor, stash));
}
return this._putAfter(args, activeTextEditor, ActionRegister.stash);
}
private static _putAfter(args, activeTextEditor, stash): Thenable<boolean> {
if (!stash) {
return Promise.resolve(false);
}
// snip This structure would retain most of the indentation from before because it just refactors most of the method into another private method, and it avoids the case where you need to check |
Looking back at that code snippet i just posted, perhaps it could be simplified to just |
Rebased + force pushed. Now looking into the other feedback... |
Just looked into it now. It seems like it needs some more plumbing to do this... right now none of the configuration options have test coverage. We do however know that it is not causing a regression with the normal clipboard mode (not using the system clipboard), due to the non-option tests. |
So in 4dd608a I changed the type of actions to also include Promises (instead of Thenables, which don't allow for async methods), and the code is very clean now. I would suggest iteratively rewriting methods to async/await when they are being worked on, there's a lot of I found this reference back in 2015 to async/await in VS Code extensions, so I guess compatibility is fine as it is? I also tested it out in my VS Code by hot-patching my live extensions folder, and it works :) |
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.
Thanks for updating the PR @karlhorky! Using async/await makes the diff much cleaner. I have given it some manual testing on my machine trying a bunch of different ways to break it and so far so good. It's unfortunate we can't easily write an automated test for this, but I'm happy to merge this now and iterate as needed.
Great, sounds good. Automated testing for options would be a cool thing, maybe I should make an issue for it? |
Yep, if this is something you'd like to take a look at, that would be great! |
Nice, opened #271 for the test. And... oops, forgot to add documentation for this option. Opened #272 for this. Thanks @alisonatwork ! |
Okay, my first try to implement this feature of copying to and pasting from the system clipboard!
Not sure if this is what you meant @aioutecism. Happy to take feedback and improve this still!
I tried changing from
Thenable
toPromise
to allow forasync
methods onputAfter
andputBefore
so that there's not this.then()
callback hell, but I guess async methods are not supported? Anyway, would love to do this a better way if possible.This will not overwrite the stash register in case:
Closes #17
Closes #166