Vim 8 in multiple windows

Hi! I set up rust-analyzer to work with Vim 8, and I'm quite amazed at the features! The problem is that I like being able to spontaneously start new Vim processes in different windows, but I have to wait for rust-analyzer to index my project again in the new window (I have 1517 crates for it to index), which takes at least 10 seconds.

I was wondering if the same instance of rust-analyzer can receive multiple Initialization Requests from different clients but re-use its dependency index? I plan to write a simple python script that serves rust-analyzer over TCP to solve this issue.

Edit: I have my eyes set on either Ale or "vim-lsc" to use as TCP clients. I don't know if they send a new Initialization Request for every connection. The point is that I want to re-use the dependency index.

I believe I'm going to give up this endeavour, but here is what I found out after some experimenting:

  1. LSP is not built to server multiple clients, according to the spec: "The protocol currently assumes that one server serves one tool. There is currently no support in the protocol to share one server between different tools. Such a sharing would require additional protocol e.g. to lock a document to support concurrent editing."
    You could imagine having multiple processes "pretending" to be a single tool, but...

  2. Both vim-lsc and Ale assume that they have singular control over the TCP connection, and send Initialization Requests for each individual process that is started. Sending multiple initialization requests will cause rust analyzer to error out and crash.

Although it is imaginable to automatically detect initialization requests and preventing multiple from being sent, pretending to reply to each process with a cached reply from the first one, I never got that far since although I could intercept the communication between vim-lsc/ale and rust analyzer, and both seemed to communicate without errors, I somehow still couldn't get them to send any requests past the Initialization request. vim-lsc would just not send anything after its Initialization Request, while ale sent its first initialization request, waited for a minute or two, and then sent another initialization request...

For context, I used a simple python script to redirect the TCP requests from the vim plugins to a subprocess running rust analyzer, and replied again using TCP

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.