blob: e4e3df0b289059f747fddef213f4fc3aac0c4ddf [file] [log] [blame] [view]
Haojian Wuaa891f172019-04-05 14:56:521# Clangd
2
3## Introduction
4
5[clangd](https://clang.llvm.org/extra/clangd/) is a clang-based [language server](http://langserver.org/).
6It brings IDE features (e.g. diagnostics, code completion, code navigations) to
7your editor.
8
9## Getting clangd
10
11See [instructions](https://clang.llvm.org/extra/clangd/Installation.html#installing-clangd).
12
13**Googlers:** clangd has been installed on your glinux by default, just use
14`/usr/bin/clangd`.
15
16Alternative: use the following command to build clangd from LLVM source, and you
17will get the binary at
18`out/Release/tools/clang/third_party/llvm/build/bin/clangd`.
19
20```
21tools/clang/scripts/build_clang_tools_extra.py --fetch out/Release clangd
22```
23
24## Setting Up
25
David Benjaminf676adb12019-05-07 07:19:10261. Make sure generated ninja files are up-to-date.
Haojian Wuaa891f172019-04-05 14:56:5227
28```
David Benjaminf676adb12019-05-07 07:19:1029gn gen out/Release
Haojian Wuaa891f172019-04-05 14:56:5230```
31
322. Generate the compilation database, clangd needs it to know how to build a
33source file.
34
35```
36tools/clang/scripts/generate_compdb.py -p out/Release > compile_commands.json
37```
38
39Note: the compilation database is not re-generated automatically, you'd need to
40regenerate it manually when you have new files checked in.
41
David Benjaminf676adb12019-05-07 07:19:10423. Optional: build chrome normally. This ensures generated headers exist and are
43up-to-date. clangd will still work without this step, but it may give errors or
44inaccurate results for files which depend on generated headers.
45
46```
47ninja -C out/Release chrome
48```
49
504. Use clangd in your favourite editor, see detailed [instructions](
Haojian Wuaa891f172019-04-05 14:56:5251https://clang.llvm.org/extra/clangd/Installation.html#getting-started-with-clangd).
52
53## Index
54
55By default, clangd only knows the files you are currently editing. To provide
56project-wide code navigations (e.g. find references), clangd neesds a
57project-wide index.
58
59You can pass an **experimental** `--background-index` command line argument to
60clangd, clangd will incrementally build an index of Chromium in the background.
61Note: the first index time may take hours (for reference, it took 2~3 hours on
62a 48-core, 64GB machine).
63
64A full index of Chromium (including v8, blink) takes ~550 MB disk space and ~2.7
65GB memory in clangd.
66
67## Questions
68
69If you have any questions, reach out to [email protected].