I'm trying to use lsp-mode
(together with company-lsp
) for auto completion in C++. According to the docs[0], recent lsp-mode
includes clangd support, so I should be all set when I do (require 'lsp-clients)
. However, lsp-mode
can't find any clients to handle c++-mode
, and from the documentation I can't find any way of debugging this.
The Main Problem
Here is the (almost) complete init.el
file, which I have produced as a minimal example:
(unless (package-installed-p 'lsp-mode)
(package-install 'lsp-mode))
(unless (package-installed-p 'company-lsp)
(package-install 'company-lsp))
(unless (package-installed-p 'lsp-ui)
(package-install 'lsp-ui))
(require 'company-lsp)
(require 'lsp-mode)
(require 'lsp-ui)
(require 'lsp-clients)
(push 'company-lsp company-backends)
(add-hook 'after-init-hook 'global-company-mode)
(add-hook 'lsp-mode-hook 'lsp-ui-mode)
(when (string= (system-name) "i11pcbarth")
(setq lsp-clients-clangd-executable "/usr/lib/llvm-7/bin/clangd"))
(add-hook 'c++-mode-hook 'lsp)
Now, when I open a C++ file, I get the message
Unable to find client(s) handling c++-mode. Make sure you have required lsp-clients.el or proper extension.
Since I already do (require 'lsp-clients)
above, I'm not sure what to do.
Further Weirdness
Looking into lsp-clients.el
, I can see that it should define e.g. the variable lsp-clients-clangd-executable
. However, the variable seems not to be defined (I can't find it using C-h v
). So, I assume that for some reason, the (require 'lsp-clients)
from my init.el
did not work. Thus, I require the file again (by typing (require 'lsp-clients)
into the current buffer and calling eval-last-sexp
). Now, C-h v
sees the variable lsp-clients-clangd-executable
. However, M-x lsp RET
(to enable lsp-mode
) again only gives me the error message about no client that handles c++-mode
.
[0] https://github.com/emacs-lsp/lsp-clangd/blob/master/README.md