Flattened some cquery/ccls configuration

c-c++-lsp-initialization-options:
-> ccls-initialization-options
-> cquery-extra-init-params (cacheFormat set to "msgpack" by default)

c-c++-lsp-args:
-> ccls-args
-> cquery-extra-args

c-c++-lsp-cache-dir:
-> ccls: Appended to initialization-options
-> cquery-cache-dir

<<Amendment 1 21/12/18>>
Removing 'clangd' from list of lsp clients to squash per-file prompt for
language client.
Updated lsp/packages.el to reflect upstream lsp-mode function name changes.
Python layer -- added if guards to prevent anaconda package loading / keyboard
shortcut config when lsp backend selected.
This commit is contained in:
cormacc 2018-12-11 21:59:25 +00:00 committed by Codruț Constantin Gușoi
parent f346ae0683
commit c375bc428f
9 changed files with 47 additions and 42 deletions

View File

@ -11,6 +11,9 @@
;; variables
(spacemacs|define-jump-handlers c++-mode)
(spacemacs|define-jump-handlers c-mode)
(defconst c-c++-modes '(c-mode c++-mode)
"Primary major modes of the `c-c++' layer.")
@ -45,9 +48,6 @@
"If non-nil, automatically format code with ClangFormat on
save. Clang support has to be enabled for this to work.")
(spacemacs|define-jump-handlers c++-mode)
(spacemacs|define-jump-handlers c-mode)
(defvar c-c++-default-mode-for-headers 'c-mode
"Default mode to open header files. Can be `c-mode' or `c++-mode'.")
@ -77,17 +77,10 @@ if no pattern matches the project root, lsp-c-c++ will be initialized.")
"When non-nil, use rainbow semantic highlighting")
(defvar c-c++-lsp-initialization-options nil
"Extra initialisation parameters to pass to the ccls backend. See
"Extra initialisation parameters to pass to the lsp backend. See
https://github.com/MaskRay/ccls/blob/master/src/config.hh
for details. N.B. cquery still uses the deprecated extra-init-params (below)")
for details. N.B. This is remapped to cquery-extra-init-params when using cquery backend")
;; I've left cquery/ccls -extra-init-params separate for now, as one has defaults while the other doesn't
;; Just to facilitate switching between the two easily
(defvar c-c++-lsp-extra-init-params '(:cacheFormat "msgpack")
"Extra initialisation parameters to pass to the backend. See
https://github.com/cquery-project/cquery/blob/master/src/config.h or
for details.")
(defvar c-c++-lsp-extra-args nil
(defvar c-c++-lsp-args nil
"Extra args to pass to the backend. E.g. to log to file.
https://github.com/MaskRay/ccls/wiki/Emacs for details")
https://github.com/MaskRay/ccls/wiki/Emacs for details. N.B. this is remapped to cquery-extra-args when using cquery backend")

View File

@ -221,19 +221,19 @@ and the arguments for flyckeck-clang based on a project-specific text file."
(defun spacemacs//c-c++-lsp-set-config (param prefix suffix)
(when (symbol-value param) (spacemacs//c-c++-lsp-set-symbol prefix suffix param)))
(defun spacemacs//c-c++-lsp-apply-config (suffix)
(spacemacs//c-c++-lsp-set-config (intern (concat "c-c++-lsp-" suffix)) nil (concat "-" suffix)))
(defun spacemacs//c-c++-lsp-apply-config (&rest parameters)
(dolist (suffix parameters) (spacemacs//c-c++-lsp-set-config (intern (concat "c-c++-lsp-" suffix)) nil (concat "-" suffix))))
;; -- END helper functions for common configuration of cquery and ccls backends
(defun spacemacs//c-c++-lsp-config ()
"Configure the LSP backend specified by the `c-c++-backend' configuration variable."
(progn
(remhash 'clangd lsp-clients)
(spacemacs//c-c++-lsp-define-extensions)
(spacemacs//c-c++-lsp-wrap-functions)
(setq-default flycheck-disabled-checkers '(c/c++-clang c/c++-gcc))
(dolist (param '("executable" "extra-init-params" "initialization-options" "extra-args" "project-whitelist" "project-blacklist" "sem-highlight-method"))
(spacemacs//c-c++-lsp-apply-config param))
(spacemacs//c-c++-lsp-apply-config "executable" "initialization-options" "args" "project-whitelist" "project-blacklist" "sem-highlight-method")
(if (eq c-c++-lsp-cache-dir nil)
(progn
@ -241,10 +241,15 @@ and the arguments for flyckeck-clang based on a project-specific text file."
(message (concat "c-c++: No c-c++-lsp-cache-dir specified: defaulting to " c-c++-lsp-cache-dir))))
(ecase c-c++-backend
('lsp-cquery (setq cquery-cache-dir c-c++-lsp-cache-dir))
('lsp-cquery (setq cquery-cache-dir c-c++-lsp-cache-dir)
(setq cquery-extra-args c-c++-lsp-args)
(setq cquery-extra-init-params
(if c-c++-lsp-initialization-options
(append c-c++-lsp-initialization-options '(:cacheFormat "msgpack"))
'(:cacheFormat "msgpack"))))
('lsp-ccls (setq ccls-initialization-options
(if ccls-initialization-options
(append ccls-initialization-options `(:cacheDirectory ,c-c++-lsp-cache-dir))
(if c-c++-lsp-initialization-options
(append c-c++-lsp-initialization-options `(:cacheDirectory ,c-c++-lsp-cache-dir))
`(:cacheDirectory ,c-c++-lsp-cache-dir)))))
(when c-c++-lsp-sem-highlight-rainbow

View File

@ -260,25 +260,22 @@
;; BEGIN LSP BACKEND PACKAGES
;; See also https://github.com/cquery-project/cquery/wiki/Emacs
;; :mode "\\.c..'" appears to work for deferred loading, in terms of registration with lsp layer
;; however results in a warning in the log as the package doesn't define a function 'cquery'
;; So probably preferable not to defer
(defun c-c++/init-cquery ()
(use-package cquery
:if (eq c-c++-backend 'lsp-cquery)
:init
(add-hook 'c-mode-common-hook 'lsp)
:config
(spacemacs//c-c++-lsp-config)))
(spacemacs//c-c++-lsp-config)
:hook ((c-mode c++-mode) .
(lambda () (cl-pushnew #'company-lsp company-backends) (require 'cquery) (remhash 'clangd lsp-clients) (lsp)))))
;; See also https://github.com/MaskRay/ccls/wiki/Emacs
(defun c-c++/init-ccls ()
(use-package ccls
:if (eq c-c++-backend 'lsp-ccls)
:init
(add-hook 'c-mode-common-hook 'lsp)
:config
(spacemacs//c-c++-lsp-config)))
(spacemacs//c-c++-lsp-config)
:hook ((c-mode c++-mode) .
(lambda () (cl-pushnew #'company-lsp company-backends) (require 'ccls) (remhash 'clangd lsp-clients) (lsp)))))
;;Intentionally adding both cquery and ccls cache dirs to ignore list, to facilitate switching between
;;two without multiple caches polluting projectile find file results

View File

@ -122,6 +122,11 @@ Additionally you can install the following other packages:
pip install pyls-mypy
#+END_SRC
If you've installed the language server and related packages as development
dependencies in a pipenv environment, you'll want to set the ~python-pipenv-activate~
config variable to ~t~. This activates your pipenv before enabling the
lsp backend.
* Additional tools
** Syntax checking
Syntax checking uses =flake8= package:
@ -346,7 +351,7 @@ Live coding is provided by the [[https://github.com/donkirkby/live-py-plugin][li
| Key binding | Description |
|-------------+---------------------|
| ~SPC m l~ | Toggle live-py-mode |
| ~SPC m l~ | Toggle live-py-mode |
** Other Python commands

View File

@ -18,6 +18,9 @@
"The backend to use for IDE features. Possible values are `anaconda'
and `lsp'.")
(defvar python-pipenv-activate nil
"If non-nil, activate pipenv before enabling backend")
(defvar python-enable-yapf-format-on-save nil
"If non-nil, automatically format code with YAPF on save.")

View File

@ -11,6 +11,7 @@
(defun spacemacs//python-setup-backend ()
"Conditionally setup python backend."
(when python-pipenv-activate (pipenv-activate))
(pcase python-backend
(`anaconda (spacemacs//python-setup-anaconda))
(`lsp (spacemacs//python-setup-lsp))))

View File

@ -46,6 +46,7 @@
(defun python/init-anaconda-mode ()
(use-package anaconda-mode
:if (eq python-backend 'anaconda)
:defer t
:init
(progn
@ -55,7 +56,7 @@
"gb" 'xref-pop-marker-stack
"gu" 'anaconda-mode-find-references)
(setq anaconda-mode-installation-directory
(concat spacemacs-cache-directory "anaconda-mode")))
(concat spacemacs-cache-directory "anaconda-mode")))
:config
(progn
;; new anaconda-mode (2018-06-03) removed `anaconda-view-mode-map' in
@ -72,7 +73,7 @@
(defadvice anaconda-mode-goto (before python/anaconda-mode-goto activate)
(evil--jumps-push))
(add-to-list 'spacemacs-jump-handlers-python-mode
'(anaconda-mode-find-definitions :async t)))))
'(anaconda-mode-find-definitions :async t)))))
(defun python/post-init-company ()
;; backend specific
@ -90,6 +91,7 @@
(defun python/init-company-anaconda ()
(use-package company-anaconda
:if (eq python-backend 'anaconda)
:defer t
;; see `spacemacs//python-setup-anaconda-company'
))
@ -99,9 +101,10 @@
:defer t
:init
(progn
(spacemacs/set-leader-keys-for-major-mode 'cython-mode
"hh" 'anaconda-mode-show-doc
"gu" 'anaconda-mode-find-references))))
(when (eq python-backend 'anaconda)
(spacemacs/set-leader-keys-for-major-mode 'cython-mode
"hh" 'anaconda-mode-show-doc
"gu" 'anaconda-mode-find-references)))))
(defun python/post-init-eldoc ()
(add-hook 'python-mode-local-vars-hook #'spacemacs//python-setup-eldoc))

View File

@ -41,7 +41,7 @@ https://github.com/emacs-lsp/lsp-javascript/issues/9#issuecomment-379515379"
;;format
"=b" #'lsp-format-buffer
;;goto
"gt" #'lsp-goto-type-definition
"gt" #'lsp-find-type-definition
"gk" #'spacemacs/lsp-avy-goto-word
"gK" #'spacemacs/lsp-avy-goto-symbol
"ge" #'lsp-ui-flycheck-list
@ -64,7 +64,7 @@ https://github.com/emacs-lsp/lsp-javascript/issues/9#issuecomment-379515379"
(defun spacemacs//lsp-bind-simple-navigation-functions (prefix-char)
(spacemacs/set-leader-keys-for-minor-mode 'lsp-mode
(concat prefix-char "i") #'lsp-goto-implementation
(concat prefix-char "i") #'lsp-find-implementation
(concat prefix-char "d") #'xref-find-definitions
(concat prefix-char "r") #'xref-find-references
(concat prefix-char "s") #'lsp-ui-find-workspace-symbol
@ -124,7 +124,7 @@ https://github.com/emacs-lsp/lsp-javascript/issues/9#issuecomment-379515379"
(defun spacemacs//lsp-define-custom-extension (layer-name nav-mode kind request &optional extra)
(let ((lsp-extension-fn (if (eq nav-mode "find")
'lsp-find-custom
'lsp-find-locations
'lsp-ui-peek-find-custom))
(extension-name (spacemacs//lsp-get-extension-name layer-name nav-mode kind))
(extension-descriptor (format (concat nav-mode " %s") (symbol-name kind))))

View File

@ -27,9 +27,7 @@
(add-hook 'lsp-after-open-hook (lambda ()
"Setup xref jump handler and declare keybinding prefixes"
(spacemacs//setup-lsp-jump-handler major-mode)
(spacemacs//lsp-declare-prefixes-for-mode major-mode)))
(evil-set-command-property 'lsp-goto-type-definition :jump t)
(evil-set-command-property 'lsp-goto-implementation :jump t))))
(spacemacs//lsp-declare-prefixes-for-mode major-mode))))))
(defun lsp/init-lsp-ui ()
(use-package lsp-ui