2015-11-15 12:21:53 +00:00
|
|
|
|
;;; funcs.el --- C/C++ Layer functions File for Spacemacs
|
|
|
|
|
;;
|
2018-01-04 07:00:25 +00:00
|
|
|
|
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
2015-11-15 12:21:53 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
|
;;
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
2018-08-30 20:03:11 +00:00
|
|
|
|
(require 'cl-lib)
|
|
|
|
|
(require 'subr-x)
|
|
|
|
|
|
2018-05-15 20:54:03 +00:00
|
|
|
|
(defun spacemacs//c-toggle-auto-newline ()
|
|
|
|
|
"Toggle auto-newline."
|
|
|
|
|
(c-toggle-auto-newline 1))
|
|
|
|
|
|
2018-01-06 07:44:33 +00:00
|
|
|
|
|
2017-08-01 15:36:18 +00:00
|
|
|
|
;; clang
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/clang-format-function (&optional style)
|
|
|
|
|
"Format the current function with clang-format according to STYLE."
|
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(c-mark-function)
|
|
|
|
|
(clang-format (region-beginning) (region-end) style)
|
|
|
|
|
(deactivate-mark) ; If the function is already formatted, then remove the mark
|
|
|
|
|
(message "Formatted function %s" (c-defun-name))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/clang-format-region-or-buffer (&optional style)
|
|
|
|
|
"Format the current region or buffer with clang-format according to STYLE."
|
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(if (region-active-p)
|
|
|
|
|
(progn
|
2018-01-06 06:29:45 +00:00
|
|
|
|
(clang-format-region (region-beginning) (region-end) style)
|
2017-08-01 15:36:18 +00:00
|
|
|
|
(message "Formatted region"))
|
|
|
|
|
(progn
|
2018-01-06 06:29:45 +00:00
|
|
|
|
(clang-format-buffer style)
|
2017-08-01 15:36:18 +00:00
|
|
|
|
(message "Formatted buffer %s" (buffer-name))))))
|
|
|
|
|
|
2017-04-09 21:55:50 +00:00
|
|
|
|
(defun spacemacs//clang-format-on-save ()
|
2017-08-01 15:36:18 +00:00
|
|
|
|
"Format the current buffer with clang-format on save when
|
|
|
|
|
`c-c++-enable-clang-format-on-save' is non-nil."
|
2017-04-09 21:50:21 +00:00
|
|
|
|
(when c-c++-enable-clang-format-on-save
|
2018-01-03 00:45:17 +00:00
|
|
|
|
(spacemacs/clang-format-region-or-buffer)))
|
2017-04-09 21:50:21 +00:00
|
|
|
|
|
2017-04-09 21:55:50 +00:00
|
|
|
|
(defun spacemacs/clang-format-on-save ()
|
2017-08-01 15:36:18 +00:00
|
|
|
|
"Add before-save hook for clang-format."
|
2017-04-09 21:55:50 +00:00
|
|
|
|
(add-hook 'before-save-hook 'spacemacs//clang-format-on-save nil t))
|
2017-04-07 09:21:05 +00:00
|
|
|
|
|
2017-04-09 21:55:50 +00:00
|
|
|
|
(defun spacemacs/company-more-than-prefix-guesser ()
|
|
|
|
|
(spacemacs/c-c++-load-clang-args)
|
2017-01-02 05:39:04 +00:00
|
|
|
|
(company-clang-guess-prefix))
|
|
|
|
|
|
2015-11-15 12:21:53 +00:00
|
|
|
|
;; Based on the Sarcasm/irony-mode compilation database code.
|
2017-04-09 21:55:50 +00:00
|
|
|
|
(defun spacemacs/company-find-clang-complete-file ()
|
2015-11-15 12:21:53 +00:00
|
|
|
|
(when buffer-file-name
|
|
|
|
|
(let ((dir (locate-dominating-file buffer-file-name ".clang_complete")))
|
|
|
|
|
(when dir
|
|
|
|
|
(concat (file-name-as-directory dir) ".clang_complete")))))
|
|
|
|
|
|
|
|
|
|
;; Based on the Sarcasm/irony-mode compilation database code.
|
2017-04-09 21:55:50 +00:00
|
|
|
|
(defun spacemacs/company-load-clang-complete-file (cc-file)
|
2015-11-15 12:21:53 +00:00
|
|
|
|
"Load the flags from CC-FILE, one flag per line."
|
|
|
|
|
(let ((invocation-dir (expand-file-name (file-name-directory cc-file)))
|
|
|
|
|
(case-fold-search nil)
|
2017-08-06 07:45:21 +00:00
|
|
|
|
(include-regex "\\(-I\\|-isystem\\|-iquote\\|-idirafter\\)\\s-*\\(\\S-+\\)")
|
2015-11-15 12:21:53 +00:00
|
|
|
|
compile-flags)
|
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(insert-file-contents cc-file)
|
|
|
|
|
;; Replace relative paths with absolute paths (by @trishume)
|
|
|
|
|
;; (goto-char (point-min))
|
2017-08-06 07:45:21 +00:00
|
|
|
|
(while (re-search-forward include-regex nil t)
|
2015-11-15 12:21:53 +00:00
|
|
|
|
(replace-match (format "%s%s" (match-string 1)
|
2017-04-09 21:55:50 +00:00
|
|
|
|
(expand-file-name (match-string 2)
|
|
|
|
|
invocation-dir))))
|
2015-11-15 12:21:53 +00:00
|
|
|
|
;; Turn lines into a list
|
|
|
|
|
(setq compile-flags
|
|
|
|
|
;; remove whitespaces at the end of each line, if any
|
|
|
|
|
(mapcar #'(lambda (line)
|
|
|
|
|
(if (string-match "[ \t]+$" line)
|
|
|
|
|
(replace-match "" t t line)
|
|
|
|
|
line))
|
|
|
|
|
(split-string (buffer-string) "\n" t))))
|
|
|
|
|
compile-flags))
|
|
|
|
|
|
2017-08-06 07:45:21 +00:00
|
|
|
|
(defun spacemacs//c-c++-get-standard-include-paths (lang)
|
|
|
|
|
"Returns the default system header include paths for LANG if gcc is on the
|
|
|
|
|
system and supports it, else returns a default set of include paths."
|
|
|
|
|
(let* ((start "#include <...> search starts here:")
|
|
|
|
|
(end "End of search list.")
|
|
|
|
|
(gcc-tmplt "echo | gcc -x%s -E -v - 2>&1")
|
|
|
|
|
(sed-tmplt " | sed -n '/%s/,/%s/{/%s/b;/%s/b;p}' | sed -e 's/^ *//g'")
|
|
|
|
|
(template (concat gcc-tmplt sed-tmplt))
|
|
|
|
|
(inc-dirs-cmd (format template lang start end start end))
|
|
|
|
|
(inc-dirs (split-string (shell-command-to-string inc-dirs-cmd)
|
|
|
|
|
"\n" t)))
|
|
|
|
|
(if (and inc-dirs (every 'file-exists-p inc-dirs))
|
|
|
|
|
inc-dirs
|
|
|
|
|
'("/usr/include" "/usr/local/include"))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//filter-and-substring (flags filter-prefix substr-index)
|
|
|
|
|
"Returns all the strings in FLAGS starting with FILTER-PREFIX. The returned
|
|
|
|
|
strings are substringed from SUBSTR-INDEX inclusive to the end of the string."
|
|
|
|
|
(mapcar (lambda (f) (substring f substr-index))
|
|
|
|
|
(remove-if-not (lambda (f) (string-prefix-p filter-prefix f))
|
|
|
|
|
flags)))
|
|
|
|
|
|
2017-04-09 21:55:50 +00:00
|
|
|
|
(defun spacemacs/c-c++-load-clang-args ()
|
2015-12-21 14:37:26 +00:00
|
|
|
|
"Sets the arguments for company-clang, the system paths for company-c-headers
|
|
|
|
|
and the arguments for flyckeck-clang based on a project-specific text file."
|
2015-11-15 12:21:53 +00:00
|
|
|
|
(unless company-clang-arguments
|
2017-04-09 21:55:50 +00:00
|
|
|
|
(let* ((cc-file (spacemacs/company-find-clang-complete-file))
|
|
|
|
|
(flags (if cc-file
|
|
|
|
|
(spacemacs/company-load-clang-complete-file cc-file)
|
|
|
|
|
'()))
|
2017-08-06 07:45:21 +00:00
|
|
|
|
(i-paths (spacemacs//filter-and-substring flags
|
|
|
|
|
"-I" 2))
|
|
|
|
|
(iquote-paths (spacemacs//filter-and-substring flags
|
|
|
|
|
"-iquote" 7))
|
|
|
|
|
(isystem-paths (spacemacs//filter-and-substring flags
|
|
|
|
|
"-isystem" 8))
|
|
|
|
|
(idirafter-paths (spacemacs//filter-and-substring flags
|
|
|
|
|
"-idirafter" 10)))
|
2015-11-15 12:21:53 +00:00
|
|
|
|
(setq-local company-clang-arguments flags)
|
2017-08-06 07:45:21 +00:00
|
|
|
|
(setq-local flycheck-clang-args flags)
|
|
|
|
|
(setq-local company-c-headers-path-user
|
|
|
|
|
(append '(".")
|
|
|
|
|
iquote-paths))
|
2017-04-09 21:55:50 +00:00
|
|
|
|
(setq-local company-c-headers-path-system
|
2017-08-06 07:45:21 +00:00
|
|
|
|
(append i-paths
|
|
|
|
|
isystem-paths
|
|
|
|
|
(when (string-equal major-mode "c++-mode")
|
|
|
|
|
(spacemacs//c-c++-get-standard-include-paths "c++"))
|
|
|
|
|
(when (string-equal major-mode "c-mode")
|
|
|
|
|
(spacemacs//c-c++-get-standard-include-paths "c"))
|
|
|
|
|
idirafter-paths)))))
|
2017-05-14 17:20:10 +00:00
|
|
|
|
|
2019-05-10 17:40:06 +00:00
|
|
|
|
|
|
|
|
|
;; cpp-auto-include
|
|
|
|
|
|
|
|
|
|
(defalias 'spacemacs/c++-organize-includes 'cpp-auto-include)
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//c++-organize-includes-on-save ()
|
|
|
|
|
"Organize the includes on save when `c++-enable-organize-includes-on-save'
|
|
|
|
|
is non-nil."
|
|
|
|
|
(when c++-enable-organize-includes-on-save
|
|
|
|
|
(spacemacs/c++-organize-includes)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/c++-organize-includes-on-save ()
|
|
|
|
|
"Add before-save hook for c++-organize-includes."
|
|
|
|
|
(add-hook 'before-save-hook
|
|
|
|
|
#'spacemacs//c++-organize-includes-on-save nil t))
|
|
|
|
|
|
2018-01-06 07:44:33 +00:00
|
|
|
|
|
|
|
|
|
;; rtags
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/c-c++-use-rtags (&optional useFileManager)
|
2018-01-12 05:45:03 +00:00
|
|
|
|
"Return non-nil if rtags function should be used."
|
|
|
|
|
;; this function is used to fallback on gtags function if rtags is not
|
|
|
|
|
;; supported. So if gtags layer is not used we disable the fallback by
|
|
|
|
|
;; returning always t.
|
|
|
|
|
(or (not (configuration-layer/layer-used-p 'gtags))
|
|
|
|
|
(and (rtags-executable-find "rc")
|
|
|
|
|
(cond ((not (gtags-get-rootpath)) t)
|
|
|
|
|
((and (not (eq major-mode 'c++-mode))
|
|
|
|
|
(not (eq major-mode 'c-mode))) (rtags-has-filemanager))
|
|
|
|
|
(useFileManager (rtags-has-filemanager))
|
|
|
|
|
(t (rtags-is-indexed))))))
|
2018-01-06 07:44:33 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs/c-c++-tags-find-symbol-at-point (&optional prefix)
|
|
|
|
|
(interactive "P")
|
|
|
|
|
(if (and (not (rtags-find-symbol-at-point prefix))
|
|
|
|
|
rtags-last-request-not-indexed)
|
|
|
|
|
(gtags-find-tag)))
|
|
|
|
|
|
2018-12-30 21:10:02 +00:00
|
|
|
|
(defun spacemacs/c-c++-tags-find-references-at-point (&optional prefix)
|
2018-01-06 07:44:33 +00:00
|
|
|
|
(interactive "P")
|
2018-12-30 21:10:02 +00:00
|
|
|
|
(if (and (not (rtags-find-references-at-point prefix))
|
2018-01-06 07:44:33 +00:00
|
|
|
|
rtags-last-request-not-indexed)
|
|
|
|
|
(gtags-find-rtag)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/c-c++-tags-find-symbol ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(call-interactively (if (spacemacs/c-c++-use-rtags)
|
|
|
|
|
'rtags-find-symbol 'gtags-find-symbol)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/c-c++-tags-find-references ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(call-interactively (if (spacemacs/c-c++-use-rtags)
|
|
|
|
|
'rtags-find-references 'gtags-find-rtag)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/c-c++-tags-find-file ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(call-interactively (if (spacemacs/c-c++-use-rtags t)
|
|
|
|
|
'rtags-find-file 'gtags-find-file)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/c-c++-tags-imenu ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(call-interactively (if (spacemacs/c-c++-use-rtags t)
|
|
|
|
|
'rtags-imenu 'idomenu)))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; lsp
|
|
|
|
|
(defun spacemacs//c-c++-lsp-enabled ()
|
|
|
|
|
"Return true if one or other of the lsp backends is enabled"
|
|
|
|
|
(member c-c++-backend c-c++-lsp-backends))
|
|
|
|
|
|
|
|
|
|
;; -- BEGIN helper functions for common configuration of cquery and ccls backends
|
|
|
|
|
(defun spacemacs//c-c++-lsp-backend ()
|
|
|
|
|
"Return a string representation of the LSP backend specified by the `c-c++-backend' configuration variable, without the `lsp-' prefix."
|
|
|
|
|
(ecase c-c++-backend
|
|
|
|
|
('lsp-ccls "ccls")
|
|
|
|
|
('lsp-cquery "cquery")))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//c-c++-lsp-string (prefix suffix)
|
|
|
|
|
(concat prefix (spacemacs//c-c++-lsp-backend) suffix))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//c-c++-lsp-symbol (prefix suffix)
|
|
|
|
|
"Return a symbol for the LSP backend specified by the `c-c++-backend' configuration variable."
|
|
|
|
|
(intern (spacemacs//c-c++-lsp-string prefix suffix)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//c-c++-lsp-call-function (prefix suffix &rest args)
|
|
|
|
|
(apply (spacemacs//c-c++-lsp-symbol prefix suffix) args))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//c-c++-lsp-funcall-interactively (prefix suffix &rest args)
|
|
|
|
|
(funcall-interactively (spacemacs//c-c++-lsp-symbol prefix suffix) args))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//c-c++-lsp-funcall-interactively-no-args (prefix suffix)
|
|
|
|
|
(funcall-interactively (spacemacs//c-c++-lsp-symbol prefix suffix)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//c-c++-lsp-set-symbol (prefix suffix value)
|
|
|
|
|
(set (spacemacs//c-c++-lsp-symbol prefix suffix) (symbol-value value)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//c-c++-lsp-set-config (param prefix suffix)
|
|
|
|
|
(when (symbol-value param) (spacemacs//c-c++-lsp-set-symbol prefix suffix param)))
|
|
|
|
|
|
2018-12-11 21:59:25 +00:00
|
|
|
|
(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))))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
;; -- 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
|
|
|
|
|
(spacemacs//c-c++-lsp-define-extensions)
|
|
|
|
|
(spacemacs//c-c++-lsp-wrap-functions)
|
|
|
|
|
(setq-default flycheck-disabled-checkers '(c/c++-clang c/c++-gcc))
|
|
|
|
|
|
2018-12-11 21:59:25 +00:00
|
|
|
|
(spacemacs//c-c++-lsp-apply-config "executable" "initialization-options" "args" "project-whitelist" "project-blacklist" "sem-highlight-method")
|
2018-11-22 10:56:35 +00:00
|
|
|
|
|
2018-08-30 20:03:11 +00:00
|
|
|
|
(if (eq c-c++-lsp-cache-dir nil)
|
|
|
|
|
(progn
|
|
|
|
|
(setq c-c++-lsp-cache-dir (file-truename(concat "~/.emacs.d/.cache/" (symbol-name c-c++-backend))))
|
|
|
|
|
(message (concat "c-c++: No c-c++-lsp-cache-dir specified: defaulting to " c-c++-lsp-cache-dir))))
|
|
|
|
|
|
2018-11-22 10:56:35 +00:00
|
|
|
|
(ecase c-c++-backend
|
2018-12-11 21:59:25 +00:00
|
|
|
|
('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"))))
|
2018-11-22 10:56:35 +00:00
|
|
|
|
('lsp-ccls (setq ccls-initialization-options
|
2018-12-11 21:59:25 +00:00
|
|
|
|
(if c-c++-lsp-initialization-options
|
2019-02-26 08:38:45 +00:00
|
|
|
|
(append c-c++-lsp-initialization-options `(:cache (:directory ,c-c++-lsp-cache-dir)))
|
|
|
|
|
`(:cache (:directory ,c-c++-lsp-cache-dir ))))))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
|
|
|
|
|
(when c-c++-lsp-sem-highlight-rainbow
|
|
|
|
|
(unless c-c++-lsp-sem-highlight-method
|
|
|
|
|
(progn
|
|
|
|
|
(setq c-c++-lsp-sem-highlight-method 'font-lock)
|
|
|
|
|
(message "c-c++: No semantic highlight method specified. Defaulting to `font-lock'.")))
|
|
|
|
|
(ecase c-c++-backend
|
|
|
|
|
('lsp-cquery (cquery-use-default-rainbow-sem-highlight))
|
|
|
|
|
('lsp-ccls (ccls-use-default-rainbow-sem-highlight))))
|
|
|
|
|
|
|
|
|
|
(dolist (mode c-c++-modes)
|
|
|
|
|
(spacemacs//c-c++-lsp-bind-keys-for-mode mode))
|
|
|
|
|
|
|
|
|
|
(evil-set-initial-state '(spacemacs//c-c++-lsp-symbol nil "-tree-mode") 'emacs)
|
|
|
|
|
;;evil-record-macro keybinding clobbers q in cquery-tree-mode-map for some reason?
|
2019-04-14 12:44:51 +00:00
|
|
|
|
(evil-make-overriding-map (symbol-value (spacemacs//c-c++-lsp-symbol nil "-tree-mode-map")))
|
|
|
|
|
|
|
|
|
|
(if (configuration-layer/layer-used-p 'dap)
|
|
|
|
|
(progn
|
|
|
|
|
(require 'dap-gdb-lldb)
|
|
|
|
|
(dolist (mode c-c++-modes)
|
|
|
|
|
(spacemacs/dap-bind-keys-for-mode mode)))
|
|
|
|
|
(message "`dap' layer is not installed, please add `dap' layer to your dotfile."))))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs//c-c++-lsp-wrap-functions ()
|
|
|
|
|
"Wrap navigation functions for the LSP backend specified by the `c-c++-backend' configuration variable."
|
2018-11-22 10:56:35 +00:00
|
|
|
|
(defun c-c++/call-hierarchy () (interactive) (spacemacs//c-c++-lsp-funcall-interactively nil "-call-hierarchy"))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
(defun c-c++/call-hierarchy-inv () (interactive) (spacemacs//c-c++-lsp-funcall-interactively nil "-call-hierarchy" t))
|
|
|
|
|
(defun c-c++/inheritance-hierarchy () (interactive) (spacemacs//c-c++-lsp-funcall-interactively nil "-inheritance-hierarchy"))
|
|
|
|
|
(defun c-c++/inheritance-hierarchy-inv () (interactive) (spacemacs//c-c++-lsp-funcall-interactively nil "-inheritance-hierarchy" t))
|
|
|
|
|
(defun c-c++/member-hierarchy () (interactive) (spacemacs//c-c++-lsp-funcall-interactively-no-args nil "-member-hierarchy"))
|
|
|
|
|
(defun c-c++/preprocess-file () (interactive) (spacemacs//c-c++-lsp-funcall-interactively nil "-preprocess-file"))
|
|
|
|
|
(defun c-c++/refresh-index () (interactive) ()
|
|
|
|
|
(ecase c-c++-backend
|
|
|
|
|
('lsp-cquery (cquery-freshen-index))
|
|
|
|
|
('lsp-ccls (ccls-reload)))))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//c-c++-lsp-bind-keys-for-mode (mode)
|
|
|
|
|
"Bind LSP backend functions for the specified mode."
|
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode mode
|
|
|
|
|
;; backend
|
|
|
|
|
"bf" #'c-c++/refresh-index
|
|
|
|
|
"bp" #'c-c++/preprocess-file
|
|
|
|
|
;; goto
|
|
|
|
|
"gf" 'find-file-at-point
|
|
|
|
|
"gF" 'ffap-other-window
|
|
|
|
|
;; hierarchy
|
|
|
|
|
"ghc" #'c-c++/call-hierarchy
|
|
|
|
|
"ghC" #'c-c++/call-hierarchy-inv
|
|
|
|
|
"ghi" #'c-c++/inheritance-hierarchy
|
|
|
|
|
"ghI" #'c-c++/inheritance-hierarchy-inv
|
|
|
|
|
;; members
|
|
|
|
|
"gmh" #'c-c++/member-hierarchy)
|
|
|
|
|
|
2018-11-22 10:56:35 +00:00
|
|
|
|
;; goto/peek
|
2018-08-30 20:03:11 +00:00
|
|
|
|
(spacemacs/lsp-bind-extensions-for-mode mode "c-c++"
|
|
|
|
|
"&" 'refs-address
|
|
|
|
|
"R" 'refs-read
|
|
|
|
|
"W" 'refs-write
|
|
|
|
|
"c" 'callers
|
|
|
|
|
"C" 'callees
|
|
|
|
|
"v" 'vars
|
|
|
|
|
"hb" 'base) ;;Replace this with lsp-goto-implementation in lsp-layer?
|
|
|
|
|
|
|
|
|
|
(when (eq c-c++-backend 'lsp-ccls)
|
|
|
|
|
(spacemacs/lsp-bind-extensions-for-mode mode "c-c++"
|
2018-11-22 10:56:35 +00:00
|
|
|
|
"hd" 'derived
|
|
|
|
|
"mt" 'member-types
|
2018-08-30 20:03:11 +00:00
|
|
|
|
"mf" 'member-functions
|
|
|
|
|
"mv" 'member-vars)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//c-c++-lsp-define-extensions ()
|
|
|
|
|
"Wrap some backend-specific extensions using the find functions provided by lsp-mode and lsp-ui"
|
|
|
|
|
(spacemacs//c-c++-lsp-call-function "spacemacs//c-c++-lsp-define-" "-extensions")
|
|
|
|
|
|
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'vars
|
2018-11-11 21:12:06 +00:00
|
|
|
|
(spacemacs//c-c++-lsp-string "$" "/vars")))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
|
2018-11-11 21:12:06 +00:00
|
|
|
|
(defun spacemacs//c-c++-lsp-define-cquery-extensions ()
|
2018-08-30 20:03:11 +00:00
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'refs-address
|
|
|
|
|
"textDocument/references"
|
|
|
|
|
'(plist-put (lsp--text-document-position-params) :context '(:role 128)))
|
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'refs-read
|
|
|
|
|
"textDocument/references"
|
|
|
|
|
'(plist-put (lsp--text-document-position-params) :context '(:role 8)))
|
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'refs-write
|
|
|
|
|
"textDocument/references"
|
2018-11-11 21:12:06 +00:00
|
|
|
|
'(plist-put (lsp--text-document-position-params) :context '(:role 16)))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'callers "$cquery/callers")
|
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'callees "$cquery/callers" '(:callee t))
|
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'base "$cquery/base"))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//c-c++-lsp-define-ccls-extensions ()
|
2018-11-11 21:12:06 +00:00
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'refs-address "textDocument/references" '(:role 128))
|
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'refs-read "textDocument/references" '(:role 8))
|
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'refs-write "textDocument/references" '(:role 16))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'callers "$ccls/call")
|
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'callees "$ccls/call" '(:callee t))
|
2018-11-11 21:12:06 +00:00
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'base "$ccls/inheritance")
|
2018-08-30 20:03:11 +00:00
|
|
|
|
;;ccls features without a cquery analogue...
|
2018-11-22 10:56:35 +00:00
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'derived "$ccls/inheritance" '(:derived t))
|
2018-11-11 21:12:06 +00:00
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'member-types "$ccls/member" `(:kind 2))
|
2018-08-30 20:03:11 +00:00
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'member-functions "$ccls/member" `(:kind 3))
|
|
|
|
|
(spacemacs/lsp-define-extensions "c-c++" 'member-vars "$ccls/member" `(:kind 0)))
|