Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork6.5k
-
Hi, and thanks for the work on neovim. I'm an avid user and fully customize my workflow (but still haven't jumped onto nightly) I have some questions regarding the use of neovim as a "remote command handler". This may be a long post but please bear in mind that my aim is to share the pain point I bumped into, how I tackled it and if it's of any use for upstream neovim. This may be related to this issue:Nvim can be a Lua host; Lua plugins can define RPC method/request handlers #31868 My use caseI'm an embedded software developer and work with vendor linux kernel trees and Android checkouts daily. These projects come with a big git history that I often peek into looking for patches or insight. I've been using (vim->neovim) for quite some time and always relied on vim-fugitive for git integration. The problem is that the single-thread nature of vim/nvim results in some git operations to lock up the UI for ~10 secs. I bumped into this every time I attempted to look at the history of a file or a log graph using vim-flog (or GV). I took a stab at my own (lua) replica of the logic found in vim-fugitive to retrieve the commit history of a file and tried to work around the lockup problem. My attempted solutionOf course I wanted to use the nvim API functions and so found that libuv threads were hard for me to use. In the end, and after looking at neovim open issues and how fzf-lua tackled some things, I came up with a module that does the following:
Here's a link to a sequence diagram for graphical illustration (dont know how long this links remains valid for): Something I had to solve was how to pass lua dicts through RPC to the remote instance, in order return the commit history in a more friendly form. I took a cue from fzf-lua and just included the single-file lib "serpent.lua" for serialization and it worked very well. Environment of remote nvim?I rely on my own config being loaded in the remote neovim process for this to work. It feels like cheating. I would like to have the remote neovim spin up with I read#18035 regarding serializing lua functions and it seems very complex for user-setup of lua modules and general environment (but I havent tried it, though). It seems simpler to provide a special RTP path at command-registration time, or something of the like. Questions
I don't know about co-routines in lua but see there's some present work for them. Maybe with coroutes no additional nvim process is needed?
If you read up to this point, thank you! I've been postponing this question almost all year long. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 2 replies
-
Unless you wantstreaming, this already "just works" when you using the RPC API. Or if you want to do things manually you can serialize via
Depends on what you want to do, but you can of course send entire scripts via
Would need to know more specifics about your use-case. There are numerous libraries for structured concurrency discussed in#19624 , but for "slow git" that isn't fundamentally different than using Ifprocessing the git results in Nvim Lua also is slow, then yes, coordinating with a which would enable Lua plugins to be "API clients" easily (likehttps://github.com/neovim/node-client ). |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Hey, thanks for your reply. Yes, processing data in a remote neovim is what I'm doing. The data comes from the The data is just git output text formatted in a similar fashion to what git log --follow --oneline --summary"--pretty=format:\th%H\tp%P\ts%s" -- src/nvim/main.cThis outputs 2 lines per commit (the 2nd line is from --summary, most often empty). This info is needed to track filename/path changes across the git log history. But nevermind my git use-case, this is just an example of the concept of: Can I ask for your opinion on how would the user provide the logic (e.g., the lua implementation) to process the data to the remote neovim? These are my thoughts:
Im already using short snippets of localfunctionsend_request(channel,req)localrpc_args= {pid=req.client_pid,cmd=req.command,user_args=req.extra_args, }returnvim.rpcrequest(channel,'nvim_exec_lua',[[ local args = { ... } local rpc_args = args[1] return require("rcmd.server"):handle_command(rpc_args.pid, rpc_args.cmd, rpc_args.user_args)]], {rpc_args })end And btw,
Thanks, I missed this ! My little test wasn't wrapping the dict in an array and thus errored out. Now I can drop variadic args in the snippets of |
BetaWas this translation helpful?Give feedback.
All reactions
-
A "user config" is just a set of packages (modules), I would not consider it hacky. But just for "science", let's imagine a use-case where one wants to do everything through the same RPC channel, without pre-loading the modules on the remote filesystem. That's somewhat related to the "streaming" topic, which is something we discussed early on#4971 but haven't had much demand for it (though I still consider it in-scope). However, we actually have at least 1 streaming API: Option 1To send an entire set of files (Lua modules or whatever) to a remote system:
Option 2You don't actually need
P.S. We probably should have something for this built-in. It's related to theremote ssh story. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1