yegappan / lsp

Language Server Protocol (LSP) plugin for Vim9
MIT License
485 stars 60 forks source link

MSYS/MinGW sends an incorrect processId to the LSP #501

Open zlogic opened 7 months ago

zlogic commented 7 months ago

Most LSP servers (like Eclipse JDT LS) use initparams' processId to check if the parent process is still running.

In MinGW versions of vim (for example, vim shipped with the Windows installer for Git), the getpid() call returns a MinGW-specific PID that doesn't match Windows PIDs.

If the LSP is a Windows executable that's not using MinGW and expects a Windows PID (like Eclipse JDT), it will try to search for a MinGW PID in the Windows process tree and almost always fail. In my case, Eclipse LSP shuts down after ≈ 30 seconds of inactivity, with a Parent process stopped running, forcing server exit message in the logs.

This can be fixed by:

  1. Using a MinGW-based LSP - so that it would search for the parent process in MinGW's own process space
  2. Or using a non-MinGW version of Vim - so that getpid() would return a Windows PID
  3. Or by replacing getpid() in https://github.com/yegappan/lsp/blob/8255965e345c0628036ac7f635cf5784cddec5dd/autoload/lsp/lspserver.vim#L162 with a function that returns a Windows PID, something like this:
    initparams.processId = str2nr(system("ps -p " .. getpid() .. " | awk -v ORS= 'NR ==2{print $4}'"))
zlogic commented 7 months ago

I don't think this is a bug of Vim or the LSP plugin, just wanted to share my (quick) solution to a problem.

Since it's possible that a specific LSP might be be compiled as a MinGW or regular Windows executable, it might make sense to have a way to override initparams.processId per-LSP.