A configuration for an Emacs LSP client for Clang-based languages using clangd as the language server.
clangd
lsp-mode
Since clangd
is part of clang-tools-extra
since Clang 5, it can be
installed by all the same methods for installing Clang 5 or later.
With macOs, the easiest way is to install via Homebrew.
brew install llvm
(use-package lsp-clangd
:load-path
"<path-to-lsp-clangd>"
:init
(add-hook 'c-mode--hook #'lsp-clangd-c-enable)
(add-hook 'c++-mode-hook #'lsp-clangd-c++-enable)
(add-hook 'objc-mode-hook #'lsp-clangd-objc-enable))
Install lsp-mode
via some suitable method and clone this repository
to a suitable path, e.g. <path-to-lsp-clangd>
.
(add-to-list 'load-path "<path-to-lsp-clangd>")
(require 'lsp-clangd)
(add-hook 'c-mode--hook #'lsp-clangd-c-enable)
(add-hook 'c++-mode-hook #'lsp-clangd-c++-enable)
(add-hook 'objc-mode-hook #'lsp-clangd-objc-enable)