jupyter-lsp / jupyterlab-lsp

Coding assistance for JupyterLab (code navigation + hover suggestions + linters + autocompletion + rename) using Language Server Protocol
https://jupyterlab-lsp.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.81k stars 148 forks source link

"OSError: [Errno 22] Invalid argument" just after strarting a Julia kernel #608

Open goryntsev opened 3 years ago

goryntsev commented 3 years ago

Description

I am trying to start using jupyterlab-lsp with julia language server in a conda environment. Both jupyterlab-lsp extension and julia language server are installed using conda. In the status bar of my julia notebooks I see that the server is "fully connected & initialized". But when I type in a code cell something in julia I see no tooltips, no highlighting, no suggestions, no autocompletion.

Reproduce

  1. Install jupyterlab in a fresh and clean conda environment.
  2. Install jupyterlab-lsp using conda.
  3. Install the julia language server using Pkg from the julia REPL.
  4. Open the anaconda prompt with the environment activated.
  5. Start jupyterlab and create a new notebook with julia kernel.
  6. Find the julia language server in the list of language servers opened from the status bar.
  7. Notice the language server status displayed as "Fully initialized".
  8. Set '"continuousHinting": true' in Settings.
  9. Open a code cell and begin typing any julia keyword. Nothing happens.
  10. Begin typing any julia keyword then press Tab. Nothing happens.

In the anaconda prompt from where I start the jupyterlab a series of error messages is produced — see them below. Sometimes — not every time — everything works fine for a minute after the launch of the jupyterlab but then breaks and produces error messages anyway.

Expected behavior

As showed in readme

Context

Required: installed server extensions
Config dir: C:\Users\alexa\miniconda3\etc\jupyter
    jupyter_lsp enabled
    - Validating jupyter_lsp...
      jupyter_lsp 1.2.0 ok
    jupyterlab enabled
    - Validating jupyterlab...
      jupyterlab 3.0.16 ok
    nbclassic enabled
    - Validating nbclassic...
      nbclassic  ok
Required: installed lab extensions
C:\Users\alexa\miniconda3\share\jupyter\labextensions
        @krassowski/jupyterlab-lsp v3.6.0 enabled ok (python, jupyterlab-lsp)
Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here.
You may want to sanitize the paths in the output.
Command Line Output
[ Info: Received new data from Julia Symbol Server.
ERROR: The handler for the 'textDocument/hover' request returned a value of type Nothing, which is not a valid return type according to the request definition.
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:33
 [2] dispatch_msg(x::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, dispatcher::JSONRPC.MsgDispatcher, msg::Dict{String, Any})
   @ JSONRPC C:\Users\alexa\.julia\packages\JSONRPC\yu0G3\src\typed.jl:77
 [3] run(server::LanguageServerInstance)
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\y1ebo\src\languageserverinstance.jl:308
 [4] runserver(pipe_in::Base.PipeEndpoint, pipe_out::Base.PipeEndpoint, env_path::String, depot_path::String, err_handler::Nothing, symserver_store_path::Nothing)
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\y1ebo\src\runserver.jl:46
 [5] runserver()
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\y1ebo\src\runserver.jl:44
 [6] top-level scope
   @ none:1
[E 2021-05-26 23:01:11.889 ServerApp] )> couldn't write message: Content-Length: 239

    {"jsonrpc":"2.0","id":5,"method":"textDocument/completion","params":{"textDocument":{"uri":"file://c:/Users/alexa/.virtual_documents/Untitled5.ipynb"},"position":{"line":3,"character":2},"context":{"triggerKind":1,"triggerCharacter":"o"}}}
    Traceback (most recent call last):
      File "C:\Users\alexa\miniconda3\lib\site-packages\jupyter_lsp\stdio.py", line 193, in write
        await convert_yielded(self._write_one(response.encode("utf-8")))
      File "C:\Users\alexa\miniconda3\lib\concurrent\futures\thread.py", line 52, in run
        result = self.fn(*self.args, **self.kwargs)
      File "C:\Users\alexa\miniconda3\lib\site-packages\jupyter_lsp\stdio.py", line 201, in _write_one
        self.stream.write(message)
    OSError: [Errno 22] Invalid argument
Browser Output (recommended for all interface issues)
Paste the output from your browser JavaScript console replacing the text in here.

To learn how to open the developer tools in your browser:
https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools#How_to_open_the_devtools_in_your_browser
If too many messages accumulated after many hours of working in JupyterLab,
consider refreshing the window and then reproducing the bug to reduce the noise in the logs.

bollwyvl commented 3 years ago

Please check the issue template... there is a lot more information we could use to help you down in the context part, but there's not quite enough information in what i see there.

goryntsev commented 3 years ago

Sorry, please find the updated description above.

krassowski commented 3 years ago

Set '"continuousHinting": true' in Settings.

does it work when you do not do that (i.e. the setting is set to false)?

What is your version of LanguageServer, SymbolServer, and JSONRPC?

krassowski commented 3 years ago

Also what is your Julia version.

krassowski commented 3 years ago

julia language server are installed using conda

I did not know it is on conda. Do you have a link for convenience?

Edit: This message very much looks like an issue on Juli language server side:

