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

Percent-encode paths #20

Closed
binEpilo opened this issue Sep 7, 2024 · 12 comments · Fixed by #21
Closed

Percent-encode paths #20

binEpilo opened this issue Sep 7, 2024 · 12 comments · Fixed by #21
Assignees
Labels
enhancement New feature or request

Comments

@binEpilo
Copy link

binEpilo commented Sep 7, 2024

Description

I just added this plugin to my plugins, installed vivify on my arch system (viv --version: vivify-server v0.6.0-1-aur) with yay and with :Vivify firefox opens my file correctly. Still there is one problem: for some reason when I now edit the file with neovim those changes arent automatically shown in the vivify firefox preview: I have to save the file with :w and then reload the page with Ctrl+R. I know that this is definitely user error on my side, but I really dont know what I need to configure here. (I also tried adding the line vim.g.vivify_instant_refresh = 1 to my init.lua)

@tuurep tuurep transferred this issue from jannis-baum/Vivify Sep 7, 2024
@tuurep tuurep added the bug Something isn't working label Sep 7, 2024
@tuurep
Copy link
Collaborator

tuurep commented Sep 7, 2024

Hey I transferred this to the (n)vim plugin's repo

I made sure it works for me with the same package v0.6.0-1-aur and it does

I think the best thing to try at first is to run with a minimal config, using for example this:

https://github.com/neovim/neovim/blob/master/contrib/minimal.lua

To rule out whether it's a config issue or bug

@binEpilo
Copy link
Author

binEpilo commented Sep 7, 2024

With this config it works now. So this is not an issue with vivify, will try to fix the issue now for my config :)

@tuurep
Copy link
Collaborator

tuurep commented Sep 7, 2024

Great, thanks 😄

I am kinda interested in what went wrong so feel free to share if you find out. Or if I can help with something.

@tuurep tuurep removed the bug Something isn't working label Sep 7, 2024
@binEpilo
Copy link
Author

binEpilo commented Sep 7, 2024

I think the issue might be that I am using file names with spaces in them with vivify. While I can open them with :Vivify and they appear in the browsers, vivify doesnt update/refresh them when typing for some reason

@tuurep tuurep added the bug Something isn't working label Sep 7, 2024
@tuurep
Copy link
Collaborator

tuurep commented Sep 7, 2024

Yes, I can reproduce this! Nice find.

@jannis-baum did we have some fix for this that can be used in this plugin's side as well?

@tuurep
Copy link
Collaborator

tuurep commented Sep 7, 2024

Relevant: jannis-baum/Vivify#26

(However filename with for example ä works with instant refresh so this concerns only spaces)

@jannis-baum
Copy link
Owner

Ah, yes, this plugin is not doing the percent-encoding. Have to adjust

https://github.com/jannis-baum/vivify.vim/blob/main/autoload/vivify.vim#L30

and percent-encode the file path. I haven't looked into how to do that with Vimscript.

@jannis-baum jannis-baum changed the title Instant refreshing not working Percent-encode paths Sep 7, 2024
@jannis-baum jannis-baum added enhancement New feature or request and removed bug Something isn't working labels Sep 7, 2024
@jannis-baum
Copy link
Owner

I did a quick search, looks like Vimscript doesn't offer a native way of doing this. So from what I can tell the main options would be:

  1. implement the percent-encoding ourselves in Vimscript, e.g. like this (this example might be a bit more lengthy than it would have to be)
  2. require that Vim is compiled with Python1 for this plugin and use Python's native urllib to do it as a one-liner like this in Vimscript's py3eval function
  3. run sed or awk as a subprocess to do it like this

1 and 3 have wouldn't introduce any new dependency but are slow, 2 is the cleanest but does introduce the Python dependency (although AFAIK it's quite uncommon to have a version of Vim without Python). 1 has the disadvantage of having to implement this ourselves, while 3 has the disadvantage of having to call a subprocess. My preference would be 2. @tuurep what do you think?

Footnotes

  1. You can use vim --version and check that it says +python3 somewhere to verify your Vim was compiled with Python3

@tuurep
Copy link
Collaborator

tuurep commented Sep 9, 2024

Ah, I see

Sounds good to use the python oneliner, apparently it works on neovim too,

But this makes me think about whether I should make a separate vivify.nvim in Lua, in case Lua has a clean way to do the url encoding.

As a bonus, we'd get rid of the ambiguity with for example this vim/nvim difference:

" Note: nvim's jobstart isn't exactly a drop-in replacement for vim's job_start
" See here: https://stackoverflow.com/questions/74999614/difference-between-vims-job-start-function-and-neovims-jobstart-functi

As a more long term idea, do you think I should go for it?

@jannis-baum
Copy link
Owner

I checked and it seemed like Lua doesn't have anything, I only found manual/custom implementations for it.

Anyways, I like that we can maintain and test this plugin together. If we separate Vim and nvim I think I'd be by myself here and also couldn't easily help you with the other one anymore haha. So I'd prefer to keep it as one ^^

@tuurep
Copy link
Collaborator

tuurep commented Sep 9, 2024

only found manual/custom implementations for it.

Yeah, in that case, lets just keep it as one :D

I don't mind installing Vim to test Vim-specific stuff however. But yeah, lets do it that way.

@tuurep tuurep self-assigned this Sep 15, 2024
tuurep added a commit to tuurep/vivify.vim that referenced this issue Sep 16, 2024
The primary intention is to fix the case where filenames have spaces in
them and this plugin doesn't encode the URL properly so it appears as if
vivify can't refresh

We do this whether (n)vim has python3 support or not, but with python3
support do a proper encoding with a library to handle more esoteric
cases, for example curly brackets in filenames.

We found that even without the library, characters such as ä, á, ñ, €
already work, so it's probably a very rare case where you need any more
meticulous encoding for filenames. And then even if that occurs,
enabling python3 support will solve it :)
@tuurep
Copy link
Collaborator

tuurep commented Sep 16, 2024

Hey @binEpilo sorry that this took longer than expected (at least I intended to do it sooner 😄 )

We've solved the spaces-in-filenames issue in #21, feel free to test as well or give feedback!

The way it's done is that if you have python3 support in (n)vim, we do a proper encoding using a library

But if you don't have python3 support that's fine too, in that case we just substitute spaces to %20 for the url. The only downside we ran into with not "encoding properly" was that if we had a file with curly braces in the filename, those wouldn't work.

But enabling python3 will handle cases like that too.

Meaning:

  • Vim needs to be compiled with +python3
  • NeoVim needs pynvim installed
    • (for me on Arch Linux, I needed to install package python-pynvim from pacman repos)

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

Successfully merging a pull request may close this issue.

3 participants