Skip to content

Instantly share code, notes, and snippets.

@zeta709
Last active February 10, 2023 04:54
Show Gist options
  • Save zeta709/38d436754670ae52ced4a3ea33c939a2 to your computer and use it in GitHub Desktop.
Save zeta709/38d436754670ae52ced4a3ea33c939a2 to your computer and use it in GitHub Desktop.
Setup ccls and coc.vim (Ubuntu 20.04.3 LTS)

⚠️ This guide is a WIP.

You can use either ccls or clangd. You don't need both. See ccls.md or clangd.md for ccls or clangd, respectively.

ccls

NOTE: This guide is a WIP.

Install

Using the prebuilt binary

sudo apt install ccls 

Building ccls

Prerequisites

sudo apt install clang libclang-dev
sudo apt install llvm-dev rapidjson-dev
sudo apt install cmake
# ninja (maybe optional)

Integration with coc.vim

See https://github.com/MaskRay/ccls/wiki/coc.nvim.

In Vim, type :CocConfig and:

{
  "languageserver": {
    "ccls": {
      "command": "ccls",
      "filetypes": ["c", "cpp", "cuda", "objc", "objcpp"],
      "rootPatterns": [".ccls-root", "compile_commands.json"],
      "initializationOptions": {
        "cache": {
          "directory": ".ccls-cache"
        },
        "client": {
          "snippetSupport": true
        }
      }
    }
  }
}

Misc.

Full indexing:

 ccls --index=.

coc.vim

NOTE: This guide is a WIP.

See https://github.com/neoclide/coc.nvim.

Install coc.vim

Install node:

export PREFIX="/home/user"
curl -sL install-node.vercel.app/lts | bash

.vimrc:

" vim-plug
Plug 'neoclide/coc.nvim', {'branch': 'release'}

Setup .vimrc

Jus copy the example in coc.nvim.

Additionally you can add set tagfunc=CocTagFunc in .vimrc.

Plugins

In Vim:

:CocInstall coc-pyright
:CocInstall coc-clangd

coc-clangd

In Vim, type :CocConfig and:

{
    "clangd.arguments": ["-j=10"]
}
  • -j: number of workers

Project setup

NOTE: This guide is a WIP.

It is the same for both ccls or clangd. See https://github.com/MaskRay/ccls/wiki/Project-Setup or https://clangd.llvm.org/installation.html#project-setup.

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=YES -S . -BDebug -DCMAKE_BUILD_TYPE=Debug # ...
# you can use either "-G 'Unix Makefiles'" or "-G Ninja" ------------------------^
# cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=YES
ln -s Debug/compile_commands.json .

In practice

Linux kernel

make defconfig
make
./scripts/clang-tools/gen_compile_commands.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment