Improve the eglot configuration according to the updated README.md

This commit is contained in:
Gerard Vermeulen 2022-09-18 11:14:56 +02:00
parent 02cfb36efc
commit d6212ff231

View File

@ -3874,47 +3874,64 @@ and listing [[lst:setting-python-shell-virtualenv-root]] to set
:CUSTOM_ID: sec:eglot-python :CUSTOM_ID: sec:eglot-python
:END: :END:
Listing [[lst:configure-eglot+python-lsp-server-for-python]] configures [[https://github.com/joaotavora/eglot][eglot]] for Listing [[lst:configure-eglot+pylsp-with-pyls-flake8]] configures [[https://github.com/joaotavora/eglot][eglot]] for [[https://www.python.org][Python]]
[[https://www.python.org][Python]] using the [[https://github.com/python-lsp/python-lsp-server][python-lsp-server]]. In order to enable all builtin using the [[https://github.com/python-lsp/python-lsp-server][python-lsp-server]] with the [[https://github.com/emanspeaks/pyls-flake8#readme][pyls-flake8]] plugin for the easiest way to
let [[https://github.com/python-lsp/python-lsp-server][python-lsp-server]] use [[https://github.com/PyCQA/flake8][flake8]]. In order to enable all builtin
[[https://github.com/python-lsp/python-lsp-server][python-lsp-server]] capabilities, ensure installation of the Python packages [[https://github.com/python-lsp/python-lsp-server][python-lsp-server]] capabilities, ensure installation of the Python packages
[[https://github.com/hhatto/autopep8#readme][autopep8]], [[https://github.com/PyCQA/flake8][flake8]], [[https://github.com/PyCQA/pydocstyle#readme][pydocstyle]], [[https://github.com/PyCQA/pylint#readme][pylint]], [[https://github.com/python-lsp/python-lsp-server][python-lsp-server]], [[https://github.com/python-rope/rope#readme][rope]], and [[https://github.com/google/yapf#readme][yapf]]. In [[https://github.com/hhatto/autopep8#readme][autopep8]], [[https://github.com/PyCQA/flake8][flake8]], [[https://github.com/PyCQA/pydocstyle#readme][pydocstyle]], [[https://github.com/PyCQA/pylint#readme][pylint]], [[https://github.com/python-lsp/python-lsp-server][python-lsp-server]], [[https://github.com/python-rope/rope#readme][rope]], and [[https://github.com/google/yapf#readme][yapf]]. The
addition, install the [[https://github.com/emanspeaks/pyls-flake8#readme][pyls-flake8]] plugin to let [[https://github.com/python-lsp/python-lsp-server][python-lsp-server]] use [[https://github.com/PyCQA/flake8][flake8]]. latest [[https://github.com/python-lsp/python-lsp-server#readme][python-lsp-server]] documentation tells to configure it for [[https://github.com/PyCQA/flake8][flake8]] as in
The latest [[https://github.com/python-lsp/python-lsp-server#readme][python-lsp-server]] documentation tells to let it use [[https://github.com/PyCQA/flake8][flake8]] as in listing [[lst:configure-eglot+pylsp-sans-pyls-flake8]]. This method is under
[[lst:broken-configure-eglot+python-lsp-server-for-python]], but it does not work. investigation (it feels flaky since it shows some error messages twice).
Listing [[lst:eglot-directory-variables-for-python]] shows a proper [[info:emacs#Directory Variables][.dir-locals.el]] Listing [[lst:eglot-directory-variables-for-python]] shows a proper [[info:emacs#Directory Variables][.dir-locals.el]]
file in the root directory of any [[https://www.python.org][Python]] project to start [[https://github.com/joaotavora/eglot][eglot]] automatically file in the root directory of any [[https://www.python.org][Python]] project to start [[https://github.com/joaotavora/eglot][eglot]] automatically
according to the configuration in listing [[lst:eglot-maybe-ensure]]. according to the configuration in listing [[lst:eglot-maybe-ensure]]. Type
{{{kbd(M-x eglot-show-workspace-configuration)}}} to dump a =JSON=
representation of src_emacs-lisp{eglot-workspace-configuration} for debugging.
The comment in listing [[lst:ensure-eglot-installation]] also shows how to increase
the the verbosity of [[https://github.com/python-lsp/python-lsp-server][python-lsp-server]] log output for debugging.
#+caption[Configure =eglot= with =python-lsp-server= for Python]: #+caption[Configure =eglot= with =python-lsp-server= with =pyls_flake8=]:
#+caption: Configure =eglot= with =python-lsp-server= for Python. #+caption: Configure =eglot= with =python-lsp-server= with =pyls_flake8=.
#+name: lst:configure-eglot+python-lsp-server-for-python #+name: lst:configure-eglot+pylsp-with-pyls-flake8
#+begin_src emacs-lisp #+begin_src emacs-lisp
(with-eval-after-load 'eglot (with-eval-after-load 'eglot
(setq-default (setq-default
eglot-workspace-configuration eglot-workspace-configuration
'(;; Disable the `:pyls_flake8' plugin to fall back to pycodestyle. ;; Disable the `:pyls_flake8' plugin to fall back to pycodestyle.
(:pylsp . (:plugins (:pyls_flake8 (:enabled t)))) `((:pylsp . (:plugins
(:pylsp . (:plugins (:jedi (:auto_import_modules ["numpy"])))) (:pyls_flake8
(:pylsp . (:plugins (:jedi_completion (:cache_for ["astropy"]))))))) (:enabled t)
:jedi
(:auto_import_modules ["numpy"])
:jedi_completion
(:cache_for ["astropy"])))))))
#+end_src #+end_src
#+caption[Broken configure =eglot= with =python-lsp-server= for Python]: #+caption[Configure =eglot= with =python-lsp-server= sans =pyls_flake8=]:
#+caption: Broken configure =eglot= with =python-lsp-server= for Python. #+caption: Configure =eglot= with =python-lsp-server= sans =pyls_flake8=.
#+name: lst:broken-configure-eglot+python-lsp-server-for-python #+name: lst:configure-eglot+pylsp-sans-pyls-flake8
#+begin_src emacs-lisp :tangle no #+begin_src emacs-lisp :tangle no
(with-eval-after-load 'eglot (with-eval-after-load 'eglot
(setq-default (setq-default
eglot-workspace-configuration eglot-workspace-configuration
'(;; To use flake8 instead of pycodestyle, see: '(;; How to use flake8 instead of pycodestyle officially, see:
;; https://github.com/python-lsp/python-lsp-server#configuration ;; https://github.com/python-lsp/python-lsp-server#configuration
(:pylsp . (:configurationSources ["flake8"])) (:pylsp . (:configurationSources
(:pylsp . (:plugins (:pycodestyle (:enabled :json-false)))) ["flake8"]
(:pylsp . (:plugins (:mccabe (:enabled :json-false)))) :plugins
(:pylsp . (:plugins (:pyflakes (:enabled :json-false)))) (:pycodestyle
(:pylsp . (:plugins (:flake8 (:enabled t)))) (:enabled :json-false)
(:pylsp . (:plugins (:jedi (:auto_import_modules ["numpy"])))) :mccabe
(:pylsp . (:plugins (:jedi_completion (:cache_for ["astropy"]))))))) (:enabled :json-false)
:pyflakes
(:enabled
:json-false)
:flake8
(:enabled t)
:jedi
(:auto_import_modules ["numpy"])
:jedi_completion
(:cache_for ["astropy"])))))))
#+end_src #+end_src
#+caption[Propose =directory-variables= to launch =eglot=]: #+caption[Propose =directory-variables= to launch =eglot=]:
@ -3925,10 +3942,14 @@ according to the configuration in listing [[lst:eglot-maybe-ensure]].
;; Proposal for a .dir-locals.el file in the root of any Python project. ;; Proposal for a .dir-locals.el file in the root of any Python project.
((python-mode ((python-mode
. ((eglot-workspace-configuration . ((eglot-workspace-configuration
. (;; Disable the `:pyls_flake8' plugin to fall back to pycodestyle. ;; Disable the `:pyls_flake8' plugin to fall back to pycodestyle.
(:pylsp . (:plugins (:pyls_flake8 (:enabled t)))) . ((:pylsp . (:plugins
(:pylsp . (:plugins (:jedi (:auto_import_modules ["numpy"])))) (:pyls_flake8
(:pylsp . (:plugins (:jedi_completion (:cache_for ["astropy"]))))))))) (:enabled t)
:jedi
(:auto_import_modules ["numpy"])
:jedi_completion
(:cache_for ["astropy"])))))))))
#+end_src #+end_src
#+attr_latex: :booktabs yes :float table #+attr_latex: :booktabs yes :float table