I've hit some trouble with lsp-mode and in particular lsp-jedi.

I have my virtualenv selected under Emacs using pyvenv-workon and jedi-language-server is installed under the virtual environment. At the command line it starts without error.

If I try opening a .py file in Emacs the server fails with...

INFO:pygls.server:Starting IO server
INFO:pygls.server:Shutting down the server
INFO:pygls.server:Closing the event loop.
Traceback (most recent call last):
  File "/home/neil/.virtualenvs/python3_9/lib/python3.9/site-packages/pygls/protocol.py", line 143, in deserialize_message
    deserialize_params(data, get_params_type)
  File "/home/neil/.virtualenvs/python3_9/lib/python3.9/site-packages/pygls/protocol.py", line 129, in deserialize_params
    data['params'] = params_type(**params)
  File "pydantic/main.py", line 400, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for InitializeParams
  value is not a valid integer (type=type_error.integer)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/neil/.virtualenvs/python3_9/bin/jedi-language-server", line 8, in <module>
  File "/home/neil/.virtualenvs/python3_9/lib/python3.9/site-packages/jedi_language_server/cli.py", line 99, in cli
  File "/home/neil/.virtualenvs/python3_9/lib/python3.9/site-packages/pygls/server.py", line 178, in start_io
  File "/usr/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/home/neil/.virtualenvs/python3_9/lib/python3.9/site-packages/pygls/server.py", line 68, in aio_readline
  File "/home/neil/.virtualenvs/python3_9/lib/python3.9/site-packages/pygls/protocol.py", line 464, in data_received
  File "/usr/lib/python3.9/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
  File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
  File "/home/neil/.virtualenvs/python3_9/lib/python3.9/site-packages/pygls/protocol.py", line 145, in deserialize_message
    raise JsonRpcInvalidParams()
pygls.exceptions.JsonRpcInvalidParams: Invalid Params

Process jedi stderr finished

I tried running plain Emacs using the lsp-start-plain.el suggested in GitHub issues and can activate the virtualenv and open a file without any problem so I think there is some error in how Emacs/lsp-mode is calling/starting jedi-language-server.

My configuration for lsp-mode is...

(use-package lsp-mode
  :ensure t
  :defer t
  (setq lsp-idle-delay 0.5
        lsp-enable-symbol-highlighting t)
  :commands (lsp lsp-deferred)
  :init (setq lsp-keymap-prefix "C-c l"
              lsp-bash-highlight-parsing-errors t)
  :hook ((python-mode . lsp)
         (bash-mode . lsp)
         (dockerfile-mode . lsp)
         (groovy-mode . lsp)
         (html-mode . lsp)
         (latex-mode . lsp)
         ;; (markdown-mode . lsp)
         (org-mode . lsp)
         (R-mode . lsp)
         (ess-r-mode . lsp)
         (sh-mode . lsp)
         (terraform-mode . lsp)))

(use-package lsp-ui
  :ensure t
  :defer t
  (setq lsp-ui-doc-delay 1
        lsp-ui-doc-enable t
        lsp-ui-doc-header nil
        lsp-ui-doc-use-childframe t
        lsp-ui-doc-position 'top
        lsp-ui-doc-include-signature t
        lsp-ui-doc-use-childframe t
        lsp-ui-sideline-enable nil
        lsp-ui-flycheck-enable t
        lsp-ui-flycheck-list-position 'right
        lsp-ui-flycheck-live-reporting t
        lsp-ui-peek-enable t
        lsp-ui-peek-list-width 60
        lsp-ui-peek-peek-height 25
        lsp-ui-sideline-enable t
        lsp-ui-sideline-show-hover t
        lsp-ui-sideline-delay 3)
  :hook (lsp-mode . lsp-ui-mode)
  :bind (:map lsp-ui-mode-map
              ("C-c i" . lsp-ui-imenu)))

(use-package lsp-treemacs
  :ensure t
  :defer t
  (setq lsp-treemacs-sync-mode 1))

(use-package lsp-jedi
  :ensure t
  (with-eval-after-load "lsp-mode"
    (add-to-list 'lsp-disabled-clients 'pyls)
    (add-to-list 'lsp-enabled-clients 'jedi)))

I tried toggle-debug-on-error to see what the problem was but couldn't get any info (presumably because the error occurs outside of Emacs with the way in which jedi-language-server is called).

Weird thing is I use the same configuration across computers, including a new work laptop where everything is fine.

Advice on how to go about working out what is going wrong would be very much appreciated.

  • looks like your version of pydantic is choking on something. try it in a new virtual env.
    – nega
    Commented May 14, 2022 at 21:29
  • I thought that might be an issue so I reinstalled pyglsand pydanticto no avail. I also used the exact same virtualenv with the lsp-start-plain.el that is suggested in the "issues" page on GitHub for jedi-language-serverand there were no errors so I think I've eliminated that avenue.
    – slackline
    Commented May 15, 2022 at 7:39


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.