I60R / page

Use neovim as pager
MIT License
207 stars 4 forks source link

Error when opened without existing nvim instance #12

Closed sandersantema closed 4 years ago

sandersantema commented 4 years ago

If I understood correctly I should be able to use page even without an active nvim instance, but this gives me the following error after executing page Cargo.lock (file from the git repo):

thread 'main' panicked at 'Cannot connect to parent neovim: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/libcore/result.rs:1165:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

With env RUST_BACKTRACE=1 page Cargo.lock:

thread 'main' panicked at 'Cannot connect to parent neovim: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/libcore/result.rs:1165:5
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:61
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1028
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:188
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:205
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:464
  11: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:373
  12: rust_begin_unwind
             at src/libstd/panicking.rs:302
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:139
  14: core::result::unwrap_failed
             at src/libcore/result.rs:1165
  15: page::main
  16: std::rt::lang_start::{{closure}}
  17: main
  18: __libc_start_main
  19: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

echo $NVIM_LISTEN_ADDRESS returns /tmp/nvimsocket which I configured for nvr this might have something to do with this error.

env NVIM_LISTEN_ADDRESS= page Cargo.lock opens the file views it for a split second after which only an empty buffer is visible, page outputs /tmp/neovim-page/DO-NOT-REDIRECT-OUTSIDE-OF-NVIM-TERM(--help[-W]) on the command line.

env NVIM_LISTEN_ADDRESS= page -W Cargo.lock gets the same result but without any output on the commandline.

I60R commented 4 years ago

Hello and sorry for delayed feedback

echo $NVIM_LISTEN_ADDRESS returns /tmp/nvimsocket

This is what causes problems: in your case page is trying to connect to neovim server at /tmp/nvimsocket address which doesn't exists.

which I configured for nvr

Does nvr reqire such configuration? I don't understand the purpose of having global $NVIM_LISTEN_ADDRESS variable; as far as I know it should only be exposed under :term shell in order to allow clients like page and nvr to attach to parent neovim process.

Previously it was accepted by neovim to manually set the address on which it will listen to commands, but now this becomes deprecated in favor of --listen option.

That said, you was probably confused by README in neovim-remote repo, and manually setting NVIM_LISTEN_ADDRESS before each nvr invocation is not necessary

sandersantema commented 4 years ago

I understood the purpose of $NVIM_LISTEN_ADDRESS a bit differently (possibly incorrect), as a way to configure nvim to always use the same server address (on which it listens). For instance launching nvim with NVIM_LISTEN_ADDRESS unset: env NVIM_LISTEN_ADDRESS= nvim in nvim :echo v:servername will return /tmp/nvimnWij4Z/0which will be different if I launch nvim again. That way if NVIM_LISTEN_ADDRESS isn't set nvr will not know which socket to send stuff to if I understood correctly.

But it seems like --listen is the actual option I should use and nvr seems to work perfect with that.

I tried page in the nvim terminal after launching nvim with env NVIM_LISTEN_ADDRESS= nvim --listen /tmp/nvimsocket. Page does seems to work as a manpage for instance but without any colored text and after opening nvim focuses on another split, i.e. I have to splits open one with nothing in it and the other a terminal after opening something with page my cursor is in the window with nothing in it.

So irregardless of what NVIM_LISTEN_ADDRESS is set to or if it is even set to something, something seems to go wrong with page for me.

sandersantema commented 4 years ago

Is it clear what exactly the bug is or do you still need more info? Is this bug you reported the cause?

I60R commented 4 years ago

For instance launching nvim with NVIM_LISTEN_ADDRESS unset: env NVIM_LISTEN_ADDRESS= nvim in nvim :echo v:servername will return /tmp/nvimnWij4Z/0which will be different if I launch nvim again.

That's right. But if you further launch :term and run echo $NVIM_LISTEN_ADDRESS on it then you will find that NVIM_LISTEN_ADDRESS is set and it's the same as v:servername value.

Here you can use page and nvr and they should connect to parent neovim process just fine without any /tmp/nvimsocket tweaks.

And yes, NVIM_LISTEN_ADDRESS has two purposes, that's confusing, and that's why they introduced --listen instead of one of them.

That way if NVIM_LISTEN_ADDRESS isn't set nvr will not know which socket to send stuff to if I understood correctly.

If it isn't set then both page and nvr will launch a new neovim process and will use it. Again, /tmp/nvimsocket in this case isn't required.

Having global NVIM_LISTEN_ADDRESS might have sense only if you want to keep a singe system-wide neovim instance that would be used by various clients like page and nvr from different terminals. For me this setup feels completely broken, so I don't see any sense in setting global NVIM_LISTEN_ADDRESS or in using --listen option. It probably was put in neovim-remote README only to explain how things work under the hood but this turned out to be only confusing for users.

after opening nvim focuses on another split, i.e. I have to splits open one with nothing in it and the other a terminal after opening something with page my cursor is in the window with nothing in it.

This is the bug and I've reported and I've fixed it already. Fix will be included in the next version of page which I hope to release soon (maybe even today)