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++, |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 7 | Python, Go, Java). It works without too much setup. Get started |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 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. |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 33 | * VSCode Remote, which allows you to edit remotely-hosted code, and even run |
| 34 | computationally expensive plugins like vscode-clangd on the remote |
| 35 | server/workstation (see the [Remote section](#Remote)). Great for working- |
James Cook | 3a41598 | 2020-03-25 18:47:38 | [diff] [blame^] | 36 | from-home. (Googlers: See [go/vscode-remote](http://go/vscode-remote)].) |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 37 | |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 38 | [TOC] |
| 39 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 40 | ## Updating This Page |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 41 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 42 | Please keep this doc up-to-date. VS Code is still in active development and |
| 43 | subject to changes. This doc is checked into the Chromium git repo, so if you |
| 44 | make changes, read the [documentation |
James Cook | 9d7e219 | 2017-06-19 19:59:09 | [diff] [blame] | 45 | guidelines](https://chromium.googlesource.com/chromium/src/+/master/docs/documentation_guidelines.md) |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 46 | and [submit a change list](https://www.chromium.org/developers/contributing-code). |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 47 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 48 | All file paths and commands have been tested on Linux. Windows and Mac might |
| 49 | require a slightly different setup (e.g. `Ctrl` -> `Cmd`). Please update this |
| 50 | page accordingly. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 51 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 52 | ## Setup |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 53 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 54 | ### Installation |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 55 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 56 | Follow the steps on https://code.visualstudio.com/docs/setup/setup-overview. To |
| 57 | run it on Linux, just navigate to `chromium/src` folder and type `code .` in a |
| 58 | terminal. The argument to `code` is the base directory of the workspace. VS |
| 59 | Code does not require project or solution files. However, it does store |
| 60 | workspace settings in a `.vscode` folder in your base directory. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 61 | |
Mounir Lamouri | 1679feab | 2019-01-25 19:30:03 | [diff] [blame] | 62 | ### Fixes for Known Issues |
| 63 | |
| 64 | #### Git on Windows |
Mounir Lamouri | 8202f36 | 2019-01-14 11:48:26 | [diff] [blame] | 65 | |
| 66 | If you only have the `depot_tools` Git installed on your machine, even though it |
| 67 | is in your PATH, VS Code will ignore it as it seems to be looking for `git.exe`. |
| 68 | You will have to add the following to your settings in order for the Git |
| 69 | integration to work: |
| 70 | |
Mounir Lamouri | 1679feab | 2019-01-25 19:30:03 | [diff] [blame] | 71 | ```json |
Mounir Lamouri | 8202f36 | 2019-01-14 11:48:26 | [diff] [blame] | 72 | { |
| 73 | "git.path": "C:\\src\\depot_tools\\git.bat" |
| 74 | } |
| 75 | ``` |
| 76 | |
Mounir Lamouri | 1679feab | 2019-01-25 19:30:03 | [diff] [blame] | 77 | #### Rendering of underscore on Linux |
| 78 | |
| 79 | As mentioned in [#35901](https://github.com/Microsoft/vscode/issues/35901), VS |
| 80 | Code will not show underscore (`_`) properly on Linux by default. You can work |
| 81 | around this issue by forcing another font such as the default `monospace` or |
| 82 | changing the font size in your settings: |
| 83 | |
| 84 | ```json |
| 85 | { |
| 86 | // If you want to use the default "monospace" font: |
| 87 | //"terminal.integrated.fontFamily": "monospace" |
| 88 | // If you would rather just increase the size of the font: |
| 89 | //"terminal.integrated.fontSize": 15 |
| 90 | // If you would rather decrease the size of the font: |
Mounir Lamouri | a1e5a9e | 2019-07-30 20:06:00 | [diff] [blame] | 91 | //"terminal.integrated.fontSize": 13 |
Mounir Lamouri | 1679feab | 2019-01-25 19:30:03 | [diff] [blame] | 92 | } |
| 93 | ``` |
| 94 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 95 | ### Useful Extensions |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 96 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 97 | Up to now, you have a basic version of VS Code without much language support. |
| 98 | Next, we will install some useful extensions. Jump to the extensions window |
| 99 | (`Ctrl+Shift+X`) and install these extensions, you will most likely use them |
| 100 | every day: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 101 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 102 | * ***C/C++*** - |
James Cook | 9d7e219 | 2017-06-19 19:59:09 | [diff] [blame] | 103 | Code formatting, debugging, Intellisense. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 104 | * ***Python*** - |
| 105 | Linting, intellisense, code formatting, refactoring, debugging, snippets. |
James Cook | 9f7c73d | 2017-06-20 15:06:19 | [diff] [blame] | 106 | * ***Toggle Header/Source*** - |
| 107 | Toggles between .cc and .h with `F4`. The C/C++ extension supports this as |
| 108 | well through `Alt+O` but sometimes chooses the wrong file when there are |
| 109 | multiple files in the workspace that have the same name. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 110 | * ***Protobuf support*** - |
| 111 | Syntax highlighting for .proto files. |
| 112 | * ***you-complete-me*** - |
| 113 | YouCompleteMe code completion for VS Code. It works fairly well in Chromium. |
| 114 | * ***Rewrap*** - |
| 115 | Wrap lines at 80 characters with `Alt+Q`. |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 116 | * ***Remote*** - |
| 117 | Remotely connect to your workstation through SSH using your laptop. See the |
| 118 | [Remote](#Remote) section for more information about how to set this up. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 119 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 120 | To install You-Complete-Me, enter these commands in a terminal: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 121 | |
| 122 | ``` |
| 123 | $ git clone https://github.com/Valloric/ycmd.git ~/.ycmd |
| 124 | $ cd ~/.ycmd |
sangwoo.ko | 5fe74c73 | 2017-09-01 14:44:56 | [diff] [blame] | 125 | $ git submodule update --init --recursive |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 126 | $ ./build.py --clang-completer |
| 127 | ``` |
James Cook | cb86840 | 2017-06-23 16:04:29 | [diff] [blame] | 128 | If it fails with "Your C++ compiler does NOT fully support C++11." but you know |
| 129 | you have a good compiler, hack cpp/CMakeLists.txt to set CPP11_AVAILABLE true. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 130 | |
Victor Costan | 1a50407 | 2018-02-20 20:10:25 | [diff] [blame] | 131 | On Mac, replace the last command above with the following. |
| 132 | |
| 133 | ``` |
| 134 | $ ./build.py --clang-completer --system-libclang |
| 135 | ``` |
| 136 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 137 | The following extensions might be useful for you as well: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 138 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 139 | * ***Annotator*** - |
| 140 | Git blame view. |
| 141 | * ***Git History (git log)*** - |
| 142 | Git history view. |
| 143 | * ***chromium-codesearch*** - |
| 144 | Code search (CS) integration, see [Chromium Code |
| 145 | Search](https://cs.chromium.org/), in particular *open current line in CS*, |
| 146 | *show references* and *go to definition*. Very useful for existing code. By |
| 147 | design, won't work for code not checked in yet. Overrides default C/C++ |
| 148 | functionality. Had some issues last time I tried (extensions stopped |
| 149 | working), so use with care. |
| 150 | * ***change-case*** - |
| 151 | Quickly change the case of the current selection or current word. |
| 152 | * ***Instant Markdown*** - |
| 153 | Instant markdown (.md) preview in your browser as you type. This document |
| 154 | was written with this extension! |
| 155 | * ***Clang-Format*** - |
| 156 | Format your code using clang-format. The C/C++ extension already supports |
| 157 | format-on-save (see `C_Cpp.clang_format_formatOnSave` setting). This |
| 158 | extension adds the ability to format a document or the current selection on |
| 159 | demand. |
Katie D | 36d0cd7b | 2019-04-03 22:19:53 | [diff] [blame] | 160 | * ***vscode-clangd*** - |
| 161 | If you do not plan to use VSCode for debugging, vscode-clangd is a great |
| 162 | alternative to C/C++ IntelliSense. It knows about how to compile Chromium, |
| 163 | enabling it to provide smarter autocomplete than C/C++ IntelliSense as well |
Haojian Wu | 052c819 | 2019-04-08 15:22:30 | [diff] [blame] | 164 | as allowing you to jump from functions to their definitions. See |
| 165 | [clangd.md](clangd.md) for details. |
Katie D | 36d0cd7b | 2019-04-03 22:19:53 | [diff] [blame] | 166 | |
Haojian Wu | 052c819 | 2019-04-08 15:22:30 | [diff] [blame] | 167 | If you need to debug, disable the vscode-clangd extension, enable C/C++ |
Katie D | 36d0cd7b | 2019-04-03 22:19:53 | [diff] [blame] | 168 | Intellisense, and restart VSCode. |
| 169 | |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 170 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 171 | Also be sure to take a look at the |
| 172 | [VS Code marketplace](https://marketplace.visualstudio.com/VSCode) to check out other |
| 173 | useful extensions. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 174 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 175 | ### Color Scheme |
| 176 | Press `Ctrl+Shift+P, color, Enter` to pick a color scheme for the editor. There |
| 177 | are also tons of [color schemes available for download on the |
| 178 | marketplace](https://marketplace.visualstudio.com/search?target=VSCode&category=Themes&sortBy=Downloads). |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 179 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 180 | ### Usage Tips |
| 181 | * `Ctrl+P` opens a search box to find and open a file. |
| 182 | * `F1` or `Ctrl+Shift+P` opens a search box to find a command (e.g. Tasks: Run |
| 183 | Task). |
| 184 | * `Ctrl+K, Ctrl+S` opens the key bindings editor. |
| 185 | * ``Ctrl+` `` toggles the built-in terminal. |
| 186 | * `Ctrl+Shift+M` toggles the problems view (linter warnings, compile errors |
| 187 | and warnings). You'll swicth a lot between terminal and problem view during |
| 188 | compilation. |
| 189 | * `Alt+O` switches between the source/header file. |
| 190 | * `Ctrl+G` jumps to a line. |
| 191 | * `F12` jumps to the definition of the symbol at the cursor (also available on |
| 192 | right-click context menu). |
| 193 | * `Shift+F12` or `F1, CodeSearchReferences, Return` shows all references of |
| 194 | the symbol at the cursor. |
| 195 | * `F1, CodeSearchOpen, Return` opens the current file in Code Search. |
| 196 | * `Ctrl+D` selects the word at the cursor. Pressing it multiple times |
| 197 | multi-selects the next occurrences, so typing in one types in all of them, |
| 198 | and `Ctrl+U` deselects the last occurrence. |
| 199 | * `Ctrl+K, Z` enters Zen Mode, a fullscreen editing mode with nothing but the |
| 200 | current editor visible. |
| 201 | * `Ctrl+X` without anything selected cuts the current line. `Ctrl+V` pastes |
| 202 | the line. |
| 203 | |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 204 | ### Java/Android Support |
| 205 | To get Java support in VS Code, you'll need to install the |
| 206 | 'Java Extension Pack' extension, but you'll want to immediately uninstall or |
| 207 | disable the Maven for Java extension so it stops nagging you as we won't need |
| 208 | it. |
| 209 | |
| 210 | #### Setting up code completion/reference finding/etc. |
| 211 | You'll need to locate the .classpath file redhat generates for you. Its |
| 212 | location will depend on whether you're doing local or remote development. |
| 213 | Local path on linux will look something like: |
| 214 | |
| 215 | `~/.vscode/data/User/workspaceStorage/<hash>/redhat.java/jdt_ws/<project>/.classpath` |
| 216 | |
| 217 | If doing remote development, the file will be under `~/.vscode-server/` on your |
| 218 | remote machine. |
| 219 | |
| 220 | You'll need to replace the contents of that file with the contents of |
| 221 | <chromium-root>/.classpath (generated by gclient runhooks), and then replace |
| 222 | some paths as vscode interprets some paths differently from eclipse. |
| 223 | * Replace: `kind="src" path="` with `kind="src" path="_/` |
| 224 | * Replace: `kind="lib" path="../src` with `kind="lib" path="_` |
| 225 | * Remove all nested paths (or exclude them from their parents). At time of |
| 226 | writing: |
| 227 | * `third_party/android_protobuf/src/java/src/main/java` |
| 228 | * `third_party/junit/src/src/main/java` |
| 229 | |
| 230 | Then restart vscode, open a Java file, and wait for a bit. |
| 231 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 232 | ## Setup For Chromium |
| 233 | |
| 234 | VS Code is configured via JSON files. This paragraph contains JSON configuration |
| 235 | files that are useful for Chromium development, in particular. See [VS Code |
| 236 | documentation](https://code.visualstudio.com/docs/customization/overview) for an |
| 237 | introduction to VS Code customization. |
| 238 | |
| 239 | ### Workspace Settings |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 240 | Open the file [//tools/vscode/settings.json5](/tools/vscode/settings.json5), |
| 241 | and check out the default settings there. Feel free to commit added or removed |
| 242 | settings to enable better team development, or change settings locally to suit |
| 243 | personal preference. Remember to replace `<full_path_to_your_home>`! To use |
| 244 | these settings wholesale, enter the following commands into your terminal while |
| 245 | at the src directory: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 246 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 247 | $ mkdir .vscode/ |
| 248 | $ cp tools/vscode/settings.json5 .vscode/settings.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 249 | ``` |
| 250 | |
| 251 | ### Tasks |
| 252 | 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] | 253 | errors from the build output. Open the file |
| 254 | [//tools/vscode/tasks.json5](/tools/vscode/tasks.json5). This will provide 5 |
| 255 | tasks to do basic things. You might have to adjust the commands to your |
| 256 | situation and needs. To use these settings wholesale, enter the following |
| 257 | command into your terminal: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 258 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 259 | $ cp tools/vscode/tasks.json5 .vscode/tasks.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 260 | ``` |
| 261 | |
| 262 | ### Launch Commands |
| 263 | Launch commands are the equivalent of `F5` in Visual Studio: They launch some |
| 264 | program or a debugger. Optionally, they can run some task defined in |
| 265 | `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] | 266 | Open the file at [//tools/vscode/launch.json5](/tools/vscode/launch.json5) and |
| 267 | adjust the example launch commands to your situation and needs. To use these |
| 268 | settings wholesale, enter the following command into your terminal: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 269 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 270 | $ cp tools/vscode/launch.json5 .vscode/launch.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 271 | ``` |
| 272 | |
| 273 | ### Key Bindings |
| 274 | To edit key bindings, press `Ctrl+K, Ctrl+S`. You'll see the defaults on the |
| 275 | left and your overrides on the right stored in the file `keybindings.json`. To |
| 276 | change a key binding, copy the corresponding key binding to the right. It's |
| 277 | fairly self-explanatory. |
| 278 | |
| 279 | You can bind any command to a key, even commands specified by extensions like |
| 280 | `CodeSearchOpen`. For instance, to bind `CodeSearchOpen` to `F2` to , simply add |
| 281 | `{ "key": "F2", "command": "cs.open" },`. |
| 282 | Note that the command title `CodeSearchOpen` won't work. You have to get the |
| 283 | actual command name from the [package.json |
| 284 | file](https://github.com/chaopeng/vscode-chromium-codesearch/blob/master/package.json) |
| 285 | of the extension. |
| 286 | |
| 287 | If you are used to other editors, you can also install your favorite keymap. |
| 288 | For instance, to install eclipse keymaps, install the |
| 289 | `vscode-eclipse-keybindings` extension. More keymaps can be found |
| 290 | [in the marketplace](https://marketplace.visualstudio.com/search?target=vscode&category=Keymaps). |
| 291 | |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 292 | Some key bindings that are likely to be useful for you are available at |
| 293 | [//tools/vscode/keybindings.json5](/tools/vscode/keybindings.json5). Please |
| 294 | take a look and adjust them to your situation and needs. To use these settings |
| 295 | wholesale, enter the following command into your terminal: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 296 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 297 | $ cp tools/vscode/keybindings.json5 .vscode/keybindings.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 298 | ``` |
| 299 | |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 300 | ### Remote |
| 301 | VSCode now has a |
| 302 | [Remote](https://code.visualstudio.com/docs/remote/remote-overview) framework |
| 303 | that allows you to use VSCode on your laptop while your code is hosted |
| 304 | elsewhere. This really shines when used in conjunction with the vscode-clangd plugin, |
| 305 | which allows clangd to run remotely as well. |
| 306 | |
| 307 | To get this to run, install the Remote pack extension, and then make sure your |
| 308 | ssh config file has your remote connection: |
| 309 | |
| 310 | `~/.ssh/config`: |
| 311 | ``` |
| 312 | Host my-connection |
| 313 | HostName my-remote-host.corp.company.com |
| 314 | ``` |
| 315 | |
| 316 | VSCode will then list this connection in the 'Remote Explorer' section on the |
| 317 | left. To launch VSCode with this connection, click on the '+window' icon next |
| 318 | to the listed hostname. It has you choose a folder - use the 'src' folder root. |
| 319 | This will open a new VSCode window in 'Remote' mode. ***Now you can install |
| 320 | extensions specifically for your remote connection, like vscode-clangd, etc.*** |
| 321 | |
| 322 | #### Windows & SSH |
| 323 | This currently is difficult on Windows because VSCode remote tools assumes |
| 324 | 'sshd' is installed, which isn't the case on Windows. If someone figures out |
| 325 | how to get vscode remote working on windows with ssh please update this |
| 326 | document :) |
| 327 | |
Dan Harrington | b06ce2f | 2019-04-09 15:35:29 | [diff] [blame] | 328 | ### Snippets |
| 329 | There are some useful snippets provided in |
| 330 | [//tools/vscode/cpp.json5](/tools/vscode/cpp.json5). |
| 331 | |
Mounir Lamouri | 3b9e31d | 2019-07-30 20:14:41 | [diff] [blame] | 332 | You can either install them in your user profile (path may vary depending on the |
| 333 | platform): |
| 334 | ``` |
| 335 | $ cp tools/vscode/cpp.json5 ~/.config/Code/User/snippets/cpp.json |
| 336 | ``` |
| 337 | |
| 338 | Or install them as project snippets after installing the [Project |
| 339 | Snippets](https://marketplace.visualstudio.com/items?itemName=rebornix.project-snippets) |
| 340 | extension: |
| 341 | ``` |
| 342 | $ cp tools/vscode/cpp.json5 .vscode/snippets/cpp.json |
| 343 | ``` |
| 344 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 345 | ### Tips |
| 346 | |
| 347 | #### The `out` folder |
| 348 | Automatically generated code is put into a subfolder of out/, which means that |
| 349 | 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] | 350 | opened e.g. from quick-open (`Ctrl+P`). |
| 351 | As of version 1.21, VS Code does not support negated glob commands, but you can |
| 352 | define a set of exclude pattern to include only out/Debug/gen: |
Christian Dullweber | babb96e1 | 2018-05-28 14:00:14 | [diff] [blame] | 353 | ``` |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 354 | "files.exclude": { |
| 355 | // Ignore build output folders. Except out/Debug/gen/ |
| 356 | "out/[^D]*/": true, |
| 357 | "out/Debug/[^g]*": true, |
| 358 | "out/Debug/g[^e]*": true, |
| 359 | "out_*/**": true, |
| 360 | }, |
Christian Dullweber | babb96e1 | 2018-05-28 14:00:14 | [diff] [blame] | 361 | ``` |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 362 | |
| 363 | Once it does, you can use |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 364 | ``` |
| 365 | "!out/Debug/gen/**": true |
| 366 | ``` |
| 367 | in files.exclude instead of the symlink. |
| 368 | |
| 369 | #### Using VS Code as git editor |
| 370 | Add `[core] editor = "code --wait"` to your `~/.gitconfig` file in order to use |
| 371 | VS Code as editor for git commit messages etc. Note that the editor starts up |
| 372 | significantly slower than nano or vim. To use VS Code as merge tool, add |
| 373 | `[merge] tool = code`. |
| 374 | |
| 375 | #### Task Names |
| 376 | Note that we named the tasks `1-build_chrome_debug`, `2-build_chrome_release` |
| 377 | etc. This allows you to quickly execute tasks by pressing their number: |
| 378 | Press `Ctrl+P` and enter `task <n>`, where `<n>` is the number of the task. You |
| 379 | can also create a keyboard shortcut for running a task. `File > Preferences > |
| 380 | Keyboard Shortcuts` and add `{ "key": "ctrl+r", "command": |
| 381 | "workbench.action.tasks.runTask", "when": "!inDebugMode" }`. Then it's |
| 382 | sufficient to press `Ctrl+R` and enter `<n>`. |
| 383 | |
| 384 | #### Working on Laptop |
| 385 | Because autocomplete is provided by the You-Complete-Me extension, consider |
| 386 | disabling C/C++ autocomplete and indexing to save battery. In addition, you |
| 387 | might want to disable git status autorefresh as well. |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 388 | |
| 389 | ``` |
chaopeng | 5c66dfe | 2017-03-22 13:51:45 | [diff] [blame] | 390 | "git.autorefresh": false, |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 391 | "C_Cpp.autocomplete": "Disabled", |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 392 | ``` |
| 393 | |
Jianpeng Chao | b4048b8 | 2018-08-28 23:40:01 | [diff] [blame] | 394 | ### Unable to open $File resource is not available when debugging Chromium on Linux |
| 395 | Chromium [recently changed](https://docs.google.com/document/d/1OX4jY_bOCeNK7PNjVRuBQE9s6BQKS8XRNWGK8FEyh-E/edit?usp=sharing) |
| 396 | the file path to be relative to the output dir. Check |
| 397 | `gn args out/$dir --list` if `strip_absolute_paths_from_debug_symbols` is true (which is the default), |
| 398 | set `cwd` to the output dir. otherwise, set `cwd` to `${workspaceRoot}`. |
| 399 | |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 400 | ### More |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 401 | More tips and tricks can be found |
sangwoo.ko | 5fe74c73 | 2017-09-01 14:44:56 | [diff] [blame] | 402 | [here](https://github.com/Microsoft/vscode-tips-and-tricks/blob/master/README.md). |