Revise python layer
Make LSP be used as default backend Request DAP layer when LSP is used as backend Update README.org with latest pyls package dependencies Remove obsolete getter functions
This commit is contained in:
parent
7f6b4205cb
commit
9720127282
5 changed files with 55 additions and 70 deletions
|
@ -49,9 +49,9 @@ This layer adds support for the Python language.
|
|||
|
||||
** Features:
|
||||
- Support for the following backends:
|
||||
- [[https://github.com/proofit404/anaconda-mode][anaconda]] (default),
|
||||
- [[https://github.com/emacs-lsp/lsp-python][Language Server Protocol]] (experimental - 2 implementations),
|
||||
- python-language-server
|
||||
- [[https://github.com/proofit404/anaconda-mode][anaconda]],
|
||||
- [[https://github.com/emacs-lsp/lsp-python][Language Server Protocol]]
|
||||
- python-language-server (default)
|
||||
- Microsoft python language server
|
||||
- Auto-completion
|
||||
- Code Navigation
|
||||
|
@ -81,10 +81,7 @@ To choose a default backend set the layer variable =python-backend=:
|
|||
(python :variables python-backend 'anaconda)
|
||||
#+END_SRC
|
||||
|
||||
Alternatively the =lsp= backend will be automatically chosen if the layer =lsp=
|
||||
is used and you did not specify any value for =python-backend=.
|
||||
|
||||
Backend can be chosen on a per project basis using directory local variables
|
||||
A Backend can be chosen on a per project basis using directory local variables
|
||||
(files named =.dir-locals.el= at the root of a project), an example to use the
|
||||
=lsp= backend:
|
||||
|
||||
|
@ -148,7 +145,7 @@ layer variable as follows:
|
|||
You just have to install python language server package:
|
||||
|
||||
#+BEGIN_SRC sh
|
||||
pip install python-language-server
|
||||
pip install python-language-server[all]
|
||||
#+END_SRC
|
||||
|
||||
Additionally you can install the following other packages:
|
||||
|
@ -158,6 +155,7 @@ Additionally you can install the following other packages:
|
|||
pip install pyls-isort
|
||||
# for mypy checking (python 3.4+ is needed)
|
||||
pip install pyls-mypy
|
||||
pip install pyls-black
|
||||
#+END_SRC
|
||||
|
||||
If you've installed the language server and related packages as development
|
||||
|
@ -228,17 +226,15 @@ directory local variable in your project root. ~SPC f v d~ in Spacemacs. See
|
|||
The root of the project is detected with a =.git= directory or a =setup.cfg= file.
|
||||
|
||||
** Buffer formatting
|
||||
One of [[https://github.com/google/yapf][YAPF]] (the default), [[https://github.com/ambv/black][black]] or =lsp= may be selected as the formatter, via
|
||||
=python-formatter=, as ='yapf=, ='black= or =lsp= respectively.
|
||||
One of [[https://github.com/google/yapf][YAPF]], [[https://github.com/ambv/black][black]] or =lsp= may be selected as the formatter, via
|
||||
=python-formatter=, as =yapf=, =black= or =lsp= respectively. If non is selected
|
||||
either =yapf= or =lsp= is used depending on the selected backend.
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(setq-default dotspacemacs-configuration-layers '(
|
||||
(python :variables python-formatter 'yapf)))
|
||||
#+END_SRC
|
||||
|
||||
Alternatively the =lsp= formatter will be automatically chosen if the layer =lsp=
|
||||
is used and you did not specify any value for =python-formatter=.
|
||||
|
||||
The key binding ~SPC m =~ invokes the selected formatter on the current buffer
|
||||
when in non LSP python mode otherwise ~SPC m ==~ is used.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
;;; config.el --- Python Layer Configuration File for Spacemacs
|
||||
;;
|
||||
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
||||
;; Copyright (c) 2012-2019 Sylvain Benner & Contributors
|
||||
;;
|
||||
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
||||
;; URL: https://github.com/syl20bnr/spacemacs
|
||||
|
@ -14,10 +14,9 @@
|
|||
(spacemacs|define-jump-handlers python-mode)
|
||||
(spacemacs|define-jump-handlers cython-mode anaconda-mode-goto)
|
||||
|
||||
(defvar python-backend 'nil
|
||||
(defvar python-backend 'lsp
|
||||
"The backend to use for IDE features.
|
||||
Possible values are `anaconda'and `lsp'.
|
||||
If `nil' then `anaconda' is the default backend unless `lsp' layer is used.")
|
||||
Possible values are `anaconda' and `lsp'.")
|
||||
|
||||
(defvar python-lsp-server 'pyls
|
||||
"Language server to use for lsp backend. Possible values are `pyls'
|
||||
|
@ -31,7 +30,7 @@ and `mspyls'")
|
|||
|
||||
(defvar python-formatter nil
|
||||
"The formatter to use. Possible values are `yapf',
|
||||
`black' and 'lsp'.")
|
||||
`black' and `lsp'. If left empty a default will be selected based on the backend.")
|
||||
|
||||
(defvar python-format-on-save nil
|
||||
"If non-nil, automatically format code with formatter selected
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
;;; funcs.el --- Python Layer functions File for Spacemacs
|
||||
;;
|
||||
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
||||
;; Copyright (c) 2012-2019 Sylvain Benner & Contributors
|
||||
;;
|
||||
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
||||
;; URL: https://github.com/syl20bnr/spacemacs
|
||||
|
@ -9,44 +9,34 @@
|
|||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
(defun spacemacs//python-backend ()
|
||||
"Returns selected backend."
|
||||
(if python-backend
|
||||
python-backend
|
||||
(cond
|
||||
((configuration-layer/layer-used-p 'lsp) 'lsp)
|
||||
(t 'anaconda))))
|
||||
|
||||
(defun spacemacs//python-formatter ()
|
||||
"Returns selected backend."
|
||||
(if python-formatter
|
||||
python-formatter
|
||||
(cond
|
||||
((configuration-layer/layer-used-p 'lsp) 'lsp)
|
||||
(t 'yapf))))
|
||||
"Returns selected python-formatter."
|
||||
(or python-formatter (pcase python-backend
|
||||
('lsp 'lsp)
|
||||
('anaconda 'yapf))))
|
||||
|
||||
(defun spacemacs//python-setup-backend ()
|
||||
"Conditionally setup python backend."
|
||||
(when python-pipenv-activate (pipenv-activate))
|
||||
(pcase (spacemacs//python-backend)
|
||||
(pcase python-backend
|
||||
(`anaconda (spacemacs//python-setup-anaconda))
|
||||
(`lsp (spacemacs//python-setup-lsp))))
|
||||
|
||||
(defun spacemacs//python-setup-company ()
|
||||
"Conditionally setup company based on backend."
|
||||
(pcase (spacemacs//python-backend)
|
||||
(pcase python-backend
|
||||
(`anaconda (spacemacs//python-setup-anaconda-company))
|
||||
(`lsp (spacemacs//python-setup-lsp-company))))
|
||||
|
||||
(defun spacemacs//python-setup-dap ()
|
||||
"Conditionally setup elixir DAP integration."
|
||||
;; currently DAP is only available using LSP
|
||||
(pcase (spacemacs//python-backend)
|
||||
(pcase python-backend
|
||||
(`lsp (spacemacs//python-setup-lsp-dap))))
|
||||
|
||||
(defun spacemacs//python-setup-eldoc ()
|
||||
"Conditionally setup eldoc based on backend."
|
||||
(pcase (spacemacs//python-backend)
|
||||
(pcase python-backend
|
||||
;; lsp setup eldoc on its own
|
||||
(`anaconda (spacemacs//python-setup-anaconda-eldoc))))
|
||||
|
||||
|
@ -382,7 +372,7 @@ to be called for each testrunner. "
|
|||
"Bind the python formatter keys.
|
||||
Bind formatter to '==' for LSP and '='for all other backends."
|
||||
(spacemacs/set-leader-keys-for-major-mode 'python-mode
|
||||
(if (eq (spacemacs//python-backend) 'lsp)
|
||||
(if (eq python-backend 'lsp)
|
||||
"=="
|
||||
"=") 'spacemacs/python-format-buffer))
|
||||
|
||||
|
|
|
@ -11,4 +11,4 @@
|
|||
|
||||
(when (and (boundp 'python-backend)
|
||||
(eq python-backend 'lsp))
|
||||
(configuration-layer/declare-layer-dependencies '(lsp)))
|
||||
(configuration-layer/declare-layer-dependencies '(lsp dap)))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
;;; packages.el --- Python Layer packages File for Spacemacs
|
||||
;;
|
||||
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
||||
;; Copyright (c) 2012-2019 Sylvain Benner & Contributors
|
||||
;;
|
||||
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
||||
;; URL: https://github.com/syl20bnr/spacemacs
|
||||
|
@ -50,7 +50,7 @@
|
|||
|
||||
(defun python/init-anaconda-mode ()
|
||||
(use-package anaconda-mode
|
||||
:if (eq (spacemacs//python-backend) 'anaconda)
|
||||
:if (eq python-backend 'anaconda)
|
||||
:defer t
|
||||
:init
|
||||
(setq anaconda-mode-installation-directory
|
||||
|
@ -94,7 +94,7 @@
|
|||
|
||||
(defun python/init-company-anaconda ()
|
||||
(use-package company-anaconda
|
||||
:if (eq (spacemacs//python-backend) 'anaconda)
|
||||
:if (eq python-backend 'anaconda)
|
||||
:defer t
|
||||
;; see `spacemacs//python-setup-anaconda-company'
|
||||
))
|
||||
|
@ -114,7 +114,7 @@
|
|||
(use-package cython-mode
|
||||
:defer t
|
||||
:config
|
||||
(when (eq (spacemacs//python-backend) 'anaconda)
|
||||
(when (eq python-backend 'anaconda)
|
||||
(spacemacs/set-leader-keys-for-major-mode 'cython-mode
|
||||
"hh" 'anaconda-mode-show-doc
|
||||
"gu" 'anaconda-mode-find-references))))
|
||||
|
|
Reference in a new issue