Setup lsp server election process for cpp

This commit is contained in:
Sameer Rahmani 2024-03-24 21:56:25 +00:00
parent 86699f34fb
commit e17f16590d
Signed by: lxsameer
GPG Key ID: 8741FACBF412FFA5
2 changed files with 23 additions and 15 deletions

View File

@ -21,15 +21,16 @@
;;
;;; Commentary:
;;; Code:
(eval-when-compile
(require 'fpkg)
;; Language support
)
(require 'fg42/autocomplete)
(require 'fg42/langs/cpp))
(require 'server)
(require 'fg42/modeline)
(require 'fg42/autocomplete)
(require 'fg42/langs/cpp)
;; (require 'fg42/utils)
;; (require 'fg42/modeline)
@ -93,6 +94,7 @@ external dependencies."
"Use ripgrep with projectile"
:after projectile)
(use! helpful
"Helpful is an alternative to the built-in Emacs help that provides much more
contextual information."

View File

@ -32,9 +32,7 @@
"--pch-storage=memory"
"--background-index"
"--cross-file-rename"
"--completion-style=detailed"
"--malloc-trim"
)
"--completion-style=detailed")
"Arguments to pass to clangd.")
(use! cmake-ts-mode
@ -50,13 +48,29 @@
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 ()
"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")
(setq-local company-backends
'((company-capf :with company-yasnippet) :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
@ -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-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
(c++-ts-mode . eglot-ensure)
(c++-ts-mode . company-mode)
(c++-ts-mode . fg42/c-ts-mode-setup)
(c++-ts-mode . flyspell-prog-mode))