Setup lsp server election process for cpp
This commit is contained in:
parent
86699f34fb
commit
e17f16590d
|
@ -21,15 +21,16 @@
|
||||||
;;
|
;;
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(eval-when-compile
|
(eval-when-compile
|
||||||
(require 'fpkg)
|
(require 'fpkg)
|
||||||
;; Language support
|
;; Language support
|
||||||
)
|
(require 'fg42/autocomplete)
|
||||||
|
(require 'fg42/langs/cpp))
|
||||||
|
|
||||||
(require 'server)
|
(require 'server)
|
||||||
(require 'fg42/modeline)
|
(require 'fg42/modeline)
|
||||||
|
|
||||||
(require 'fg42/autocomplete)
|
|
||||||
(require 'fg42/langs/cpp)
|
|
||||||
|
|
||||||
;; (require 'fg42/utils)
|
;; (require 'fg42/utils)
|
||||||
;; (require 'fg42/modeline)
|
;; (require 'fg42/modeline)
|
||||||
|
@ -93,6 +94,7 @@ external dependencies."
|
||||||
"Use ripgrep with projectile"
|
"Use ripgrep with projectile"
|
||||||
:after projectile)
|
:after projectile)
|
||||||
|
|
||||||
|
|
||||||
(use! helpful
|
(use! helpful
|
||||||
"Helpful is an alternative to the built-in Emacs help that provides much more
|
"Helpful is an alternative to the built-in Emacs help that provides much more
|
||||||
contextual information."
|
contextual information."
|
||||||
|
|
|
@ -32,9 +32,7 @@
|
||||||
"--pch-storage=memory"
|
"--pch-storage=memory"
|
||||||
"--background-index"
|
"--background-index"
|
||||||
"--cross-file-rename"
|
"--cross-file-rename"
|
||||||
"--completion-style=detailed"
|
"--completion-style=detailed")
|
||||||
"--malloc-trim"
|
|
||||||
)
|
|
||||||
"Arguments to pass to clangd.")
|
"Arguments to pass to clangd.")
|
||||||
|
|
||||||
(use! cmake-ts-mode
|
(use! cmake-ts-mode
|
||||||
|
@ -50,13 +48,29 @@
|
||||||
https://github.com/ninja-build/ninja/blob/master/misc/ninja-mode.el")
|
https://github.com/ninja-build/ninja/blob/master/misc/ninja-mode.el")
|
||||||
|
|
||||||
|
|
||||||
|
(defun fg42/c_cpp_ls (_)
|
||||||
|
"Return the proper lang server fo C/C++.
|
||||||
|
By default it will return `clangd' or `ccls' depends on what you have
|
||||||
|
installed. If you set `CPP_LS' env variable, then the value of that
|
||||||
|
var will be used instead. You can use `add-advice' to change the
|
||||||
|
return value of this function as well."
|
||||||
|
(let ((ls (getenv "CPP_LS")))
|
||||||
|
(if (null ls)
|
||||||
|
(eglot-alternatives `(("clangd" ,@fg42/clangd-args) ("ccls")))
|
||||||
|
(split-string ls " "))))
|
||||||
|
|
||||||
|
|
||||||
(defun fg42/c-ts-mode-setup ()
|
(defun fg42/c-ts-mode-setup ()
|
||||||
"A hook handler to setup cpp related configurations."
|
"A hook handler to setup cpp related configurations."
|
||||||
(message "[FG42][C/C++]: Make sure to setup clangd to fit your needs. For more info: https://clangd.llvm.org/config")
|
(message "[FG42][C/C++]: Make sure to setup clangd to fit your needs. For more info: https://clangd.llvm.org/config")
|
||||||
(setq-local company-backends
|
(setq-local company-backends
|
||||||
'((company-capf :with company-yasnippet) :separate
|
'((company-capf :with company-yasnippet) :separate
|
||||||
(company-keywords company-dabbrev company-ispell) :separate
|
(company-keywords company-dabbrev company-ispell) :separate
|
||||||
company-files)))
|
company-files))
|
||||||
|
;; We set eglot's autoload command to `eglot-ensure'
|
||||||
|
(eglot-ensure)
|
||||||
|
(add-to-list 'eglot-server-programs
|
||||||
|
`(c++-ts-mode . ,#'fg42/c_cpp_ls)))
|
||||||
|
|
||||||
|
|
||||||
(use! c-ts-mode
|
(use! c-ts-mode
|
||||||
|
@ -67,15 +81,7 @@ https://github.com/ninja-build/ninja/blob/master/misc/ninja-mode.el")
|
||||||
(add-to-list 'major-mode-remap-alist '(c++-mode . c++-ts-mode))
|
(add-to-list 'major-mode-remap-alist '(c++-mode . c++-ts-mode))
|
||||||
(add-to-list 'major-mode-remap-alist '(c-or-c++-mode . c-or-c++-ts-mode))
|
(add-to-list 'major-mode-remap-alist '(c-or-c++-mode . c-or-c++-ts-mode))
|
||||||
|
|
||||||
:config
|
|
||||||
;; Set the default lang server for C/C++ to clangd
|
|
||||||
(with-eval-after-load 'eglot
|
|
||||||
(add-to-list
|
|
||||||
'eglot-server-programs
|
|
||||||
`(c-mode c++-mode c-ts-mode c++-ts-mode . ("clangd" ,@fg42/clangd-args))))
|
|
||||||
|
|
||||||
:hook
|
:hook
|
||||||
(c++-ts-mode . eglot-ensure)
|
|
||||||
(c++-ts-mode . company-mode)
|
(c++-ts-mode . company-mode)
|
||||||
(c++-ts-mode . fg42/c-ts-mode-setup)
|
(c++-ts-mode . fg42/c-ts-mode-setup)
|
||||||
(c++-ts-mode . flyspell-prog-mode))
|
(c++-ts-mode . flyspell-prog-mode))
|
||||||
|
|
Loading…
Reference in New Issue