Shadow eglot-server-programs to work around initialization problems

This commit is contained in:
Gerard Vermeulen 2022-07-12 11:22:59 +02:00
parent 8b7851c3f8
commit ecc42c39ea

View File

@ -229,7 +229,6 @@ The [[info:emacs#Init File][init file (info)]] does not load the ~custom-file~ a
citar-embark ; citar and embark integration
company ; complete anything
consult ; consult completing-read
eglot ; Emacs polyGLOT LSP client
embark ; act on any buffer selection
engrave-faces ; convert font-lock faces to text
magit ; Git Text-based User Interface
@ -3228,36 +3227,47 @@ such a proper [[info:emacs#Directory Variables][.dir-locals.el]] file.
#+caption: Configure =eglot= with =python-lsp-server= for Python.
#+name: lst:configure-eglot+python-lsp-server-for-python
#+begin_src emacs-lisp
(with-eval-after-load 'eglot
(setq-default
eglot-workspace-configuration
'(;; Disable the `:pyls_flake8' plugin to fall back to pycodestyle.
(:pylsp . (:plugins (:pyls_flake8 (:enabled t))))
(:pylsp . (:plugins (:jedi (:auto_import_modules ["numpy"])))))
(:pylsp . (:plugins (:jedi_completion (:cache_for ["astropy"])))))
(when (ensure-package-installation 'eglot)
(defvar eglot-server-programs
`((python-mode . ("pylsp")))
"Shadow the definition of `eglot-server-programs' in `eglot'.")
(with-eval-after-load 'eglot
(setq-default
eglot-workspace-configuration
'(;; Disable the `:pyls_flake8' plugin to fall back to pycodestyle.
(:pylsp . (:plugins (:pyls_flake8 (:enabled t))))
(:pylsp . (:plugins (:jedi (:auto_import_modules ["numpy"]))))
(:pylsp . (:plugins (:jedi_completion (:cache_for ["astropy"]))))))
(define-key eglot-mode-map (kbd "C-c n") #'flymake-goto-next-error)
(define-key eglot-mode-map (kbd "C-c p") #'flymake-goto-prev-error)
(define-key eglot-mode-map (kbd "C-c r") 'eglot-rename))
(define-key eglot-mode-map (kbd "C-c n") #'flymake-goto-next-error)
(define-key eglot-mode-map (kbd "C-c p") #'flymake-goto-prev-error)
(define-key eglot-mode-map (kbd "C-c r") 'eglot-rename)))
#+end_src
#+caption[Broken configure =eglot= with =python-lsp-server= for Python]:
#+caption: Broken configure =eglot= with =python-lsp-server= for Python.
#+name: lst:broken-configure-eglot+python-lsp-server-for-python
#+begin_src emacs-lisp :tangle no
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs '(python-mode "pylsp" "-vvv"))
(setq-default
eglot-workspace-configuration
'(;; To use flake8 instead of pycodestyle, see:
;; https://github.com/python-lsp/python-lsp-server#configuration
(:pylsp . (:configurationSources ["flake8"]))
(:pylsp . (:plugins (:pycodestyle (:enabled :json-false))))
(:pylsp . (:plugins (:mccabe (:enabled :json-false))))
(:pylsp . (:plugins (:pyflakes (:enabled :json-false))))
(:pylsp . (:plugins (:flake8 (:enabled t))))
(:pylsp . (:plugins (:jedi (:auto_import_modules ["numpy"]))))
(:pylsp . (:plugins (:jedi_completion (:cache_for ["astropy"])))))))
(when (ensure-package-installation 'eglot)
(defvar eglot-server-programs
`((python-mode . ("pylsp" "-vvv")))
"Shadow the definition of `eglot-server-programs' in `eglot'.")
(with-eval-after-load 'eglot
(setq-default
eglot-workspace-configuration
'(;; To use flake8 instead of pycodestyle, see:
;; https://github.com/python-lsp/python-lsp-server#configuration
(:pylsp . (:configurationSources ["flake8"]))
(:pylsp . (:plugins (:pycodestyle (:enabled :json-false))))
(:pylsp . (:plugins (:mccabe (:enabled :json-false))))
(:pylsp . (:plugins (:pyflakes (:enabled :json-false))))
(:pylsp . (:plugins (:flake8 (:enabled t))))
(:pylsp . (:plugins (:jedi (:auto_import_modules ["numpy"]))))
(:pylsp . (:plugins (:jedi_completion (:cache_for ["astropy"]))))))
(define-key eglot-mode-map (kbd "C-c n") #'flymake-goto-next-error)
(define-key eglot-mode-map (kbd "C-c p") #'flymake-goto-prev-error)
(define-key eglot-mode-map (kbd "C-c r") 'eglot-rename)))
#+end_src
#+caption[Start =eglot= in case of a proper =dir-local-variables-alist=]: