ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.46k stars 2.81k forks source link

TypeScript completion hangs after Ctrl-Space #1802

Closed kmARC closed 8 years ago

kmARC commented 8 years ago

YouCompleteMe completion works very well with TypeScript if the semantic trigger (by default, .) is pressed. However, when I want to get completion and type hints without pressing a trigger (e.g. using <C-Space> or <C-x> <C-o>), YCM stops working, even worse, after exiting vim, YCM and tsserver processes are still running.

I also tried Python completion, works out of the box, even after pressing <C-Space>.

Example

function add(a: number, b: number) {
    return a+b;
}

class MyClass {
    add(a: number, b: number) {
        return a+b;
    }
}

var my = new MyClass();
  1. Typing my. then suggestions show up (in this case, the MyClass::add method)
  2. Typing add<C-Space> then vim freezes for around half a second, and doesn't offer completion
  3. Typing any characters, vim seems to freeze for the same half a second
  4. Typing again my. neither works anymore.

    Versions

    • OS: Ubuntu 15.04
    • Vim: 7.4.488 (default Ubuntu package)
    • YouCompleteMe: 96f0d941 (updated today with Vim-Plug)
    • Node.js: v4.2.1 (managed by nvm)
    • TypeScript: 1.6.2 (also tried with 1.5.3, neither works)

      Attachments

    • server_42157_stderr.log.txt
    • vim-version.txt
kmARC commented 8 years ago

A good start for debugging would be to attach somehow to the tsserver that was started by YouCompleteMe. Any idea how to do this?

puremourning commented 8 years ago

Are the log files listed in YcmDebugInfo ?

kmARC commented 8 years ago

This is what I have after :YcmDebugInfo

Printing YouCompleteMe debug information...
-- Server has Clang support compiled in: True
-- Clang version: clang version 3.7.0 (tags/RELEASE_370/final)
--
-- Server running at: http://127.0.0.1:56312
-- Server process ID: 10183
-- Server logfiles:
--   /tmp/ycm_temp/server_56312_stdout.log
--   /tmp/ycm_temp/server_56312_stderr.log

From these, I attached stderr.log. stdout.log is empty.

vheon commented 8 years ago

I would say post the tsserver logs file, but apparently we don't make them :astonished:

EDIT: forget this. There should be a log file, but I don't know where the server saves it.

vheon commented 8 years ago
  1. Typing again my. neither works anymore.

This makes me think that the tsserver crashed or something.

kmARC commented 8 years ago

This makes me think that the tsserver crashed or something.

According to ps it's running even after exiting vim. Killing it kills YouCompleteMe process too. Maybe it's not a YCM bug but TypeScript?

I'll try to find the log file.

kmARC commented 8 years ago

Unfortunately I could not find the logs. However, I found out the following.

After completion stops working, if I try to :YcmCompleter GoToDefinition, vim freezes for a long time and then I get a python stack trace too complaining on a timeout:

HTTPConnectionPool(host='127.0.0.1', port=43038): Read timed out. (read timeout=0.5)                                                                                                                                                                                      
Error detected while processing function <SNR>119_CompleterCommand:                                                                                                                                                                                                       
line   18:                                                                                                                                                                                                                                                                
Traceback (most recent call last):                                                                                                                                                                                                                                        
  File "<string>", line 1, in <module>                                                                                                                                                                                                                                    
  File "/home/oro/.vim/plugged/YouCompleteMe/autoload/../python/ycm/youcompleteme.py", line 207, in SendCommandRequest                                                                                                                                                    
    return SendCommandRequest( arguments, completer )                                                                                                                                                                                                                     
  File "/home/oro/.vim/plugged/YouCompleteMe/autoload/../python/ycm/client/command_request.py", line 111, in SendCommandRequest                                                                                                                                           
    request.Start()                                                                                                                                                                                                                                                       
  File "/home/oro/.vim/plugged/YouCompleteMe/autoload/../python/ycm/client/command_request.py", line 53, in Start                                                                                                                                                         
    'run_completer_command' )                                                                                                                                                                                                                                             
  File "/home/oro/.vim/plugged/YouCompleteMe/autoload/../python/ycm/client/base_request.py", line 71, in PostDataToHandler                                                                                                                                                
    timeout ) )                                                                                                                                                                                                                                                           
  File "/home/oro/.vim/plugged/YouCompleteMe/autoload/../python/ycm/client/base_request.py", line 163, in JsonFromFuture                                                                                                                                                  
    response = future.result()                                                                                                                                                                                                                                            
  File "/home/oro/.vim/plugged/YouCompleteMe/third_party/pythonfutures/concurrent/futures/_base.py", line 404, in result                                                                                                                                                  
    return self.__get_result()                                                                                                                                                                                                                                            
  File "/home/oro/.vim/plugged/YouCompleteMe/third_party/pythonfutures/concurrent/futures/_base.py", line 356, in __get_result                                                                                                                                            
    raise self._exception                                                                                                                                                                                                                                                 
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='127.0.0.1', port=43038): Read timed out. (read timeout=30)

