neovim / node-client

Nvim Node.js client and plugin host
https://neovim.io/node-client/
MIT License
464 stars 49 forks source link

Quick start example does not work on Windows: getNvimFromEnv fails #319

Closed saidelike closed 4 months ago

saidelike commented 4 months ago

getNvimFromEnv fails due to a space in the path? We can see it triggers a 'C:\Program' is not recognized as an internal or external command, operable program or batch file. error below when it is called which implies it tried to run it.

C:\>node demo.mjs
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
found:
{
  matches: [],
  invalid: [
    {
      path: 'C:\\Program Files\\Neovim\\bin\\nvim.exe',
      error: [Error]
    }
  ]
}

however then if I hardcode the path it works as shown below

  const found = getNvimFromEnv({ orderBy: "desc", minVersion: "0.9.0" });
  console.log("found:");
  console.log(found)
  const nvim_proc = child_process.spawn(
    // `C:\\Program Files\\Neovim\\bin\\nvim-qt.exe`,
    `C:\\Program Files\\Neovim\\bin\\nvim.exe`,
    ["--clean", "--embed"],
    {}
  );

  const nvim = attach({ proc: nvim_proc });
  nvim.command("vsp | vsp | vsp");

  console.log("awaiting window");
  const windows = await nvim.windows;
  assert.deepStrictEqual(windows.length, 4);
  assert.ok(windows[0] instanceof nvim.Window);

  nvim.window = windows[2];
  console.log("awaiting window #2");
  const win = await nvim.window;

C:\>node demo.mjs
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
found:
{
  matches: [],
  invalid: [
    {
      path: 'C:\\Program Files\\Neovim\\bin\\nvim.exe',
      error: [Error]
    }
  ]
}
awaiting window
awaiting window #2
waiting for Nvim (pid 968) to exit
Nvim exit code: 0

note that I haven't been able to have it working with nvim-qt.exe. Is that expected?

justinmk commented 4 months ago

Thanks for reporting this! Will fix.

note that I haven't been able to have it working with nvim-qt.exe. Is that expected?

what does "have it work with nvim-qt" mean? List the exact steps.

saidelike commented 4 months ago

You can ignore that nvim-qt.exe but it is basically an alternative binary on Windows. And the node client works in nvim-qt.exe when using the remote plugin

justinmk commented 4 months ago

I still don't understand what you mean. I need you to list the exact steps that you expect to work with nvim-qt.exe.

nvim-qt.exe is a GUI which starts a nvim.exe child. If you are trying to attach() to nvim-qt.exe, that won't work. You need to attach() to nvim.exe.

saidelike commented 4 months ago

Yes i also think it won't work as indeed I was trying what you mentions. Sorry for the confusion but i won't list steps as it does not make sense imho.

By the way, in the demo.mjs example, i noticed we don't see the gui at all and it is hidden (at least on Windows in my environment). It's that expected?

Am i missing something obvious here and is there a way to show the nvim.exe window? That would be handy to visually see the lines changed etc.

justinmk commented 4 months ago

Am i missing something obvious here and is there a way to show the nvim.exe window?

To attach to a already-running Nvim, you can need to get the socket name from the running Nvim via :echo v:servername for example. Then pass the socket name to attach().

saidelike commented 3 months ago

I can confirm that version 5.1.0 works now