Install kak-lsp (git clone https://github.com/ul/kak-lsp; cd kak-lsp; cargo install --locked --force --path .; cp target/release/kak-lsp ~/.local/bin/
) (~/.local/bin
is in my PATH
)
~/.config/kak-lsp/kak-lsp.toml
snippet_support = false
verbosity = 2
[server]
# exit session if no requests were received during given period in seconds
# works only in unix sockets mode (-s/--session)
# set to 0 to disable
timeout = 1800 # seconds = 30 minutes
[language.c_cpp]
filetypes = ["c", "cpp"]
roots = [".ccls-root", ".ccls", "compile_commands.json"]
# ensure `ccls` is in a PATH directory, see https://github.com/MaskRay/ccls/wiki/Install#shell-script-wrapper
command = "ccls"
# kak-lsp does not support newText yet
args = ["--init={\"completion\":{\"detailedLabel\":false}}"]
Add the following to my ~/.config/kak/kakrc
:
eval %sh{kak-lsp --kakoune -s $kak_session}
hook global WinSetOption filetype=(c|cpp) %{
lsp-enable-window
}
.ccls
can be hierarchical (Project Setup · MaskRay/ccls Wiki · GitHub). I hope .ccls-root
has the highest priority but I am not sure whether that is the case.
cd /tmp; mkdir d; cd d
touch .ccls # an empty .ccls ensures all .c/.cc/.cpp files are indexed with the default clang command line options
touch a.cc
kak a.cc
Note about completion.detailedLabel: false
If I delete this initialization option, the completion items will look weird.
What ccls responds (to the textDocument/completion
request) is something like this:
{"label":"foo(int a, int b) -> void","kind":3,"detail":"","sortText":" ","filterText":"foo","insertTextFormat
":1,"textEdit":{"range":{"start":{"line":4,"character":4},"end":{"line":4,"character":7}},"newText":"foo"}
The client is expected to insert newText
instead of label
in the buffer.