I tried the following:

  1. import * as Kefir from 'kefir'; This works perfectly.
  2. var stream = Kefir. completion shows up immediately.
  3. Continue editing: var stream = Kefir.interval(1.5);
  4. stream. <- and from this point, YCM stops working.
  5. Now if I want :YcmCompleter GoToDefinition then after several seconds I get the stacktrace.
  6. In a terminal I telnet-ed to into the running server, it accepts requests. I don't know the protocol to test it, but it seems working.
kmARC commented 8 years ago

Additional info:

  1. With the same version of node, npm, typescript, I tried another TypeScript plugin (https://github.com/Quramy/tsuquyomi). It works well (it also can't complete after stream., but at least doesn't hang).
  2. I Installed latest Atom, completion works like a charm, even with stream.
vheon commented 8 years ago

Do you know for sure if Atom uses the tsserver as well?

vheon commented 8 years ago

@icholy maybe this would interest you.

kmARC commented 8 years ago

@vheon Sorry you're right probably they don't (seems they had their stuff before MS released TSServer)

icholy commented 8 years ago

I'll get on this.

vheon commented 8 years ago

If https://github.com/Quramy/tsuquyomi can't complete in the same spot then that is a tsserver issue. I really don't like the fact that vim freeze.

vheon commented 8 years ago

@icholy thanks :+1:

icholy commented 8 years ago

I'm able to reproduce this. My vim doesn't freeze though.

icholy commented 8 years ago

Looks like a tsserver issue:

Err 27    Exception on executing command {"command": "completions", "type": "request", "arguments": {"line": 8, "file": "/home/icholy/test/foo.ts", "offset": 5}, "seq": 7}:
EAGAIN: resource temporarily unavailable, write
Error: EAGAIN: resource temporarily unavailable, write
    at Error (native)
    at Object.fs.writeSync (fs.js:706:20)
    at Object.write (/usr/local/lib/node_modules/typescript/lib/tsserver.js:944:43)
    at IOSession.Session.sendLineToClient (/usr/local/lib/node_modules/typescript/lib/tsserver.js:40992:27)
    at IOSession.Session.send (/usr/local/lib/node_modules/typescript/lib/tsserver.js:40999:22)
    at IOSession.Session.response (/usr/local/lib/node_modules/typescript/lib/tsserver.js:41026:22)
    at IOSession.Session.output (/usr/local/lib/node_modules/typescript/lib/tsserver.js:41030:22)
    at IOSession.Session.onMessage (/usr/local/lib/node_modules/typescript/lib/tsserver.js:41695:30)
    at Interface.<anonymous> (/usr/local/lib/node_modules/typescript/lib/tsserver.js:43663:27)
    at emitOne (events.js:77:13)
Info 28   response: {"seq":0,"type":"response","command":"completions","request_seq":7,"success":false,"message":"Error processing request. EAGAIN: resource temporarily unavailable, write"}
kmARC commented 8 years ago

Okay, so what's the next step? Should we probably create a bugreport to the TypeScript guys? Or is it possible that YCM doesn't use the API properly?

icholy commented 8 years ago

Looks like it's already fixed: https://github.com/Microsoft/TypeScript/pull/5354

The sublime plugin was having the same issue: https://github.com/Microsoft/TypeScript-Sublime-Plugin/issues/379

EDIT: You'll have to wait till 1.7 is released unless you're ok with using their master.

EDIT: FYI, you can enable tsserver logging by setting the TSS_LOG env variable:

export TSS_LOG='-level verbose -file /tmp/tsserver.log'
vheon commented 8 years ago

FYI, you can enable tsserver logging by setting the TSS_LOG env variable:

export TSS_LOG='-level verbose -file /tmp/tsserver.log'

Thanks.

@Valloric, @micbou, @puremourning @oblitum I think we should add this to the typescript completer so we could keep the logs around like we do with every other completers.

kmARC commented 8 years ago

Thanks for all. With npm install -g typescript@next works like a charm.

puremourning commented 8 years ago

Can we redirect to ycmd log file? This makes it simpler IMO.

On 27 Nov 2015, at 18:24, Andrea Cedraro notifications@github.com wrote:

FYI, you can enable tsserver logging by setting the TSS_LOG env variable:

export TSS_LOG='-level verbose -file /tmp/tsserver.log' Thanks.

@Valloric, @micbou, @puremourning @oblitum I think we should add this to the typescript completer so we could keep the logs around like we do with every other completers.

— Reply to this email directly or view it on GitHub.

icholy commented 8 years ago

Can we redirect to ycmd log file? This makes it simpler IMO.

I don't think so.

puremourning commented 8 years ago

Because we communicate with tsserver via stdin/stdout ? Makes sense.

vheon commented 8 years ago

@puremourning I'm working on adding logs file for tsserver ;)

puremourning commented 8 years ago

nice one

icholy commented 8 years ago

@kmARC FYI 1.7 was released today.

kmARC commented 8 years ago

Yepp, thanks for heads up.

$ npm install -g typescript@latest
...
$ tsc --version 
message TS6029: Version 1.7.3

Works perfectly with YCM.