ycm-core / lsp-examples

Use any language server with YouCompleteMe.
https://ycm-core.github.io/YouCompleteMe
Apache License 2.0
83 stars 26 forks source link

Kotlin completer donot work #5

Closed Jackey-Huo closed 5 years ago

Jackey-Huo commented 5 years ago

Hi~ I try to use the kotlin settings for a gradle project, but there is no semantic completion at all. The stderr log file output as below:

2019-08-09 14:47:34,756 - INFO - Received ready request
2019-08-09 14:47:34,809 - INFO - Received event notification
2019-08-09 14:47:34,811 - INFO - Received event notification
2019-08-09 14:47:34,811 - INFO - Adding buffer identifiers for file: /home/jackey/My_project/kotlin/hello/hello.kt
Traceback (most recent call last):
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/bottle/bottle.py", line 862, in _handle
    return route.call(**args)
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/bottle/bottle.py", line 1740, in wrapper
    rv = callback(*a, **ka)
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/watchdog_plugin.py", line 104, in wrapper
    return callback( *args, **kwargs )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/hmac_plugin.py", line 68, in wrapper
    body = callback( *args, **kwargs )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/handlers.py", line 67, in EventNotification
    event_handler )( request_data )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 1186, in OnFileReadyToParse
    self._StartAndInitializeServer( request_data )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 1172, in _StartAndInitializeServer
    extra_conf_dir = self._GetSettingsFromExtraConf( request_data )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 1152, in _GetSettingsFromExtraConf
    module = extra_conf_store.ModuleForSourceFile( request_data[ 'filepath' ] )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/extra_conf_store.py", line 62, in ModuleForSourceFile
    return Load( ModuleFileForSourceFile( filename ) )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/extra_conf_store.py", line 73, in ModuleFileForSourceFile
    if Load( module_file ):
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/extra_conf_store.py", line 158, in Load
    if not force and not _ShouldLoad( module_file, is_global ):
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/extra_conf_store.py", line 141, in _ShouldLoad
    raise UnknownExtraConf( module_file )
UnknownExtraConf: Found /home/jackey/.ycm_extra_conf.py. Load? 

(Question can be turned off with options, see YCM docs)
2019-08-09 14:47:34,916 - INFO - Received filetype completion available request
2019-08-09 14:47:36,676 - INFO - Received extra conf load request
2019-08-09 14:47:36,689 - INFO - Received event notification
2019-08-09 14:47:36,689 - INFO - Adding buffer identifiers for file: /home/jackey/My_project/kotlin/hello/hello.kt
2019-08-09 14:47:36,690 - INFO - Starting kotlinCompleter: [u'/home/jackey/Development/lsp/kotlin/KotlinLanguageServer/server/build/install/server/bin/kotlin-language-server']
2019-08-09 14:47:36,706 - INFO - kotlinCompleter started
2019-08-09 14:47:44,252 - ERROR - The language server communication channel closed unexpectedly. Issue a RestartServer command to recover.
Traceback (most recent call last):
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 318, in run
    self._ReadMessages()
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 473, in _ReadMessages
    self._DispatchMessage( lsp.Parse( content ) )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 549, in _DispatchMessage
    self._responses[ message_id ].ResponseReceived( message )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 174, in ResponseReceived
    self._response_callback( self, message )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 1566, in response_handler
    self._HandleInitializeInPollThread( message )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 1589, in _HandleInitializeInPollThread
    self._server_capabilities = response[ 'result' ][ 'capabilities' ]
KeyError: u'result'
2019-08-09 14:47:49,437 - INFO - Received debug info request

After set log level into debug mode, I found some useful info here:

