You can use npiperelay to let coc-discord-rpc connect to a Discord instance running on the host Windows operating system. It requires modifying the extension a bit, but it's relatively painless. This guide assumes you have coc.nvim and coc-discord-rpc already installed.
To build npiperelay, you'll need Go. Grab the golang
package from your favorite package manager and follow the instructions on the
npiperelay repo. You'll also need to install socat
if it doesn't come with your distribution.
To locate the Discord IPC socket, the coc-discord-rpc extension looks in the subdirectory of /tmp/
created for NeoVim when it starts.
Discord, however, puts its IPC in the root of /tmp/
, not a subdirectory. And since we will be starting socat
before NeoVim, we won't be able
to put the forwarded socket in its subdirectory. We have to modify the extension to look in the correct directory. Open the main source file,
which should be located at ~/.config/coc/extensions/node_modules/coc-discord-rpc/lib/index.js
. Search for the function named getIPCPath
.
This function contains a line that sets the path prefix for the IPC socket. It should look something like this:
const prefix = XDG_RUNTIME_DIR || TMPDIR || TMP || TEMP || '/tmp';
Change that line to the following:
const prefix = '/tmp';
Now that the extension is looking in the right place, we have to put an actual IPC socket there. To do so, we need to launch socat
before
NeoVim to forward the Discord IPC named pipe from Windows. You can do this by creating an alias for nvim
that checks if socat
is running
and launches it in the background if it isn't.
I use fish, so my alias looks something like this:
function nvim
pidof socat > /dev/null; or socat UNIX-LISTEN:/tmp/discord-ipc-0,fork \
EXEC:"npiperelay.exe //./pipe/discord-ipc-0"&
command nvim $argv
end
Or in bash:
nvim () {
pidof socat > /dev/null 2>&1
if ! $? -eq 0; then
socat UNIX-LISTEN:/tmp/discord-ipc-0,fork \
EXEC:"npiperelay.exe //./pipe/discord-ipc-0"&
fi
command nvim "$@"
}
And that's it! Running nvim
from your shell of choice should now allow it to connect to the Discord IPC pipe on your host Windows system (as
long as you have Discord running, of course).
Note: Using the fork
option to socat
ensures that you won't get connection errors when running multiple instances of NeoVim. However,
only the first opened instance will be able to provide rich presence. If you decide to try to modify coc-discord-rpc to support multiple
instances of NeoVim, I'd definitely love to hear about it.
We've been looking for a long time if this is possible. Thanks mate! 💗