[ Info: Received new data from Julia Symbol Server.
ERROR: The handler for the 'textDocument/hover' request returned a value of type Nothing, which is not a valid return type according to the request definition.
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:33
 [2] dispatch_msg(x::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, dispatcher::JSONRPC.MsgDispatcher, msg::Dict{String, Any})
   @ JSONRPC C:\Users\alexa\.julia\packages\JSONRPC\yu0G3\src\typed.jl:77
 [3] run(server::LanguageServerInstance)
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\y1ebo\src\languageserverinstance.jl:308
 [4] runserver(pipe_in::Base.PipeEndpoint, pipe_out::Base.PipeEndpoint, env_path::String, depot_path::String, err_handler::Nothing, symserver_store_path::Nothing)
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\y1ebo\src\runserver.jl:46
 [5] runserver()
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\y1ebo\src\runserver.jl:44
 [6] top-level scope
   @ none:1

So I guess you should make sure that you are running the latest version in case if it was fixed and then report the bug on the LanguageServer.jl repository.

goryntsev commented 3 years ago

Sorry for my writing, I did not mean that julia language server is installed using conda — it is my mistake in description. Certainly it has been installed as a julia package.

My julia environment:

By the way I have tried to replicate the issue out of any conda environment, installed everything with pip — the result is the same: sometimes it works fine for a while and then breaks with error messages anyway. This delay is particularly weird.

Setting "continuousHinting": false' brings no improvement: the same behavior with the same error messages.

krassowski commented 3 years ago

Why don't you try updating to the most recent versions? LanguageServer v4.0.0 (and SymbolServer v7.0.0) just got released 3 hours ago.

krassowski commented 3 years ago

I just tested manually on Ubuntu that all works fine with IJulia v1.23.2, LanguageServer v4.0.0, and Julia 1.5.3. If after upgrade you still experience issues, please try opening an issue in https://github.com/julia-vscode/LanguageServer.jl and linking this one (providing the Julia backtrace starting with [ Info: Received new data from Julia Symbol Server).

krassowski commented 3 years ago

Could you please try to upgrade to v3.7.0 and see if it still happens?

goryntsev commented 3 years ago

First I followed your advice and updated the freshly relleased julia LanguageServer to v4.0.0. And again got the error messages both from the server and from the extension — but this time they differed from those before, find an excerpt from the longer backtrace in details below.

backtrace with LS v4.0.0
ERROR: get_offset crashed. More diagnostics:
line=35
character=0
position(io)=0
line_offsets='[0, 15, 16, 17, 76, 77, 78, 97, 98, 99, 134, 216, 299, 328, 360, 368, 377, 378, 379, 391, 392, 393, 435, 470, 498, 538, 604, 630, 632, 633, 634, 734, 832, 845]'
text='aaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaa
aaaaaaaa

aaaaaaaaaaa

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaa
a

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaαααααααaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaαααααααaaaa
aaaaaaaaaaaa
'

original_error=ERROR: BoundsError: attempt to access 34-element Vector{Int64} at index [36]
Stacktrace:
  [1] getindex
    @ .\array.jl:801 [inlined]
  [2] get_offset(doc::LanguageServer.Document, line::Int64, character::Int64)
    @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\document.jl:77
  [3] get_offset
    @ C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\document.jl:98 [inlined]
  [4] textDocument_documentHighlight_request(params::LanguageServer.DocumentHighlightParams, server::LanguageServerInstance, conn::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint})
    @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\requests\highlight.jl:3
  [5] (::LanguageServer.var"#96#97"{typeof(LanguageServer.textDocument_documentHighlight_request), LanguageServerInstance})(conn::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, params::LanguageServer.DocumentHighlightParams)
    @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\languageserverinstance.jl:245
  [6] dispatch_msg(x::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, dispatcher::JSONRPC.MsgDispatcher, msg::Dict{String, Any})
    @ JSONRPC C:\Users\alexa\.julia\packages\JSONRPC\yu0G3\src\typed.jl:67
  [7] run(server::LanguageServerInstance)
    @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\languageserverinstance.jl:353
  [8] runserver(pipe_in::Base.PipeEndpoint, pipe_out::Base.PipeEndpoint, env_path::String, depot_path::String, err_handler::Nothing, symserver_store_path::Nothing)
    @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\runserver.jl:46
  [9] runserver()
    @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\runserver.jl:44
 [10] top-level scope
    @ none:1

Stacktrace:
 [1] get_offset(doc::LanguageServer.Document, line::Int64, character::Int64)
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\document.jl:95
 [2] get_offset
   @ C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\document.jl:98 [inlined]
 [3] textDocument_documentHighlight_request(params::LanguageServer.DocumentHighlightParams, server::LanguageServerInstance, conn::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint})
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\requests\highlight.jl:3
 [4] (::LanguageServer.var"#96#97"{typeof(LanguageServer.textDocument_documentHighlight_request), LanguageServerInstance})(conn::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, params::LanguageServer.DocumentHighlightParams)
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\languageserverinstance.jl:245
 [5] dispatch_msg(x::JSONRPC.JSONRPCEndpoint{Base.PipeEndpoint, Base.PipeEndpoint}, dispatcher::JSONRPC.MsgDispatcher, msg::Dict{String, Any})
   @ JSONRPC C:\Users\alexa\.julia\packages\JSONRPC\yu0G3\src\typed.jl:67
 [6] run(server::LanguageServerInstance)
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\languageserverinstance.jl:353
 [7] runserver(pipe_in::Base.PipeEndpoint, pipe_out::Base.PipeEndpoint, env_path::String, depot_path::String, err_handler::Nothing, symserver_store_path::Nothing)
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\runserver.jl:46
 [8] runserver()
   @ LanguageServer C:\Users\alexa\.julia\packages\LanguageServer\jiDTR\src\runserver.jl:44
 [9] top-level scope
   @ none:1

But then I followed your next advice and upgraded the extension to v3.7.0 — and happily got couple of hours of smooth work without any crash or error.

I would propose to keep this issue open for a week so that I could post here any updates on my side. If there will be nothing we can consider the issue closed. Does it make sense to you?

krassowski commented 3 years ago

Hi @goryntsev, any updates on this one?