blob: 99559663c4af2eb29ff4b695c614c58f7f41d534 [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
Jesse McKenna454b946f2020-05-08 18:23:1042If using Windows PowerShell, use the following command instead to set the
43output's encoding to UTF-8 (otherwise Clangd will hit "YAML:1:4: error: Got
44empty plain scalar" while parsing it).
45
46```
47tools/clang/scripts/generate_compdb.py -p out/Release | out-file -encoding utf8 compile_commands.json
48```
49
David Benjaminf676adb12019-05-07 07:19:10503. Optional: build chrome normally. This ensures generated headers exist and are
51up-to-date. clangd will still work without this step, but it may give errors or
52inaccurate results for files which depend on generated headers.
53
54```
55ninja -C out/Release chrome
56```
57
584. Use clangd in your favourite editor, see detailed [instructions](
Haojian Wuaa891f172019-04-05 14:56:5259https://clang.llvm.org/extra/clangd/Installation.html#getting-started-with-clangd).
60
61## Index
62
63By default, clangd only knows the files you are currently editing. To provide
64project-wide code navigations (e.g. find references), clangd neesds a
65project-wide index.
66
67You can pass an **experimental** `--background-index` command line argument to
68clangd, clangd will incrementally build an index of Chromium in the background.
69Note: the first index time may take hours (for reference, it took 2~3 hours on
70a 48-core, 64GB machine).
71
72A full index of Chromium (including v8, blink) takes ~550 MB disk space and ~2.7
73GB memory in clangd.
74
75## Questions
76
77If you have any questions, reach out to clangd-dev@lists.llvm.org.