blob: 13708e826156ae0a51563bc4f2eff3797f5d3ee2 [file] [log] [blame] [view]
ljustene262c842017-04-12 08:29:041# Visual Studio Code Dev
2
3Visual Studio Code is a free, lightweight and powerful code editor for Windows,
4Mac and Linux, based on Electron/Chromium. It has built-in support for
5JavaScript, TypeScript and Node.js and a rich extension ecosystem that adds
6intellisense, debugging, syntax highlighting etc. for many languages (C++,
7Python, Go). It works without too much setup. Get started
8[here](https://code.visualstudio.com/docs).
9
10It is NOT a full-fledged IDE like Visual Studio. The two are completely
11separate products. The only commonality with Visual Studio is that both are
12from Microsoft.
13
14Here's what works well:
15
16* Editing code works well especially when you get used to the [keyboard
17 shortcuts](https://code.visualstudio.com/docs/customization/keybindings).
18 VS Code is very responsive and can handle even big code bases like Chromium.
19* Git integration is a blast. Built-in side-by-side view, local commit and
20 even extensions for
21 [history](https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory)
22 and
23 [blame view](https://marketplace.visualstudio.com/items?itemName=ryu1kn.annotator).
24* [Debugging](https://code.visualstudio.com/Docs/editor/debugging) works
25 well, even though startup times can be fairly high (~40 seconds with
26 gdb on Linux, much lower on Windows). You can step through code, inspect
27 variables, view call stacks for multiple threads etc.
28* Opening files and searching solution-wide works well now after having
29 problems in earlier versions.
30* Building works well. Build tools are easy to integrate. Warnings and errors
31 are displayed on a separate page and you can click to jump to the
32 corresponding line of code.
chaopengba312ce2017-02-12 03:38:2533
chaopengca285112017-03-02 15:39:0434[TOC]
35
ljustene262c842017-04-12 08:29:0436## Updating This Page
chaopengba312ce2017-02-12 03:38:2537
ljustene262c842017-04-12 08:29:0438Please keep this doc up-to-date. VS Code is still in active development and
39subject to changes. This doc is checked into the Chromium git repo, so if you
40make changes, read the [documentation
James Cook9d7e2192017-06-19 19:59:0941guidelines](https://chromium.googlesource.com/chromium/src/+/master/docs/documentation_guidelines.md)
ljustene262c842017-04-12 08:29:0442and [submit a change list](https://www.chromium.org/developers/contributing-code).
chaopengba312ce2017-02-12 03:38:2543
ljustene262c842017-04-12 08:29:0444All file paths and commands have been tested on Linux. Windows and Mac might
45require a slightly different setup (e.g. `Ctrl` -> `Cmd`). Please update this
46page accordingly.
chaopengba312ce2017-02-12 03:38:2547
ljustene262c842017-04-12 08:29:0448## Setup
chaopengba312ce2017-02-12 03:38:2549
ljustene262c842017-04-12 08:29:0450### Installation
chaopengba312ce2017-02-12 03:38:2551
ljustene262c842017-04-12 08:29:0452Follow the steps on https://code.visualstudio.com/docs/setup/setup-overview. To
53run it on Linux, just navigate to `chromium/src` folder and type `code .` in a
54terminal. The argument to `code` is the base directory of the workspace. VS
55Code does not require project or solution files. However, it does store
56workspace settings in a `.vscode` folder in your base directory.
chaopengba312ce2017-02-12 03:38:2557
Mounir Lamouri8202f362019-01-14 11:48:2658### Git on Windows
59
60If you only have the `depot_tools` Git installed on your machine, even though it
61is in your PATH, VS Code will ignore it as it seems to be looking for `git.exe`.
62You will have to add the following to your settings in order for the Git
63integration to work:
64
65```
66{
67 "git.path": "C:\\src\\depot_tools\\git.bat"
68}
69```
70
ljustene262c842017-04-12 08:29:0471### Useful Extensions
chaopengba312ce2017-02-12 03:38:2572
ljustene262c842017-04-12 08:29:0473Up to now, you have a basic version of VS Code without much language support.
74Next, we will install some useful extensions. Jump to the extensions window
75(`Ctrl+Shift+X`) and install these extensions, you will most likely use them
76every day:
chaopengba312ce2017-02-12 03:38:2577
ljustene262c842017-04-12 08:29:0478* ***C/C++*** -
James Cook9d7e2192017-06-19 19:59:0979 Code formatting, debugging, Intellisense.
ljustene262c842017-04-12 08:29:0480* ***Python*** -
81 Linting, intellisense, code formatting, refactoring, debugging, snippets.
James Cook9f7c73d2017-06-20 15:06:1982* ***Toggle Header/Source*** -
83 Toggles between .cc and .h with `F4`. The C/C++ extension supports this as
84 well through `Alt+O` but sometimes chooses the wrong file when there are
85 multiple files in the workspace that have the same name.
ljustene262c842017-04-12 08:29:0486* ***Protobuf support*** -
87 Syntax highlighting for .proto files.
88* ***you-complete-me*** -
89 YouCompleteMe code completion for VS Code. It works fairly well in Chromium.
90* ***Rewrap*** -
91 Wrap lines at 80 characters with `Alt+Q`.
chaopengba312ce2017-02-12 03:38:2592
ljustene262c842017-04-12 08:29:0493To install You-Complete-Me, enter these commands in a terminal:
chaopengba312ce2017-02-12 03:38:2594
95```
96$ git clone https://github.com/Valloric/ycmd.git ~/.ycmd
97$ cd ~/.ycmd
sangwoo.ko5fe74c732017-09-01 14:44:5698$ git submodule update --init --recursive
chaopengba312ce2017-02-12 03:38:2599$ ./build.py --clang-completer
100```
James Cookcb868402017-06-23 16:04:29101If it fails with "Your C++ compiler does NOT fully support C++11." but you know
102you have a good compiler, hack cpp/CMakeLists.txt to set CPP11_AVAILABLE true.
chaopengba312ce2017-02-12 03:38:25103
Victor Costan1a504072018-02-20 20:10:25104On Mac, replace the last command above with the following.
105
106```
107$ ./build.py --clang-completer --system-libclang
108```
109
ljustene262c842017-04-12 08:29:04110The following extensions might be useful for you as well:
chaopengba312ce2017-02-12 03:38:25111
ljustene262c842017-04-12 08:29:04112* ***Annotator*** -
113 Git blame view.
114* ***Git History (git log)*** -
115 Git history view.
116* ***chromium-codesearch*** -
117 Code search (CS) integration, see [Chromium Code
118 Search](https://cs.chromium.org/), in particular *open current line in CS*,
119 *show references* and *go to definition*. Very useful for existing code. By
120 design, won't work for code not checked in yet. Overrides default C/C++
121 functionality. Had some issues last time I tried (extensions stopped
122 working), so use with care.
123* ***change-case*** -
124 Quickly change the case of the current selection or current word.
125* ***Instant Markdown*** -
126 Instant markdown (.md) preview in your browser as you type. This document
127 was written with this extension!
128* ***Clang-Format*** -
129 Format your code using clang-format. The C/C++ extension already supports
130 format-on-save (see `C_Cpp.clang_format_formatOnSave` setting). This
131 extension adds the ability to format a document or the current selection on
132 demand.
chaopengba312ce2017-02-12 03:38:25133
ljustene262c842017-04-12 08:29:04134Also be sure to take a look at the
135[VS Code marketplace](https://marketplace.visualstudio.com/VSCode) to check out other
136useful extensions.
chaopengba312ce2017-02-12 03:38:25137
ljustene262c842017-04-12 08:29:04138### Color Scheme
139Press `Ctrl+Shift+P, color, Enter` to pick a color scheme for the editor. There
140are also tons of [color schemes available for download on the
141marketplace](https://marketplace.visualstudio.com/search?target=VSCode&category=Themes&sortBy=Downloads).
chaopengba312ce2017-02-12 03:38:25142
ljustene262c842017-04-12 08:29:04143### Usage Tips
144* `Ctrl+P` opens a search box to find and open a file.
145* `F1` or `Ctrl+Shift+P` opens a search box to find a command (e.g. Tasks: Run
146 Task).
147* `Ctrl+K, Ctrl+S` opens the key bindings editor.
148* ``Ctrl+` `` toggles the built-in terminal.
149* `Ctrl+Shift+M` toggles the problems view (linter warnings, compile errors
150 and warnings). You'll swicth a lot between terminal and problem view during
151 compilation.
152* `Alt+O` switches between the source/header file.
153* `Ctrl+G` jumps to a line.
154* `F12` jumps to the definition of the symbol at the cursor (also available on
155 right-click context menu).
156* `Shift+F12` or `F1, CodeSearchReferences, Return` shows all references of
157 the symbol at the cursor.
158* `F1, CodeSearchOpen, Return` opens the current file in Code Search.
159* `Ctrl+D` selects the word at the cursor. Pressing it multiple times
160 multi-selects the next occurrences, so typing in one types in all of them,
161 and `Ctrl+U` deselects the last occurrence.
162* `Ctrl+K, Z` enters Zen Mode, a fullscreen editing mode with nothing but the
163 current editor visible.
164* `Ctrl+X` without anything selected cuts the current line. `Ctrl+V` pastes
165 the line.
166
167## Setup For Chromium
168
169VS Code is configured via JSON files. This paragraph contains JSON configuration
170files that are useful for Chromium development, in particular. See [VS Code
171documentation](https://code.visualstudio.com/docs/customization/overview) for an
172introduction to VS Code customization.
173
174### Workspace Settings
Darwin Huang985c38a2018-11-21 19:24:13175Open the file [//tools/vscode/settings.json5](/tools/vscode/settings.json5),
176and check out the default settings there. Feel free to commit added or removed
177settings to enable better team development, or change settings locally to suit
178personal preference. Remember to replace `<full_path_to_your_home>`! To use
179these settings wholesale, enter the following commands into your terminal while
180at the src directory:
ljustene262c842017-04-12 08:29:04181```
Darwin Huang985c38a2018-11-21 19:24:13182$ mkdir .vscode/
183$ cp tools/vscode/settings.json5 .vscode/settings.json
ljustene262c842017-04-12 08:29:04184```
185
186### Tasks
187Next, we'll tell VS Code how to compile our code and how to read warnings and
Darwin Huang985c38a2018-11-21 19:24:13188errors from the build output. Open the file
189[//tools/vscode/tasks.json5](/tools/vscode/tasks.json5). This will provide 5
190tasks to do basic things. You might have to adjust the commands to your
191situation and needs. To use these settings wholesale, enter the following
192command into your terminal:
ljustene262c842017-04-12 08:29:04193```
Darwin Huang985c38a2018-11-21 19:24:13194$ cp tools/vscode/tasks.json5 .vscode/tasks.json
ljustene262c842017-04-12 08:29:04195```
196
197### Launch Commands
198Launch commands are the equivalent of `F5` in Visual Studio: They launch some
199program or a debugger. Optionally, they can run some task defined in
200`tasks.json`. Launch commands can be run from the debug view (`Ctrl+Shift+D`).
Darwin Huang985c38a2018-11-21 19:24:13201Open the file at [//tools/vscode/launch.json5](/tools/vscode/launch.json5) and
202adjust the example launch commands to your situation and needs. To use these
203settings wholesale, enter the following command into your terminal:
ljustene262c842017-04-12 08:29:04204```
Darwin Huang985c38a2018-11-21 19:24:13205$ cp tools/vscode/launch.json5 .vscode/launch.json
ljustene262c842017-04-12 08:29:04206```
207
208### Key Bindings
209To edit key bindings, press `Ctrl+K, Ctrl+S`. You'll see the defaults on the
210left and your overrides on the right stored in the file `keybindings.json`. To
211change a key binding, copy the corresponding key binding to the right. It's
212fairly self-explanatory.
213
214You can bind any command to a key, even commands specified by extensions like
215`CodeSearchOpen`. For instance, to bind `CodeSearchOpen` to `F2` to , simply add
216`{ "key": "F2", "command": "cs.open" },`.
217Note that the command title `CodeSearchOpen` won't work. You have to get the
218actual command name from the [package.json
219file](https://github.com/chaopeng/vscode-chromium-codesearch/blob/master/package.json)
220of the extension.
221
222If you are used to other editors, you can also install your favorite keymap.
223For instance, to install eclipse keymaps, install the
224`vscode-eclipse-keybindings` extension. More keymaps can be found
225[in the marketplace](https://marketplace.visualstudio.com/search?target=vscode&category=Keymaps).
226
Darwin Huang985c38a2018-11-21 19:24:13227Some key bindings that are likely to be useful for you are available at
228[//tools/vscode/keybindings.json5](/tools/vscode/keybindings.json5). Please
229take a look and adjust them to your situation and needs. To use these settings
230wholesale, enter the following command into your terminal:
ljustene262c842017-04-12 08:29:04231```
Darwin Huang985c38a2018-11-21 19:24:13232$ cp tools/vscode/keybindings.json5 .vscode/keybindings.json
ljustene262c842017-04-12 08:29:04233```
234
235### Tips
236
237#### The `out` folder
238Automatically generated code is put into a subfolder of out/, which means that
239these files are ignored by VS Code (see files.exclude above) and cannot be
Christian Dullweberd67c9b32018-04-03 08:30:42240opened e.g. from quick-open (`Ctrl+P`).
241As of version 1.21, VS Code does not support negated glob commands, but you can
242define a set of exclude pattern to include only out/Debug/gen:
Christian Dullweberbabb96e12018-05-28 14:00:14243```
Christian Dullweberd67c9b32018-04-03 08:30:42244"files.exclude": {
245 // Ignore build output folders. Except out/Debug/gen/
246 "out/[^D]*/": true,
247 "out/Debug/[^g]*": true,
248 "out/Debug/g[^e]*": true,
249 "out_*/**": true,
250},
Christian Dullweberbabb96e12018-05-28 14:00:14251```
Christian Dullweberd67c9b32018-04-03 08:30:42252
253Once it does, you can use
ljustene262c842017-04-12 08:29:04254```
255"!out/Debug/gen/**": true
256```
257in files.exclude instead of the symlink.
258
259#### Using VS Code as git editor
260Add `[core] editor = "code --wait"` to your `~/.gitconfig` file in order to use
261VS Code as editor for git commit messages etc. Note that the editor starts up
262significantly slower than nano or vim. To use VS Code as merge tool, add
263`[merge] tool = code`.
264
265#### Task Names
266Note that we named the tasks `1-build_chrome_debug`, `2-build_chrome_release`
267etc. This allows you to quickly execute tasks by pressing their number:
268Press `Ctrl+P` and enter `task <n>`, where `<n>` is the number of the task. You
269can also create a keyboard shortcut for running a task. `File > Preferences >
270Keyboard Shortcuts` and add `{ "key": "ctrl+r", "command":
271"workbench.action.tasks.runTask", "when": "!inDebugMode" }`. Then it's
272sufficient to press `Ctrl+R` and enter `<n>`.
273
274#### Working on Laptop
275Because autocomplete is provided by the You-Complete-Me extension, consider
276disabling C/C++ autocomplete and indexing to save battery. In addition, you
277might want to disable git status autorefresh as well.
chaopengca285112017-03-02 15:39:04278
279```
chaopeng5c66dfe2017-03-22 13:51:45280"git.autorefresh": false,
chaopengca285112017-03-02 15:39:04281"C_Cpp.autocomplete": "Disabled",
282"C_Cpp.addWorkspaceRootToIncludePath": false
283```
284
Jianpeng Chaob4048b82018-08-28 23:40:01285### Unable to open $File resource is not available when debugging Chromium on Linux
286Chromium [recently changed](https://docs.google.com/document/d/1OX4jY_bOCeNK7PNjVRuBQE9s6BQKS8XRNWGK8FEyh-E/edit?usp=sharing)
287the file path to be relative to the output dir. Check
288`gn args out/$dir --list` if `strip_absolute_paths_from_debug_symbols` is true (which is the default),
289set `cwd` to the output dir. otherwise, set `cwd` to `${workspaceRoot}`.
290
chaopengba312ce2017-02-12 03:38:25291### More
ljustene262c842017-04-12 08:29:04292More tips and tricks can be found
sangwoo.ko5fe74c732017-09-01 14:44:56293[here](https://github.com/Microsoft/vscode-tips-and-tricks/blob/master/README.md).