Merge pull request #3020 from gagbo/feature/eglot-support
Add support for eglot as LSP client implementation
This commit is contained in:
commit
75b6e11f56
24 changed files with 454 additions and 235 deletions
|
@ -16,6 +16,8 @@
|
|||
- [[#configure][Configure]]
|
||||
- [[#project-compile-settings][Project compile settings]]
|
||||
- [[#known-issues-with-bear-on-macos][Known issues with bear on macOS]]
|
||||
- [[#appendix][Appendix]]
|
||||
- [[#eglot-specific-bindings][Eglot specific bindings]]
|
||||
|
||||
* Description
|
||||
This module adds support for the C-family of languages: C, C++, and Objective-C.
|
||||
|
@ -42,7 +44,7 @@ This module adds support for the C-family of languages: C, C++, and Objective-C.
|
|||
+ [[https://github.com/jimhourihan/glsl-mode][glsl-mode]]*
|
||||
+ [[https://github.com/guidoschmidt/company-glsl][company-glsl]]*
|
||||
+ =+lsp=
|
||||
+ [[https://github.com/MaskRay/emacs-ccls][ccls]]
|
||||
+ [[https://github.com/MaskRay/emacs-ccls][ccls]] if =:tools lsp= has *no* =+eglot= flag
|
||||
+ =-lsp=
|
||||
+ [[https://github.com/Sarcasm/irony-mode][irony]]
|
||||
+ [[https://github.com/ikirill/irony-eldoc][irony-eldoc]]
|
||||
|
@ -173,3 +175,12 @@ bear gmake
|
|||
Additional info:
|
||||
+ [[https://github.com/rizsotto/Bear/issues/158][Empty compilation database with compiler in /usr/local]]
|
||||
+ [[https://github.com/rizsotto/Bear/issues/152][Workaround for 'Empty compilation database on OS X Captain]]
|
||||
|
||||
* Appendix
|
||||
** Eglot specific bindings
|
||||
When using =+lsp= and =:tools (lsp +eglot)=, lsp-mode is replaced with eglot,
|
||||
and an additional function to get inheritance type hierarchy is added
|
||||
| Binding | Description |
|
||||
|------------------------------+--------------------------------------------------|
|
||||
| ~<localleader> c t~ | ~Display inheritance type hierarchy (upwards)~ |
|
||||
| ~<prefix> <localleader> c t~ | ~Display inheritance type hierarchy (downwards)~ |
|
||||
|
|
|
@ -122,6 +122,34 @@ simpler."
|
|||
#'rtags-imenu
|
||||
#'imenu)))
|
||||
|
||||
;; Eglot specific helper, courtesy of MaskRay
|
||||
;;;###autoload
|
||||
(defun +cc/eglot-ccls-inheritance-hierarchy (&optional derived)
|
||||
"Show inheritance hierarchy for the thing at point.
|
||||
If DERIVED is non-nil (interactively, with prefix argument), show
|
||||
the children of class at point."
|
||||
(interactive "P")
|
||||
(if-let* ((res (jsonrpc-request
|
||||
(eglot--current-server-or-lose)
|
||||
:$ccls/inheritance
|
||||
(append (eglot--TextDocumentPositionParams)
|
||||
`(:derived ,(if derived t :json-false))
|
||||
'(:levels 100) '(:hierarchy t))))
|
||||
(tree (list (cons 0 res))))
|
||||
(with-help-window "*ccls inheritance*"
|
||||
(with-current-buffer standard-output
|
||||
(while tree
|
||||
(pcase-let ((`(,depth . ,node) (pop tree)))
|
||||
(cl-destructuring-bind (&key uri range) (plist-get node :location)
|
||||
(insert (make-string depth ?\ ) (plist-get node :name) "\n")
|
||||
(make-text-button (+ (point-at-bol 0) depth) (point-at-eol 0)
|
||||
'action (lambda (_arg)
|
||||
(interactive)
|
||||
(find-file (eglot--uri-to-path uri))
|
||||
(goto-char (car (eglot--range-region range)))))
|
||||
(cl-loop for child across (plist-get node :children)
|
||||
do (push (cons (1+ depth) child) tree)))))))
|
||||
(eglot--error "Hierarchy unavailable")))
|
||||
|
||||
;;
|
||||
;; Hooks
|
||||
|
|
|
@ -236,9 +236,25 @@ If rtags or rdm aren't available, fail silently instead of throwing a breaking e
|
|||
(setq-local company-lsp-cache-candidates nil)
|
||||
(lsp!))))
|
||||
|
||||
(when (and (featurep! +lsp) (featurep! :tools lsp +eglot))
|
||||
;; Map eglot specific helper
|
||||
(map! :localleader
|
||||
:after cc-mode
|
||||
:map c++-mode-map
|
||||
:n :desc "Show type inheritance hierarchy" "ct" #'+cc/eglot-ccls-inheritance-hierarchy)
|
||||
|
||||
;; NOTE : This setting is untested yet
|
||||
(after! eglot
|
||||
;; IS-MAC custom configuration
|
||||
(when IS-MAC
|
||||
(add-to-list 'eglot-workspace-configuration
|
||||
((:ccls . ((:clang . ,(list :extraArgs ["-isystem/Library/Developer/CommandLineTools/usr/include/c++/v1"
|
||||
"-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
|
||||
"-isystem/usr/local/include"]
|
||||
:resourceDir (string-trim (shell-command-to-string "clang -print-resource-dir")))))))))))
|
||||
|
||||
(use-package! ccls
|
||||
:when (featurep! +lsp)
|
||||
:when (and (featurep! +lsp) (not (featurep! :tools lsp +eglot)))
|
||||
:after lsp
|
||||
:init
|
||||
(after! projectile
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
:pin "404cd0694a")))
|
||||
|
||||
(if (featurep! +lsp)
|
||||
(package! ccls :pin "17ec7bb4cf")
|
||||
(unless (featurep! :tools lsp +eglot)
|
||||
;; ccls package is necessary only for lsp-mode.
|
||||
(package! ccls :pin "17ec7bb4cf"))
|
||||
(when (package! irony :pin "5f75fc0c92")
|
||||
(package! irony-eldoc :pin "0df5831eaa")
|
||||
(when (featurep! :checkers syntax)
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
(when (featurep! +dante)
|
||||
(package! dante :pin "4955bc7363")
|
||||
(package! attrap :pin "4cf3e4a162"))
|
||||
(when (or (featurep! +lsp)
|
||||
(when (or (and (featurep! +lsp) (not (featurep! :tools lsp +eglot)))
|
||||
(featurep! +ghcide))
|
||||
(package! lsp-haskell :pin "582fa27c88"))
|
||||
|
|
|
@ -22,7 +22,10 @@ called.")
|
|||
python-indent-guess-indent-offset-verbose nil)
|
||||
|
||||
(when (featurep! +lsp)
|
||||
(add-hook 'python-mode-local-vars-hook #'lsp!))
|
||||
(add-hook 'python-mode-local-vars-hook #'lsp!)
|
||||
;; Use "mspyls" in eglot if in PATH
|
||||
(when (executable-find "Microsoft.Python.LanguageServer")
|
||||
(set-eglot-client! 'python-mode '("Microsoft.Python.LanguageServer"))))
|
||||
:config
|
||||
(set-repl-handler! 'python-mode #'+python/open-repl :persist t)
|
||||
(set-docsets! 'python-mode "Python 3" "NumPy" "SciPy")
|
||||
|
@ -98,6 +101,7 @@ called.")
|
|||
"Enable `anaconda-mode' if `lsp-mode' is absent and
|
||||
`python-shell-interpreter' is present."
|
||||
(unless (or (bound-and-true-p lsp-mode)
|
||||
(bound-and-true-p eglot--managed-mode)
|
||||
(bound-and-true-p lsp--buffer-deferred)
|
||||
(not (executable-find python-shell-interpreter)))
|
||||
(anaconda-mode +1))))
|
||||
|
@ -286,7 +290,7 @@ called.")
|
|||
|
||||
|
||||
(use-package! lsp-python-ms
|
||||
:when (featurep! +lsp)
|
||||
:when (and (featurep! +lsp) (not (featurep! :tools lsp +eglot)))
|
||||
:after lsp-clients
|
||||
:preface
|
||||
(after! python
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
(package! flycheck-cython :pin "ecc4454d35")))
|
||||
|
||||
;; LSP
|
||||
(when (featurep! +lsp)
|
||||
(when (and (featurep! +lsp) (not (featurep! :tools lsp +eglot)))
|
||||
(package! lsp-python-ms :pin "5d0c799099"))
|
||||
|
||||
;; Programming environment
|
||||
|
|
|
@ -27,6 +27,11 @@
|
|||
(after! rustic-flycheck
|
||||
(add-to-list 'flycheck-checkers 'rustic-clippy)))
|
||||
|
||||
(when (featurep! +lsp)
|
||||
(if (featurep! :tools lsp +eglot)
|
||||
(setq rustic-lsp-client 'eglot)
|
||||
(setq rustic-lsp-client 'lsp-mode)))
|
||||
|
||||
(map! :map rustic-mode-map
|
||||
:localleader
|
||||
(:prefix ("b" . "build")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue