Enhanced autocompletion in Julia, R and Python (LSP)

With gradual progress jupyterlab-lsp arrived at a place when we can show off this simple gif with an LSP-driven autocompletion working across Julia, Python and R:

It’s a small thing, but hopefully will make the user-experience better.

I hope to submit a JEP pre-proposal to make it an official Jupyter subproject soon :slight_smile:

12 Likes

Hi,

Recently I have created a new virtual environment with Anaconda on a Windows 11 PC, in which I installed Jupyterlab 3.4.3 together with python-lsp-server. While jupyterlab is running, an error appears in the log all of the time and autocompletion etc. stops working in jupyterlab. I copied the relevant excerpt from the log below, which shows the exception that is thrown:

[E 2022-06-14 14:49:47.157 ServerApp] <LspStdIoWriter(parent=<LanguageServerSession(language_server=pylsp, argv=[‘C:\Users\Tom\anaconda3\envs\engineering-22-06\python.exe’, ‘-m’, ‘pylsp’])>)> couldn’t write message: Content-Length: 266

{"jsonrpc":"2.0","id":267,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///c:/Users/Tom/PycharmProjects/GeneralEngineering/.virtual_documents/control_systems/notebooks/mechanical_network.ipynb"},"position":{"line":2,"character":9}}}
Traceback (most recent call last):
  File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\site-packages\jupyter_lsp\stdio.py", line 193, in write
    await convert_yielded(self._write_one(response.encode("utf-8")))
  File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\asyncio\futures.py", line 284, in __await__
    yield self  # This tells Task to wait for completion.
  File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\asyncio\tasks.py", line 304, in __wakeup
    future.result()
  File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\asyncio\futures.py", line 201, in result
    raise self._exception
  File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\Tom\anaconda3\envs\engineering-22-06\lib\site-packages\jupyter_lsp\stdio.py", line 201, in _write_one
    self.stream.write(message)
OSError: [Errno 22] Invalid argument

After trying out Kite and Tabnine, I really appreciate the code completion and other stuff that python-lsp-server offers. So I hope that someone knows how this error can be fixed. I found that when I click the refresh button of the browser, the lsp-server gets active again, but after a short while the error comes up again.

EDIT:
From the error description it can be deduced that the error happens when method textDocument/documentHighlight is called. After disabling “Code Highlights” in Jupyterlab Settings,
the error hasn’t happened anymore.

I was happy too soon, the error can also happen when other methods are called.

Greetings,
Tom

1 Like

Hi @TomLXXVI would you mind filling out a bug report template on GitHub: GitHub - jupyter-lsp/jupyterlab-lsp: Coding assistance for JupyterLab (code navigation + hover suggestions + linters + autocompletion + rename) using Language Server Protocol?

Since recently, the bug doesn’t show up anymore. I think that a recent Windows update solved the issue for me.

1 Like

I have a similar error with all operating system updates. The error occurs some time after the start of work. And Lsp server stops working. I don’t understand how to fix it.

Hi,
Today I have created a new virtual environment with Anaconda on a Windows 11 PC, in which I installed Jupyterlab 3.6.5 together with python-lsp-server. While jupyterlab is running, an error appears in the log all of the time. I copied the relevant excerpt from the log below, which shows the exception that is thrown:

Error: expected initialized notification, got: Request(Request { id: RequestId(I32(0)), method: "initialize", params: Object {"capabilities": Object {"textDocument": Object {"completion": Object {"completionItem": Object {"commitCharactersSupport": Bool(true), "deprecatedSupport": Bool(true), "documentationFormat": Array [String("markdown"), String("plaintext")], "preselectSupport": Bool(false), "snippetSupport": Bool(false), "tagSupport": Object {"valueSet": Array [Number(1)]}}, "contextSupport": Bool(false), "dynamicRegistration": Bool(true)}, "declaration": Object {"dynamicRegistration": Bool(true), "linkSupport": Bool(true)}, "definition": Object {"dynamicRegistration": Bool(true), "linkSupport": Bool(true)}, "hover": Object {"contentFormat": Array [String("markdown"), String("plaintext")], "dynamicRegistration": Bool(true)}, "implementation": Object {"dynamicRegistration": Bool(true), "linkSupport": Bool(true)}, "publishDiagnostics": Object {"tagSupport": Object {"valueSet": Array [Number(2), Number(1)]}}, "signatureHelp": Object {"dynamicRegistration": Bool(true), "signatureInformation": Object {"documentationFormat": Array [String("markdown"), String("plaintext")]}}, "synchronization": Object {"didSave": Bool(true), "dynamicRegistration": Bool(true), "willSave": Bool(false), "willSaveWaitUntil": Bool(false)}, "typeDefinition": Object {"dynamicRegistration": Bool(true), "linkSupport": Bool(true)}}, "workspace": Object {"didChangeConfiguration": Object {"dynamicRegistration": Bool(true)}}}, "initializationOptions": Null, "processId": Null, "rootUri": String("file:///c:/Users/JawDrin/jupyterwork"), "workspaceFolders": Null} })
[E 2023-08-20 16:02:02.823 ServerApp] <LspStdIoWriter(parent=<LanguageServerSession(language_server=texlab, argv=['D:\\anaconda3\\envs\\py310\\Scripts\\texlab.EXE'])>)> couldn't write message: Content-Length: 52

    {"jsonrpc":"2.0","method":"initialized","params":{}}
    Traceback (most recent call last):
      File "D:\anaconda3\envs\py310\lib\site-packages\jupyter_lsp\stdio.py", line 193, in write
        await convert_yielded(self._write_one(response.encode("utf-8")))
      File "D:\anaconda3\envs\py310\lib\concurrent\futures\thread.py", line 58, in run
        result = self.fn(*self.args, **self.kwargs)
      File "D:\anaconda3\envs\py310\lib\site-packages\jupyter_lsp\stdio.py", line 201, in _write_one
        self.stream.write(message)
    OSError: [Errno 22] Invalid argument

[E 2023-08-20 16:13:16.536 ServerApp] <LspStdIoWriter(parent=<LanguageServerSession(language_server=texlab, argv=['D:\\anaconda3\\envs\\py310\\Scripts\\texlab.EXE'])>)> couldn't write message: Content-Length: 215

    {"jsonrpc":"2.0","id":9,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///c:/Users/JawDrin/jupyterwork/Trytry/continuous_network/untitled.tex"},"position":{"line":3,"character":14}}}
    Traceback (most recent call last):
      File "D:\anaconda3\envs\py310\lib\site-packages\jupyter_lsp\stdio.py", line 193, in write
        await convert_yielded(self._write_one(response.encode("utf-8")))
      File "D:\anaconda3\envs\py310\lib\concurrent\futures\thread.py", line 58, in run
        result = self.fn(*self.args, **self.kwargs)
      File "D:\anaconda3\envs\py310\lib\site-packages\jupyter_lsp\stdio.py", line 201, in _write_one
        self.stream.write(message)
    OSError: [Errno 22] Invalid argument
[E 2023-08-20 16:13:16.537 ServerApp] <LspStdIoWriter(parent=<LanguageServerSession(language_server=texlab, argv=['D:\\anaconda3\\envs\\py310\\Scripts\\texlab.EXE'])>)> couldn't write message: Content-Length: 215

    {"jsonrpc":"2.0","id":9,"method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file:///c:/Users/JawDrin/jupyterwork/Trytry/continuous_network/untitled.tex"},"position":{"line":3,"character":14}}}
    Traceback (most recent call last):
      File "D:\anaconda3\envs\py310\lib\site-packages\jupyter_lsp\stdio.py", line 193, in write
        await convert_yielded(self._write_one(response.encode("utf-8")))
      File "D:\anaconda3\envs\py310\lib\concurrent\futures\thread.py", line 58, in run
        result = self.fn(*self.args, **self.kwargs)
      File "D:\anaconda3\envs\py310\lib\site-packages\jupyter_lsp\stdio.py", line 201, in _write_one
        self.stream.write(message)
    OSError: [Errno 22] Invalid argument

So I hope that someone knows how this error can be fixed. Could you give me some advises

pylsp works but not texlab.

Can you please report this issue in the bug tracker: GitHub - jupyter-lsp/jupyterlab-lsp: Coding assistance for JupyterLab (code navigation + hover suggestions + linters + autocompletion + rename) using Language Server Protocol?

I installed
@krassowski/jupyterlab-lsp and
@jupyter-lsp/jupyterlab-lsp at the same time. when I uninstalled one (@krassowski/jupyterlab-lsp) of them, it run successfully!
Thanks!!!

1 Like

image
This jupyter_lab_config How to configure AutoCompletion to True in the python file?

This setting on the screenshot does not come from jupyterlab-lsp but from jupyterlab v4 and may be soon removed. You can configure any shortcuts that you see in the settings form from a JSON file using overrides.json.

Yes, I am using Jupyterab v4. Is there only one way?