Skip to content
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

[Feat] adding support to copy to clipboard in WSL #83

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

jhonnyV-V
Copy link

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

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 of wsl, then use powershell to copy it to the clipboard and then
it deletes the image from the tmp directory
@mistricky
Copy link
Owner

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

@jhonnyV-V
Copy link
Author

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

@jhonnyV-V jhonnyV-V mentioned this pull request Apr 15, 2024
@mistricky
Copy link
Owner

Hi @jhonnyV-V, is there any update for #73 (comment)? It seems like not work perfectly.

@jhonnyV-V
Copy link
Author

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,

@mgastonportillo
Copy link

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

@brandonsturgeon
Copy link

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

Thanks for the PR!

@jhonnyV-V
Copy link
Author

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

@brandonsturgeon
Copy link

Nice!

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

@jhonnyV-V
Copy link
Author

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
Copy link
Author

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 jhonnyV-V changed the title Adding support to copy to clipboard in wsl DRAFT: Adding support to copy to clipboard in wsl Jun 28, 2024
@jhonnyV-V jhonnyV-V changed the title DRAFT: Adding support to copy to clipboard in wsl Adding support to copy to clipboard in wsl Jun 28, 2024
@jhonnyV-V
Copy link
Author

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

@mistricky
Copy link
Owner

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
Copy link
Owner

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.

@jhonnyV-V
Copy link
Author

@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

@mistricky
Copy link
Owner

@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.

README.md Outdated Show resolved Hide resolved
@mgastonportillo
Copy link

mgastonportillo commented Jul 2, 2024

@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

@jhonnyV-V
Copy link
Author

jhonnyV-V commented Jul 2, 2024

@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

@mgastonportillo
Copy link

mgastonportillo commented Jul 2, 2024

@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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These .so files should not be committed, because them is created by CI, I'll add the them into .gitignore

@mistricky mistricky changed the title Adding support to copy to clipboard in wsl [Feat] adding support to copy to clipboard in WSL Jul 8, 2024
@mistricky mistricky mentioned this pull request Jul 8, 2024
@mistricky
Copy link
Owner

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

@jhonnyV-V
Copy link
Author

jhonnyV-V commented Oct 21, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants