kevinhwang91 / rnvimr

Make Ranger running in a floating window to communicate with Neovim via RPC
BSD 3-Clause "New" or "Revised" License
804 stars 17 forks source link

confdir is not writeable #80

Closed danbst closed 3 years ago

danbst commented 3 years ago

Describe the bug When using Nix as a package manager for this plugin, --confdir refers to path /ranger relative to plugin source code (https://github.com/kevinhwang91/rnvimr/blob/bf7d787d0dd4522bcd411f126bb05eb8bb50d4b2/autoload/rnvimr.vim#L2).

However Nix sets plugin source as readonly, so ranger crashes on start

--confdir is not writable: /nix/store/l8a2hp02cmpj2nzw8bg0bqs6minc5il5-vimplugin-rnvimr-2021-04-01/share/vim-plugins/rnvimr/ranger    

 [Process exited 1]                                                                                                              

To Reproduce using nvim -u mini.vim Remount rnvimr plugin source as readonly, maybe?

Additional context I've hotpatched this issue with

        sed -i "/let s:confdir = s:rnvimr_path/a let s:confdir = '~/.config/ranger'" autoload/rnvimr.vim

and ranger started working on toggle. I've used ~/.config/ranger here, but I'm not sure it is correct.

kevinhwang91 commented 3 years ago

https://github.com/ranger/ranger/pull/2301

rnvimr mock a plugin in ranger. I'm thinking how to solve this issue.

kevinhwang91 commented 3 years ago

Please try copy-confdir branch:) If this works for you, be careful with the synchronization issue for updating rnvimr repo.

You must reboot nvim. Fortunately, rnvimr as a plugin isn't updated frequently by users.

danbst commented 3 years ago

@kevinhwang91 I've tried, it didn't work, but that is because hardlink was created to read-only directory image

danbst commented 3 years ago

actually, I was wrong. It is just that directory is not writeable

[danbst@station:~]$ ls -la /tmp/nvimNQWRoo/rnvimr
total 0
dr-xr-xr-x 3 danbst users  60 кві 16 17:21 .
drwx------ 4 danbst users  80 кві 16 17:29 ..
dr-xr-xr-x 3 danbst users 220 кві 16 17:21 plugins

so it requires chmod +w

kevinhwang91 commented 3 years ago

Yes, does it work after +w?

danbst commented 3 years ago

@kevinhwang91 yes, it launches ranger after that on toggle!

(though it does not work as intended afterward, I'm working on that

health#rnvimr#check
========================================================================
## OS
  - OK: Name: Linux

## Ranger
  - OK: Version: ranger 1.9.3

## Python
  - OK: Version: 3.8.3 (default, May 13 2020, 19:59:26) [GCC 9.3.0]

## Pynvim
  - ERROR: Pynvim is not found in Python Lib

## Ueberzug (optional)
  - WARNING: Ueberzug is not found in Python Lib

## RPC
  - ERROR: RPC: timeout 3s
  - ERROR: Vim(call):E900: Invalid channel id

)

kevinhwang91 commented 3 years ago

Where are the path of your pynvim and ranger? It seems that it can't be import via python3 -c "import pynvim; v = pynvim.VERSION; print(v.major, v.minor, v.patch, sep=\".\", end=\"\")"

danbst commented 3 years ago

Yes, that doesn't work, because my system python doesn't have pynvim package. OTOH, my neovim python does have this module:

$ nvim -u NONE --headless -c "py3 import pynvim; print(pynvim.VERSION)" -cq
Version(major=0, minor=4, patch=2, prerelease='')

Path for pynvim is /nix/store/75pzqpmch8wfbp8jxpgfbxmvr01xqxqq-python3.8-pynvim-0.4.2 Path for ranger is /home/danbst/.nix-profile/bin/ranger

kevinhwang91 commented 3 years ago

Please install pynvim under your python system and try again. I have no idea how to solve the python env......

danbst commented 3 years ago

I fixed the python PATH problem! Hooray!

Even though healthcheck still says all is bad (btw it also uses --confdir from readonly location), AttachFile works and rnvimr is now able to speak ranger <-> nvim!

danbst commented 3 years ago

Okay, for future Nix users, here is vim plugin defintion. It depends on copy-confdir branch of this repo

with pkgs;
let
    rnvimr = let
      # convert ranger to Python module, so it can be used in Neovim python env
      # Also, make pynvim visible there
      ranger_rnvimr = pkgs.python3Packages.toPythonModule (pkgs.ranger.overrideAttrs (old: {
        propagatedBuildInputs = old.propagatedBuildInputs ++ [ pkgs.python3Packages.pynvim ];
      }));
    in vimUtils.buildVimPluginFrom2Nix {
      pname = "rnvimr";
      version = "2021-04-01";
      patchPhase = ''
        sed -i "s|let s:default_ranger_cmd = 'ranger'|let s:default_ranger_cmd = '${ranger_rnvimr}/bin/ranger'|" \
           autoload/rnvimr.vim
      '';
      src = fetchFromGitHub {
        owner = "kevinhwang91";
        repo = "rnvimr";
        rev = "0575979";
        hash = "sha256-JCXGbvfzg9PLe0c9IQp20aBHdzQTlv+snyqatL/RZb0=";
      };
      passthru.python3Dependencies = p: [ ranger_rnvimr ];
      passthru.ranger_rnvimr = ranger_rnvimr;
    };

  neovim = pkgs.neovim.override {
    withPython = false; # actually means withPython2, and we need only python3
    configure = {
      packages.myVimPackage = {
        start = [
          rnvimr
        ];
        opt = [];
      };
    };
  };
kevinhwang91 commented 3 years ago

Is it working now? I will merge copy-confdir into the main branch.

danbst commented 3 years ago

@kevinhwang91 yes, works perfectly.

kevinhwang91 commented 3 years ago

Now the main branch should work.