neoclide / coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Other
24.43k stars 954 forks source link

Cygwin support #975

Closed cosminadrianpopescu closed 5 years ago

cosminadrianpopescu commented 5 years ago

Result from CocInfo

Empty output

Describe the bug

In cygwin the plugin will fail after 10 seconds. I can do CocConfig (for example) and have a perfect intellisense for about 10 seconds. Then the plugin will stop work. If I start node in debugging mode, I can see that the node process will just finish with no error after about 10 to 15 seconds. Within those 10 to 15 seconds, it works perfect. If in autoload/coc/client.vim I change the out_mode of the channel from json to nl, then the node process will not finish, but the plugin will just not work.

I can still use an older version which uses vim-proc and vim-node-rpc.

Reproduce the bug

cosminadrianpopescu commented 5 years ago

I'm trying to find the cause of the problem but I can't really understand the architecture. Is there a wiki or could you explain what is the architecture of the plugin? I have the impression that the issue is in the nvim plugin (not sure), but first I need to understand the architecture of the plugin.

For example, I have this js:

setTimeout(() =>  console.log(JSON.stringify({prop: 'cucu'}).replace(/\r\n/gi), '\n'), 3000);

process.stdin.resume();
process.stdin.setEncoding('utf8');

var lingeringLine = "";

process.stdin.on('data', function(chunk) {
    lines = chunk.split("\n");

    lines[0] = lingeringLine + lines[0];
    lingeringLine = lines.pop();

  console.log('lines are', lines);
});

process.stdin.on('end', function() {
    processLine(lingeringLine);
});

And then this vim:

function! OnStd(msg)
  echomsg "STD"
  echomsg string(a:msg)
endfunction

function! OnErr(msg)
  echomsg "ERR"
  echomsg string(a:msg)
endfunction

function! OnExit(code)
  echomsg "EXIT"
  echomsg string(a:code)
endfunction

    let options = {
          \ 'in_mode': 'json',
          \ 'out_mode': 'json',
          \ 'err_mode': 'nl', 
          \ 'out_cb': {channel, message -> OnStd(message)},
          \ 'err_cb': {channel, message -> OnErr(message)},
          \ 'exit_cb': {channel, code -> OnExit(code)}
          \}

let chan_id = job_start(['node', 'C:/Users/<user>/programs/js.js'], options)

echomsg "=================="
echomsg string(chan_id)

When I open the vim file and do so %, this isn't going to work. Doing :messages after 10 seconds, all I get is this:

==================
process 22388 run

But, if I change the out_mode to 'nl', instead of 'json', then I get the expected output:

==================
process 9296 run
STD
'{"prop":"cucu"} '
STD
''

Now, I've tried also in client.vim to change the out_mode to 'nl', but then the initialization of the plugin is never done. The promise is never resolved.

chemzqm commented 5 years ago

It's problem of node-client used by coc.nvim, checkout https://github.com/neoclide/neovim/blob/neoclide/README.md#debug-on-vim8 for how to debug with it.

cosminadrianpopescu commented 5 years ago

I've tried this already:

[node-client] rpc error: module.js:549
[node-client] rpc error:     throw err;
[node-client] rpc error:     ^
[node-client] rpc error:
[node-client] rpc error: Error: Cannot find module '../lib/attach'
[node-client] rpc error:     at Function.Module._resolveFilename (module.js:547:15)
[node-client] rpc error:     at Function.Module._load (module.js:474:25)
[node-client] rpc error:     at Module.require (module.js:596:17)
[node-client] rpc error:     at require (internal/module.js:11:18)
[node-client] rpc error:     at Object.<anonymous> (C:\Users\<my-user>\dotfiles\vim\pack\bundle\start\neovim-neoclide\bin\server.js:2:20)
[node-client] rpc error:     at Module._compile (module.js:652:30)
[node-client] rpc error:     at Object.Module._extensions..js (module.js:663:10)
[node-client] rpc error:     at Module.load (module.js:565:32)
[node-client] rpc error:     at tryModuleLoad (module.js:505:12)
[node-client] rpc error:     at Function.Module._load (module.js:497:3)
vim-node-rpc exited with code: 1
chemzqm commented 5 years ago

It means you didn't build it, run yarn install

cosminadrianpopescu commented 5 years ago

It's true, I've built it with tsc. I'll try and let you know.

cosminadrianpopescu commented 5 years ago

I've removed the neovim-neoclide folder, I've unzipped again the archive, I changed folder, I did the yarn install inside of the neovim-neoclide folder then I've started vim again with vim -u neovim-neoclide/mini.vim, but I get the same result. Anyway, I've seen that basically the yarn install is doing the same thing (npm install and then tsc).

cosminadrianpopescu commented 5 years ago

After modifying the bin/server.js to include the ../lib/attach/attach, it starts to work. But then in VIM I get [node-client] rpc error: Could not get vim api results.

chemzqm commented 5 years ago

You should test it out by use code from master, attach is included in server.js https://github.com/neoclide/neovim/blob/neoclide/bin/server.js#L2

cosminadrianpopescu commented 5 years ago

I am using master. I mean, in the server.js, the require is like this:

require('../lib/attach');

This will fail in node v10 on Windows (which is what is running from cygwin).

I replaced the line with

require('../lib/attach/attach')

And this will not throw the node module error, but then I have the vim error from the rpc module: [node-client] rpc error: Could not get vim api results.

chemzqm commented 5 years ago

Should be bug of vim with Cygvim, you can check if https://github.com/neovim/node-client/blob/neoclide/autoload/nvim/api.vim#L514 this function get called, what returned from vim by check debug log https://github.com/neovim/node-client/blob/neoclide/src/transport/connection.ts#L34

chemzqm commented 5 years ago

Use :Openlog to check the log of vim8

cosminadrianpopescu commented 5 years ago

OpenLog will not return anything. It's empty.

cosminadrianpopescu commented 5 years ago

Finally, solved the issue. I will have a PR and everything. The issue comes from here:

https://github.com/neoclide/coc.nvim/blob/581f6e5340bb1334396eb2c034b6233dd21d9f6d/src/util/index.ts#L116

Because I am running under cygwin, this function will not detect the node process (which is a windows and not a cygwin process) running. So, in the workspace.ts file, here:

https://github.com/neoclide/coc.nvim/blob/581f6e5340bb1334396eb2c034b6233dd21d9f6d/src/workspace.ts#L1597

the process is going to be killed after 15 seconds. I will try to detect running under cygwin and then changing the isRunning function to also work there and then I will raise a PR.

ducklin5 commented 5 years ago

I must have opened this page 5 separate times trying to figure out how to get it to work on babun (cygwin). This should be added to the wiki (Quoting OP):

because node.exe is a windows application, create a junction of the home folder directly on the root of the drive. For example, if your cygwin home folder is /home/abc, which translates to c:/cygwin/home/abc, then run mklink /j c:/home c:/cygwin/home.