(Question can be turned off with options, see YCM docs)
2019-08-09 14:49:38,564 - INFO - Received filetype completion available request
2019-08-09 14:49:38,893 - INFO - Received extra conf load request
2019-08-09 14:49:38,906 - INFO - Received event notification
2019-08-09 14:49:38,907 - DEBUG - Event name: FileReadyToParse
2019-08-09 14:49:38,907 - INFO - Adding buffer identifiers for file: /home/jackey/My_project/kotlin/hello/hello.kt
2019-08-09 14:49:38,908 - DEBUG - No Settings function defined in /home/jackey/.ycm_extra_conf.py
2019-08-09 14:49:38,908 - DEBUG - Using path /home/jackey for extra_conf_dir
2019-08-09 14:49:38,908 - INFO - Starting kotlinCompleter: [u'/home/jackey/Development/lsp/kotlin/KotlinLanguageServer/server/build/install/server/bin/kotlin-language-server']
2019-08-09 14:49:38,924 - INFO - kotlinCompleter started
2019-08-09 14:49:38,926 - DEBUG - TX: Sending message: b'Content-Length: 357\r\n\r\n{"id": "1", "jsonrpc": "2.0", "method": "initialize", "params": {"capabilities": {"textDocument": {"completion": {"completionItemKind": {"valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}}}}, "initializationOptions": {}, "processId": 29394, "rootPath": "/home/jackey", "rootUri": "file:///home/jackey"}}'
2019-08-09 14:49:39,814 - DEBUG - RX: Received message: b'{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"main      Connected to client"}}'
2019-08-09 14:49:39,844 - DEBUG - RX: Received message: b'{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"client    Adding workspace file:///home/jackey to source path"}}'
2019-08-09 14:49:44,503 - INFO - Received debug info request
2019-08-09 14:49:46,473 - DEBUG - RX: Received message: b'{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":1,"message":"client    Internal error: java.lang.reflect.InvocationTargetException"}}'
2019-08-09 14:49:46,474 - DEBUG - RX: Received message: b'{"jsonrpc":"2.0","id":"1","error":{"code":-32603,"message":"Internal error.","data":"java.lang.RuntimeException: java.lang.reflect.InvocationTargetException\\n\\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:67)\\n\\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120)\\n\\tat org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261)\\n\\tat org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)\\n\\tat org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:192)\\n\\tat org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)\\n\\tat org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:99)\\n\\tat java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)\\n\\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\\n\\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\\n\\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\\n\\tat java.lang.Thread.run(Thread.java:748)\\nCaused by: java.lang.reflect.InvocationTargetException\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\\n\\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.lang.reflect.Method.invoke(Method.java:498)\\n\\tat org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)\\n\\t... 11 more\\nCaused by: java.io.UncheckedIOException: java.nio.file.AccessDeniedException: /home/jackey/.cache/dconf\\n\\tat java.nio.file.FileTreeIterator.fetchNextIfNeeded(FileTreeIterator.java:88)\\n\\tat java.nio.file.FileTreeIterator.hasNext(FileTreeIterator.java:104)\\n\\tat java.util.Iterator.forEachRemaining(Iterator.java:115)\\n\\tat java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)\\n\\tat java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)\\n\\tat java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)\\n\\tat java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)\\n\\tat java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)\\n\\tat java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)\\n\\tat org.javacs.kt.SourceFilesKt.findSourceFiles(SourceFiles.kt:197)\\n\\tat org.javacs.kt.SourceFilesKt.access$findSourceFiles(SourceFiles.kt:1)\\n\\tat org.javacs.kt.SourceFiles.addWorkspaceRoot(SourceFiles.kt:129)\\n\\tat org.javacs.kt.KotlinLanguageServer.initialize(KotlinLanguageServer.kt:70)\\n\\t... 16 more\\nCaused by: java.nio.file.AccessDeniedException: /home/jackey/.cache/dconf\\n\\tat sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)\\n\\tat sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)\\n\\tat sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)\\n\\tat sun.nio.fs.UnixFileSystemProvider.newDirectoryStream(UnixFileSystemProvider.java:427)\\n\\tat java.nio.file.Files.newDirectoryStream(Files.java:457)\\n\\tat java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:300)\\n\\tat java.nio.file.FileTreeWalker.next(FileTreeWalker.java:372)\\n\\tat java.nio.file.FileTreeIterator.fetchNextIfNeeded(FileTreeIterator.java:95)\\n\\t... 28 more\\n"}}'
2019-08-09 14:49:46,475 - ERROR - The language server communication channel closed unexpectedly. Issue a RestartServer command to recover.
Traceback (most recent call last):
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 318, in run
    self._ReadMessages()
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 473, in _ReadMessages
    self._DispatchMessage( lsp.Parse( content ) )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 549, in _DispatchMessage
    self._responses[ message_id ].ResponseReceived( message )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 174, in ResponseReceived
    self._response_callback( self, message )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 1566, in response_handler
    self._HandleInitializeInPollThread( message )
  File "/home/jackey/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/completers/language_server/language_server_completer.py", line 1589, in _HandleInitializeInPollThread
    self._server_capabilities = response[ 'result' ][ 'capabilities' ]
KeyError: u'result'

After some analysis, I finally found that this error is caused by the missing of .ycm_extra_conf.py file, YCM treats the path of conf file as workspace of the project and send it to kotlin-language-server, but the server does not set properly try-catch block for file parsing. After put .ycm_extra_conf.py into the root path of gradle project, everything work fine now ;)

Thus for an easy start for new users, I think it's better to add this notice in README file. And I provide a pr for it ;)

puremourning commented 5 years ago

Closed by #6