ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 1 | # Visual Studio Code Dev |
| 2 | |
| 3 | Visual Studio Code is a free, lightweight and powerful code editor for Windows, |
| 4 | Mac and Linux, based on Electron/Chromium. It has built-in support for |
| 5 | JavaScript, TypeScript and Node.js and a rich extension ecosystem that adds |
| 6 | intellisense, debugging, syntax highlighting etc. for many languages (C++, |
| 7 | Python, Go). It works without too much setup. Get started |
| 8 | [here](https://code.visualstudio.com/docs). |
| 9 | |
| 10 | It is NOT a full-fledged IDE like Visual Studio. The two are completely |
| 11 | separate products. The only commonality with Visual Studio is that both are |
| 12 | from Microsoft. |
| 13 | |
| 14 | Here'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. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 33 | |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 34 | [TOC] |
| 35 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 36 | ## Updating This Page |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 37 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 38 | Please keep this doc up-to-date. VS Code is still in active development and |
| 39 | subject to changes. This doc is checked into the Chromium git repo, so if you |
| 40 | make changes, read the [documentation |
James Cook | 9d7e219 | 2017-06-19 19:59:09 | [diff] [blame] | 41 | guidelines](https://chromium.googlesource.com/chromium/src/+/master/docs/documentation_guidelines.md) |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 42 | and [submit a change list](https://www.chromium.org/developers/contributing-code). |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 43 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 44 | All file paths and commands have been tested on Linux. Windows and Mac might |
| 45 | require a slightly different setup (e.g. `Ctrl` -> `Cmd`). Please update this |
| 46 | page accordingly. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 47 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 48 | ## Setup |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 49 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 50 | ### Installation |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 51 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 52 | Follow the steps on https://code.visualstudio.com/docs/setup/setup-overview. To |
| 53 | run it on Linux, just navigate to `chromium/src` folder and type `code .` in a |
| 54 | terminal. The argument to `code` is the base directory of the workspace. VS |
| 55 | Code does not require project or solution files. However, it does store |
| 56 | workspace settings in a `.vscode` folder in your base directory. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 57 | |
Mounir Lamouri | 1679feab | 2019-01-25 19:30:03 | [diff] [blame^] | 58 | |
| 59 | ### Fixes for Known Issues |
| 60 | |
| 61 | #### Git on Windows |
Mounir Lamouri | 8202f36 | 2019-01-14 11:48:26 | [diff] [blame] | 62 | |
| 63 | If you only have the `depot_tools` Git installed on your machine, even though it |
| 64 | is in your PATH, VS Code will ignore it as it seems to be looking for `git.exe`. |
| 65 | You will have to add the following to your settings in order for the Git |
| 66 | integration to work: |
| 67 | |
Mounir Lamouri | 1679feab | 2019-01-25 19:30:03 | [diff] [blame^] | 68 | ```json |
Mounir Lamouri | 8202f36 | 2019-01-14 11:48:26 | [diff] [blame] | 69 | { |
| 70 | "git.path": "C:\\src\\depot_tools\\git.bat" |
| 71 | } |
| 72 | ``` |
| 73 | |
Mounir Lamouri | 1679feab | 2019-01-25 19:30:03 | [diff] [blame^] | 74 | #### Rendering of underscore on Linux |
| 75 | |
| 76 | As mentioned in [#35901](https://github.com/Microsoft/vscode/issues/35901), VS |
| 77 | Code will not show underscore (`_`) properly on Linux by default. You can work |
| 78 | around this issue by forcing another font such as the default `monospace` or |
| 79 | changing the font size in your settings: |
| 80 | |
| 81 | ```json |
| 82 | { |
| 83 | // If you want to use the default "monospace" font: |
| 84 | //"terminal.integrated.fontFamily": "monospace" |
| 85 | // If you would rather just increase the size of the font: |
| 86 | //"terminal.integrated.fontSize": 15 |
| 87 | // If you would rather decrease the size of the font: |
| 88 | //"terminal.integrated.fontSize": 15 |
| 89 | } |
| 90 | ``` |
| 91 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 92 | ### Useful Extensions |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 93 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 94 | Up to now, you have a basic version of VS Code without much language support. |
| 95 | Next, we will install some useful extensions. Jump to the extensions window |
| 96 | (`Ctrl+Shift+X`) and install these extensions, you will most likely use them |
| 97 | every day: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 98 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 99 | * ***C/C++*** - |
James Cook | 9d7e219 | 2017-06-19 19:59:09 | [diff] [blame] | 100 | Code formatting, debugging, Intellisense. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 101 | * ***Python*** - |
| 102 | Linting, intellisense, code formatting, refactoring, debugging, snippets. |
James Cook | 9f7c73d | 2017-06-20 15:06:19 | [diff] [blame] | 103 | * ***Toggle Header/Source*** - |
| 104 | Toggles between .cc and .h with `F4`. The C/C++ extension supports this as |
| 105 | well through `Alt+O` but sometimes chooses the wrong file when there are |
| 106 | multiple files in the workspace that have the same name. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 107 | * ***Protobuf support*** - |
| 108 | Syntax highlighting for .proto files. |
| 109 | * ***you-complete-me*** - |
| 110 | YouCompleteMe code completion for VS Code. It works fairly well in Chromium. |
| 111 | * ***Rewrap*** - |
| 112 | Wrap lines at 80 characters with `Alt+Q`. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 113 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 114 | To install You-Complete-Me, enter these commands in a terminal: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 115 | |
| 116 | ``` |
| 117 | $ git clone https://github.com/Valloric/ycmd.git ~/.ycmd |
| 118 | $ cd ~/.ycmd |
sangwoo.ko | 5fe74c73 | 2017-09-01 14:44:56 | [diff] [blame] | 119 | $ git submodule update --init --recursive |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 120 | $ ./build.py --clang-completer |
| 121 | ``` |
James Cook | cb86840 | 2017-06-23 16:04:29 | [diff] [blame] | 122 | If it fails with "Your C++ compiler does NOT fully support C++11." but you know |
| 123 | you have a good compiler, hack cpp/CMakeLists.txt to set CPP11_AVAILABLE true. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 124 | |
Victor Costan | 1a50407 | 2018-02-20 20:10:25 | [diff] [blame] | 125 | On Mac, replace the last command above with the following. |
| 126 | |
| 127 | ``` |
| 128 | $ ./build.py --clang-completer --system-libclang |
| 129 | ``` |
| 130 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 131 | The following extensions might be useful for you as well: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 132 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 133 | * ***Annotator*** - |
| 134 | Git blame view. |
| 135 | * ***Git History (git log)*** - |
| 136 | Git history view. |
| 137 | * ***chromium-codesearch*** - |
| 138 | Code search (CS) integration, see [Chromium Code |
| 139 | Search](https://cs.chromium.org/), in particular *open current line in CS*, |
| 140 | *show references* and *go to definition*. Very useful for existing code. By |
| 141 | design, won't work for code not checked in yet. Overrides default C/C++ |
| 142 | functionality. Had some issues last time I tried (extensions stopped |
| 143 | working), so use with care. |
| 144 | * ***change-case*** - |
| 145 | Quickly change the case of the current selection or current word. |
| 146 | * ***Instant Markdown*** - |
| 147 | Instant markdown (.md) preview in your browser as you type. This document |
| 148 | was written with this extension! |
| 149 | * ***Clang-Format*** - |
| 150 | Format your code using clang-format. The C/C++ extension already supports |
| 151 | format-on-save (see `C_Cpp.clang_format_formatOnSave` setting). This |
| 152 | extension adds the ability to format a document or the current selection on |
| 153 | demand. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 154 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 155 | Also be sure to take a look at the |
| 156 | [VS Code marketplace](https://marketplace.visualstudio.com/VSCode) to check out other |
| 157 | useful extensions. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 158 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 159 | ### Color Scheme |
| 160 | Press `Ctrl+Shift+P, color, Enter` to pick a color scheme for the editor. There |
| 161 | are also tons of [color schemes available for download on the |
| 162 | marketplace](https://marketplace.visualstudio.com/search?target=VSCode&category=Themes&sortBy=Downloads). |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 163 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 164 | ### Usage Tips |
| 165 | * `Ctrl+P` opens a search box to find and open a file. |
| 166 | * `F1` or `Ctrl+Shift+P` opens a search box to find a command (e.g. Tasks: Run |
| 167 | Task). |
| 168 | * `Ctrl+K, Ctrl+S` opens the key bindings editor. |
| 169 | * ``Ctrl+` `` toggles the built-in terminal. |
| 170 | * `Ctrl+Shift+M` toggles the problems view (linter warnings, compile errors |
| 171 | and warnings). You'll swicth a lot between terminal and problem view during |
| 172 | compilation. |
| 173 | * `Alt+O` switches between the source/header file. |
| 174 | * `Ctrl+G` jumps to a line. |
| 175 | * `F12` jumps to the definition of the symbol at the cursor (also available on |
| 176 | right-click context menu). |
| 177 | * `Shift+F12` or `F1, CodeSearchReferences, Return` shows all references of |
| 178 | the symbol at the cursor. |
| 179 | * `F1, CodeSearchOpen, Return` opens the current file in Code Search. |
| 180 | * `Ctrl+D` selects the word at the cursor. Pressing it multiple times |
| 181 | multi-selects the next occurrences, so typing in one types in all of them, |
| 182 | and `Ctrl+U` deselects the last occurrence. |
| 183 | * `Ctrl+K, Z` enters Zen Mode, a fullscreen editing mode with nothing but the |
| 184 | current editor visible. |
| 185 | * `Ctrl+X` without anything selected cuts the current line. `Ctrl+V` pastes |
| 186 | the line. |
| 187 | |
| 188 | ## Setup For Chromium |
| 189 | |
| 190 | VS Code is configured via JSON files. This paragraph contains JSON configuration |
| 191 | files that are useful for Chromium development, in particular. See [VS Code |
| 192 | documentation](https://code.visualstudio.com/docs/customization/overview) for an |
| 193 | introduction to VS Code customization. |
| 194 | |
| 195 | ### Workspace Settings |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 196 | Open the file [//tools/vscode/settings.json5](/tools/vscode/settings.json5), |
| 197 | and check out the default settings there. Feel free to commit added or removed |
| 198 | settings to enable better team development, or change settings locally to suit |
| 199 | personal preference. Remember to replace `<full_path_to_your_home>`! To use |
| 200 | these settings wholesale, enter the following commands into your terminal while |
| 201 | at the src directory: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 202 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 203 | $ mkdir .vscode/ |
| 204 | $ cp tools/vscode/settings.json5 .vscode/settings.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 205 | ``` |
| 206 | |
| 207 | ### Tasks |
| 208 | Next, we'll tell VS Code how to compile our code and how to read warnings and |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 209 | errors from the build output. Open the file |
| 210 | [//tools/vscode/tasks.json5](/tools/vscode/tasks.json5). This will provide 5 |
| 211 | tasks to do basic things. You might have to adjust the commands to your |
| 212 | situation and needs. To use these settings wholesale, enter the following |
| 213 | command into your terminal: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 214 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 215 | $ cp tools/vscode/tasks.json5 .vscode/tasks.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 216 | ``` |
| 217 | |
| 218 | ### Launch Commands |
| 219 | Launch commands are the equivalent of `F5` in Visual Studio: They launch some |
| 220 | program or a debugger. Optionally, they can run some task defined in |
| 221 | `tasks.json`. Launch commands can be run from the debug view (`Ctrl+Shift+D`). |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 222 | Open the file at [//tools/vscode/launch.json5](/tools/vscode/launch.json5) and |
| 223 | adjust the example launch commands to your situation and needs. To use these |
| 224 | settings wholesale, enter the following command into your terminal: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 225 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 226 | $ cp tools/vscode/launch.json5 .vscode/launch.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 227 | ``` |
| 228 | |
| 229 | ### Key Bindings |
| 230 | To edit key bindings, press `Ctrl+K, Ctrl+S`. You'll see the defaults on the |
| 231 | left and your overrides on the right stored in the file `keybindings.json`. To |
| 232 | change a key binding, copy the corresponding key binding to the right. It's |
| 233 | fairly self-explanatory. |
| 234 | |
| 235 | You can bind any command to a key, even commands specified by extensions like |
| 236 | `CodeSearchOpen`. For instance, to bind `CodeSearchOpen` to `F2` to , simply add |
| 237 | `{ "key": "F2", "command": "cs.open" },`. |
| 238 | Note that the command title `CodeSearchOpen` won't work. You have to get the |
| 239 | actual command name from the [package.json |
| 240 | file](https://github.com/chaopeng/vscode-chromium-codesearch/blob/master/package.json) |
| 241 | of the extension. |
| 242 | |
| 243 | If you are used to other editors, you can also install your favorite keymap. |
| 244 | For instance, to install eclipse keymaps, install the |
| 245 | `vscode-eclipse-keybindings` extension. More keymaps can be found |
| 246 | [in the marketplace](https://marketplace.visualstudio.com/search?target=vscode&category=Keymaps). |
| 247 | |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 248 | Some key bindings that are likely to be useful for you are available at |
| 249 | [//tools/vscode/keybindings.json5](/tools/vscode/keybindings.json5). Please |
| 250 | take a look and adjust them to your situation and needs. To use these settings |
| 251 | wholesale, enter the following command into your terminal: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 252 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 253 | $ cp tools/vscode/keybindings.json5 .vscode/keybindings.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 254 | ``` |
| 255 | |
| 256 | ### Tips |
| 257 | |
| 258 | #### The `out` folder |
| 259 | Automatically generated code is put into a subfolder of out/, which means that |
| 260 | these files are ignored by VS Code (see files.exclude above) and cannot be |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 261 | opened e.g. from quick-open (`Ctrl+P`). |
| 262 | As of version 1.21, VS Code does not support negated glob commands, but you can |
| 263 | define a set of exclude pattern to include only out/Debug/gen: |
Christian Dullweber | babb96e1 | 2018-05-28 14:00:14 | [diff] [blame] | 264 | ``` |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 265 | "files.exclude": { |
| 266 | // Ignore build output folders. Except out/Debug/gen/ |
| 267 | "out/[^D]*/": true, |
| 268 | "out/Debug/[^g]*": true, |
| 269 | "out/Debug/g[^e]*": true, |
| 270 | "out_*/**": true, |
| 271 | }, |
Christian Dullweber | babb96e1 | 2018-05-28 14:00:14 | [diff] [blame] | 272 | ``` |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 273 | |
| 274 | Once it does, you can use |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 275 | ``` |
| 276 | "!out/Debug/gen/**": true |
| 277 | ``` |
| 278 | in files.exclude instead of the symlink. |
| 279 | |
| 280 | #### Using VS Code as git editor |
| 281 | Add `[core] editor = "code --wait"` to your `~/.gitconfig` file in order to use |
| 282 | VS Code as editor for git commit messages etc. Note that the editor starts up |
| 283 | significantly slower than nano or vim. To use VS Code as merge tool, add |
| 284 | `[merge] tool = code`. |
| 285 | |
| 286 | #### Task Names |
| 287 | Note that we named the tasks `1-build_chrome_debug`, `2-build_chrome_release` |
| 288 | etc. This allows you to quickly execute tasks by pressing their number: |
| 289 | Press `Ctrl+P` and enter `task <n>`, where `<n>` is the number of the task. You |
| 290 | can also create a keyboard shortcut for running a task. `File > Preferences > |
| 291 | Keyboard Shortcuts` and add `{ "key": "ctrl+r", "command": |
| 292 | "workbench.action.tasks.runTask", "when": "!inDebugMode" }`. Then it's |
| 293 | sufficient to press `Ctrl+R` and enter `<n>`. |
| 294 | |
| 295 | #### Working on Laptop |
| 296 | Because autocomplete is provided by the You-Complete-Me extension, consider |
| 297 | disabling C/C++ autocomplete and indexing to save battery. In addition, you |
| 298 | might want to disable git status autorefresh as well. |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 299 | |
| 300 | ``` |
chaopeng | 5c66dfe | 2017-03-22 13:51:45 | [diff] [blame] | 301 | "git.autorefresh": false, |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 302 | "C_Cpp.autocomplete": "Disabled", |
| 303 | "C_Cpp.addWorkspaceRootToIncludePath": false |
| 304 | ``` |
| 305 | |
Jianpeng Chao | b4048b8 | 2018-08-28 23:40:01 | [diff] [blame] | 306 | ### Unable to open $File resource is not available when debugging Chromium on Linux |
| 307 | Chromium [recently changed](https://docs.google.com/document/d/1OX4jY_bOCeNK7PNjVRuBQE9s6BQKS8XRNWGK8FEyh-E/edit?usp=sharing) |
| 308 | the file path to be relative to the output dir. Check |
| 309 | `gn args out/$dir --list` if `strip_absolute_paths_from_debug_symbols` is true (which is the default), |
| 310 | set `cwd` to the output dir. otherwise, set `cwd` to `${workspaceRoot}`. |
| 311 | |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 312 | ### More |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 313 | More tips and tricks can be found |
sangwoo.ko | 5fe74c73 | 2017-09-01 14:44:56 | [diff] [blame] | 314 | [here](https://github.com/Microsoft/vscode-tips-and-tricks/blob/master/README.md). |