GithubHelp home page GithubHelp logo

Comments (20)

jinzhongjia avatar jinzhongjia commented on August 25, 2024 1

This can effectively divide some tasks into additional processes. Exposing additional unixsockets or sockets and named pipes to the outside world, which is not safe in my opinion.

from znvim.

jinzhongjia avatar jinzhongjia commented on August 25, 2024 1

If this is the case, then using restapi is indeed the best solution

from znvim.

jinzhongjia avatar jinzhongjia commented on August 25, 2024

In theory, this is possible, but you probably need to use Lua as the callback of the key mapping to pass the message to Zig

from znvim.

jinzhongjia avatar jinzhongjia commented on August 25, 2024

Can you explain in detail your specific demand scenario?

from znvim.

ziontee113 avatar ziontee113 commented on August 25, 2024

Thank you for responding. Let's imagine this scenario:

  1. I open a Neovim session with a named pipe: nvim --listen ./nvim.pipe
  2. I press a keymap in Neovim, let's say <C-S-o>.
  3. My already running Zig application receives the signal and connect to that particular Neovim instance.

I could maybe implement a simple REST API in Zig to listen to calls from Neovim. But I'm wondering if there's a more efficient way to achieve the same thing.
Thank you very much.

from znvim.

jinzhongjia avatar jinzhongjia commented on August 25, 2024

If you just start a zig instance to connect to neovim, most current solutions start external programs as sub-processes, and use the stdio of the sub-process for communication.

from znvim.

ziontee113 avatar ziontee113 commented on August 25, 2024

I used to do the same thing when I was working with Go.
I would set up a REST API, and Neovim just use curl to send JSON payload to the REST end point.

from znvim.

jinzhongjia avatar jinzhongjia commented on August 25, 2024

For example, coc.nvim, it starts a child process to communicate with it

from znvim.

jinzhongjia avatar jinzhongjia commented on August 25, 2024

In short, all kinds of neovim remote clients need to connect to neovim through stdio or named pipe or socket.

from znvim.

ziontee113 avatar ziontee113 commented on August 25, 2024

For example, coc.nvim, it starts a child process to communicate with it

Thank you. I'm still very confused of how it works but I'll look into it 👍

from znvim.

jinzhongjia avatar jinzhongjia commented on August 25, 2024

The channels supported by neovim include socket, named pipe, or stdio (start a child process and directly use the stdio of the child process to communicate with it)
The communication protocol can optionally use the msgpackrpc protocol.

from znvim.

jinzhongjia avatar jinzhongjia commented on August 25, 2024

https://neovim.io/doc/user/api.html#rpc-connecting
https://neovim.io/doc/user/channel.html#channel-intro

from znvim.

ziontee113 avatar ziontee113 commented on August 25, 2024

Would that work if the user start nvim regularly in a terminal or in tmux? 🤔

from znvim.

ziontee113 avatar ziontee113 commented on August 25, 2024

Since in this case the terminal / tmux spawns the nvim process, not our Zig program.

from znvim.

jinzhongjia avatar jinzhongjia commented on August 25, 2024

Of course it can run normally, you just need to let neovim's configuration file actively start a jobstart.

from znvim.

jinzhongjia avatar jinzhongjia commented on August 25, 2024

Of course, maintaining an additional restapi as you mentioned before is also a solution.

from znvim.

jinzhongjia avatar jinzhongjia commented on August 25, 2024

When started as a child process, the zig instance will be in the same life cycle as neovim

from znvim.

ziontee113 avatar ziontee113 commented on August 25, 2024

When started as a child process, the zig instance will be in the same life cycle as neovim

Ah... so something like coc.nvim was started as child process, from Neovim, via jobstart.
However, I'm trying to connect to a Zig daemon that's already running 🤔, kinda like Emacs.
So.... I think the REST API might be the way to go.. Since spawning a big heavy GUI program every time Neovim is opened seems undesirable.

from znvim.

ziontee113 avatar ziontee113 commented on August 25, 2024

However, security is a concern, since I'd have to expose a named pipe / port 🤔

from znvim.

ziontee113 avatar ziontee113 commented on August 25, 2024

Thank you so much for all the answers. 🙏
I'll go with the restapi solution.

from znvim.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.