codesnap.nvim icon indicating copy to clipboard operation
codesnap.nvim copied to clipboard

[Feat] adding support to copy to clipboard in WSL

Open jhonnyV-V opened this issue 1 year ago • 21 comments

Add to dependencies to get system info, to check if is wsl and the current pretty name of the distro.

If wsl is getting used, this should create the image as a temp file inside wsl, then use powershell to copy it to the clipboard, and then it deletes the image from the tmp directory.

this is my first time doing rust so sorry if the code does not follow some good practice, I'm open to any kind of feedback, if something needs to be changed to match the standard in the rest of the codebase just leave a comment and I will fix it

jhonnyV-V avatar Apr 11 '24 13:04 jhonnyV-V

Hey @jhonnyV-V, thx for this PR. Can you run CodeSnap.nvim on WSL? there are a few issues describe that they can't run CodeSnap.nvim on WSL, it would be great if you could add some documents for the WSL install/usage guide

mistricky avatar Apr 15 '24 04:04 mistricky

Hi @mistricky, yes I can run it without problems and configuring things inside of WSL, I could give it a try

jhonnyV-V avatar Apr 15 '24 15:04 jhonnyV-V

Hi @jhonnyV-V, is there any update for https://github.com/mistricky/codesnap.nvim/issues/73#issuecomment-2057344317? It seems like not work perfectly.

mistricky avatar May 06 '24 15:05 mistricky

Hi @mistricky I haven't been able to try to tackle this issue, I will try this week, it seems like a rust issue, where rust fails to access the clipboard, I have to test this more,

jhonnyV-V avatar May 06 '24 16:05 jhonnyV-V

WSL's clipboard is tricky. Hopefully this brings some light: https://lib.rs/crates/clipboard-anywhere

mgastonportillo avatar Jun 02 '24 21:06 mgastonportillo

I'll keep an eye on this, I'd love to use this plugin but I primarily work in WSL.

Thanks for the PR!

sarahsturgeon avatar Jun 21 '24 18:06 sarahsturgeon

well I finally had the time to continue, I think this should be working now, the error was a pretty simple thing

@brandonsturgeon @mistricky any feedback is useful, maybe if this works finally #73 could be closed

jhonnyV-V avatar Jun 27 '24 23:06 jhonnyV-V

Nice!

How can I test this on my setup? Do I just point my plugin manager to your fork+branch?

sarahsturgeon avatar Jun 27 '24 23:06 sarahsturgeon

Nice!

How can I test this on my setup? Do I just point my plugin manager to your fork+branch?

yes, that should work

codesnap_0000000000000034

jhonnyV-V avatar Jun 27 '24 23:06 jhonnyV-V

I'm currently fixing a couple of things that were still wrong and could cause issues under some cases, there is a problem and is that detecting how is named the linux distro in the \wsl$ directory is hard, currently I'm relying on a crate to get a couple of good guesses, but if the user changed the name or the name for the distro is different, this could not work, maybe in the future reading this from an env variable could be solution

I'm currently adding a check for this reason to try two options that should be good enough for most cases, and adding some string escaping because it was causing some problems

jhonnyV-V avatar Jun 28 '24 14:06 jhonnyV-V

btw I made some test for the things I added If @mistricky wants I could commit them also, and I could just make early returns if the user is not in wsl

jhonnyV-V avatar Jun 28 '24 15:06 jhonnyV-V

btw I made some test for the things I added If @mistricky wants I could commit them also, and I could just make early returns if the user is not in wsl

Add test cases is really great! Can you add information in README on how to setup CodeSnap on WSL and other important considerations of WSL?

mistricky avatar Jul 01 '24 05:07 mistricky

Hi @jhonnyV-V, I have noticed that you only updated the copy.rs, the copy.rs is used to perform the copy action. If users want to save snapshot in somewhere, the save.rs should be updated.

mistricky avatar Jul 01 '24 05:07 mistricky

@mistricky Hi @mistricky, yes, I only updated the copy.rs, that is the only problem that I found in the plugin with wsl, the save workflow works fine, I could add a small example in the readme of how to store in another disk from wsl

jhonnyV-V avatar Jul 01 '24 14:07 jhonnyV-V

@mistricky Hi @mistricky, yes, I only updated the copy.rs, that is the only problem that I found in the plugin with wsl, the save workflow works fine, I could add a small example in the readme of how to store in another disk from wsl

Hi @jhonnyV-V, thx for ur amazing job! I don't have Windows machine, Can u help test if it works fine on Windows? or can someone help? @brandonsturgeon @mgastonportillo thx guys.

If everything is OK and also there is no further work in this PR, I'll merge it into main branch.

mistricky avatar Jul 02 '24 11:07 mistricky

@mistricky Hi @mistricky, yes, I only updated the copy.rs, that is the only problem that I found in the plugin with wsl, the save workflow works fine, I could add a small example in the readme of how to store in another disk from wsl

Hi @jhonnyV-V, thx for ur amazing job! I don't have Windows machine, Can u help test if it works fine on Windows? or can someone help? @brandonsturgeon @mgastonportillo thx guys.

If everything is OK and also there is no further work in this PR, I'll merge it into main branch.

I tested and it's not working for me. I'll attach a video with the spec and an example of it not working. This is my clipboard config:

if vim.fn.has "wsl" then
  local copy = "clip.exe"
  local paste = 'pwsh.exe -c [Console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))'
  vim.g.clipboard = {
    name = "wslclipboard",
    copy = { ["+"] = copy, ["*"] = copy },
    paste = { ["+"] = paste, ["*"] = paste },
    cache_enabled = 0,
  }
end

And here the video: https://github.com/mistricky/codesnap.nvim/assets/106234166/446737fd-e3df-4473-9862-d753c0da1ad7

And just in case: image

mgastonportillo avatar Jul 02 '24 19:07 mgastonportillo

@mgastonportillo you are right, somehow I managed to break everything by adding the tests, the last working commit is the 3a74e416, I will fix this soon

jhonnyV-V avatar Jul 02 '24 20:07 jhonnyV-V

@mgastonportillo you are right, somehow I managed to break everything by adding the tests, the last working commit is the 3a74e416, I will fix this soon

Would you like me to test again? I just got free

Edit: I tested again around the time I sent this message, pulled the new commits and it wasn't working yet. I assumed it still needs some fixes to be implemented.

If you need me to test again, just let me know and I'll try my best to assist with it.

mgastonportillo avatar Jul 02 '24 21:07 mgastonportillo

Hi @jhonnyV-V, do you have time to take another look at this PR? It seems like there are still few issues

mistricky avatar Aug 07 '24 16:08 mistricky

@mistricky well, sorry for the absence, for reasons I migrated to linux and in a completely unrelated note my windows installation broke so I am not able to keep developing on this, so I will comment on the issues I found and could not really solve in case someone else is able to find the problem and fix this

this should work locally, the issue is for some reason that escaped my comprehension when is installed from a github branch instead of using a path to a directory it will start failing to copy to the clipboard, not really sure what is the actual error, I didn't get to debug this before my windows problem happen, probably the best way to try this is adding a bunch of logging and log all the powershell outputs and commit that, then using that branch with the commit to install the extension

I believe that this could be a problem with permissions, maybe windows does not like when something you downloaded from the internet attempt to execute arbitrary commands on windows from wsl

jhonnyV-V avatar Oct 21 '24 15:10 jhonnyV-V