How to use pyright in lsp-mode of CentOS7, emacs.
--pyright
: Microsoft python language server
- https://github.com/microsoft/pyright
--For language server and language server protocol, please see this article.
-About language server protocol (Part 1)
--lsp-mode
: emacs minor mode to use language server functionality with language server protocol.
--lsp-ui-mode
: emacs minor mode that adds UI functions such as pop-up display to the functions of lsp-mode.
--python-mode
: emacs major mode for python.
node.js
pyright
is written in node.js.
You can look around here. https://github.com/nodesource/distributions/blob/master/README.md#enterprise-linux-based-distributions
If you don't want to add the yum repository, download the rpm from here and put it in. https://rpm.nodesource.com/pub_14.x/el/7/x86_64/
$ node --version
v14.7.0
$ npm --version
6.14.5
pyright
$ npm -g install pyright
$ pyright --version
pyright 1.1.61
It is pyright-langserver
that is started from emacs.
pyright-langserver
is installed with pyright
.
lsp-pyright, lsp-mode, lsp-ui, company, imenu-list, flycheck can all be installed from melpa.
M-x package-install lsp-mode
...
lsp-mode
https://emacs-lsp.github.io/lsp-mode/
This is a package for using the functions of lsp with emacs. Not for Python, but generic.
When used with Python, it is used as a minor mode of python-mode
.
Company
is recommended for code completion.
http://company-mode.github.io/
company-lsp
is no longer supported in lsp-mode 7.0.1. company
is enough.
https://github.com/emacs-lsp/lsp-mode/blob/master/CHANGELOG.org
Dropped support for company-lsp, the suggested provider is company-capf.
lsp-ui
A package that assists lsp-mode
.
lsp-ui-sideline
lsp-ui-peek
lsp-ui-doc
lsp-ui-imenu
lsp-pyright
https://github.com/emacs-lsp/lsp-python-ms
An add-on package that allows you to use pyright
in lsp-mode.
company
A package that provides IntelliSense-like code completion. Complementation is enhanced by including various backend packages.
lsp-mode (or rather language-server) acts as the backend for the company.
imenu-list
This is a package that displays the contents of ʻimenu` in an IDE-like side frame.
flycheck
A generic linter framework.
https://www.flycheck.org/en/latest/
I'm using ʻuse-package. I cut and paste it from my ʻinit.el
, so it may not make sense.
(use-package python
:mode
("\\.py\\'" . python-mode)
)
(use-package lsp-mode
:config
;; .venv, .mypy_Exclude cache from watch
(dolist (dir '(
"[/\\\\]\\.venv$"
"[/\\\\]\\.mypy_cache$"
"[/\\\\]__pycache__$"
))
(push dir lsp-file-watch-ignored))
;; lsp-See here for mode settings.
;; https://emacs-lsp.github.io/lsp-mode/page/settings/
(setq lsp-auto-configure t)
(setq lsp-enable-completion-at-point t)
;; imenu-I use list so I don't use imenu integration
(setq lsp-enable-imenu nil)
;;Enable integration with cross-references
;; xref-find-definitions
;; xref-find-references
(setq lsp-enable-xref t)
;;Use flycheck as linter framework
(setq lsp-diagnostics-provider :flycheck)
;;Function information display in minibuffer
(setq lsp-eldoc-enable-hover t)
;; nii:Make function information in the minibuffer only signature
;; t:Function information in the minibuffer, doc-Show string body
(setq lsp-eldoc-render-all nil)
;; breadcrumb
;;Display the breadcrumb trail.
(setq lsp-headerline-breadcrumb-enable t)
(setq lsp-headerline-breadcrumb-segments '(project file symbols))
;; snippet
(setq lsp-enable-snippet t)
;;Hook function definition
;; python-For mode, lsp-mode config
(defun lsp/python-mode-hook
()
(when (fboundp 'company-mode)
;;configure company
(setq
;;Activate completion with one character
company-minimum-prefix-length 1
;; default is 0.2
company-idle-delay 0.0
)
)
)
:commands (lsp lsp-deferred)
:hook
(python-mode . lsp) ; python-lsp in mode-Enable mode
(python-mode . lsp/python-mode-hook) ; python-Set up a hook function for mode
)
(use-package lsp-pyright
:init
(defun lsp-pyright/python-mode-hook
()
;; lsp-Enable pyright
(require 'lsp-pyright)
(when (fboundp 'flycheck-mode)
;;lint with pyright, so python-I don't use mypy.
(setq flycheck-disabled-checkers '(python-mypy))
)
)
:hook (python-mode . lsp-pyright/python-mode-hook)
)
(use-package lsp-ui
:after lsp-mode
:config
;; ui-Enable peek
(setq lsp-ui-peek-enable t)
;;Even if there is only one candidate, peek is always displayed.
(setq lsp-ui-peek-always-show t)
;;Display information such as flycheck on the sideline
(setq lsp-ui-sideline-show-diagnostics t)
;;Show code actions on sideline
(setq lsp-ui-sideline-show-code-actions t)
;;What is displayed on the hover is displayed on the sideline instead of the hover
;;(setq lsp-ui-sideline-show-hover t)
:bind
(:map lsp-ui-mode-map
;;Default xref-find-With definitions, you can jump, but ui-I can't use peek.
("M-." . lsp-ui-peek-find-definitions)
;;Default xref-find-With references, you can jump, but ui-I can't use peek.
("M-?" . lsp-ui-peek-find-references)
)
:hook
(lsp-mode . lsp-ui-mode)
)
(use-package imenu-list)
(use-package company
:init
(global-company-mode t)
)
(use-package flycheck
:init
(global-flycheck-mode)
)
Recommended Posts