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 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 58 | ### Useful Extensions |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 59 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 60 | Up to now, you have a basic version of VS Code without much language support. |
| 61 | Next, we will install some useful extensions. Jump to the extensions window |
| 62 | (`Ctrl+Shift+X`) and install these extensions, you will most likely use them |
| 63 | every day: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 64 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 65 | * ***C/C++*** - |
James Cook | 9d7e219 | 2017-06-19 19:59:09 | [diff] [blame] | 66 | Code formatting, debugging, Intellisense. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 67 | * ***Python*** - |
| 68 | Linting, intellisense, code formatting, refactoring, debugging, snippets. |
James Cook | 9f7c73d | 2017-06-20 15:06:19 | [diff] [blame] | 69 | * ***Toggle Header/Source*** - |
| 70 | Toggles between .cc and .h with `F4`. The C/C++ extension supports this as |
| 71 | well through `Alt+O` but sometimes chooses the wrong file when there are |
| 72 | multiple files in the workspace that have the same name. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 73 | * ***Protobuf support*** - |
| 74 | Syntax highlighting for .proto files. |
| 75 | * ***you-complete-me*** - |
| 76 | YouCompleteMe code completion for VS Code. It works fairly well in Chromium. |
| 77 | * ***Rewrap*** - |
| 78 | Wrap lines at 80 characters with `Alt+Q`. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 79 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 80 | To install You-Complete-Me, enter these commands in a terminal: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 81 | |
| 82 | ``` |
| 83 | $ git clone https://github.com/Valloric/ycmd.git ~/.ycmd |
| 84 | $ cd ~/.ycmd |
sangwoo.ko | 5fe74c73 | 2017-09-01 14:44:56 | [diff] [blame] | 85 | $ git submodule update --init --recursive |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 86 | $ ./build.py --clang-completer |
| 87 | ``` |
James Cook | cb86840 | 2017-06-23 16:04:29 | [diff] [blame] | 88 | If it fails with "Your C++ compiler does NOT fully support C++11." but you know |
| 89 | you have a good compiler, hack cpp/CMakeLists.txt to set CPP11_AVAILABLE true. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 90 | |
Victor Costan | 1a50407 | 2018-02-20 20:10:25 | [diff] [blame] | 91 | On Mac, replace the last command above with the following. |
| 92 | |
| 93 | ``` |
| 94 | $ ./build.py --clang-completer --system-libclang |
| 95 | ``` |
| 96 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 97 | The following extensions might be useful for you as well: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 98 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 99 | * ***Annotator*** - |
| 100 | Git blame view. |
| 101 | * ***Git History (git log)*** - |
| 102 | Git history view. |
| 103 | * ***chromium-codesearch*** - |
| 104 | Code search (CS) integration, see [Chromium Code |
| 105 | Search](https://cs.chromium.org/), in particular *open current line in CS*, |
| 106 | *show references* and *go to definition*. Very useful for existing code. By |
| 107 | design, won't work for code not checked in yet. Overrides default C/C++ |
| 108 | functionality. Had some issues last time I tried (extensions stopped |
| 109 | working), so use with care. |
| 110 | * ***change-case*** - |
| 111 | Quickly change the case of the current selection or current word. |
| 112 | * ***Instant Markdown*** - |
| 113 | Instant markdown (.md) preview in your browser as you type. This document |
| 114 | was written with this extension! |
| 115 | * ***Clang-Format*** - |
| 116 | Format your code using clang-format. The C/C++ extension already supports |
| 117 | format-on-save (see `C_Cpp.clang_format_formatOnSave` setting). This |
| 118 | extension adds the ability to format a document or the current selection on |
| 119 | demand. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 120 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 121 | Also be sure to take a look at the |
| 122 | [VS Code marketplace](https://marketplace.visualstudio.com/VSCode) to check out other |
| 123 | useful extensions. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 124 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 125 | ### Color Scheme |
| 126 | Press `Ctrl+Shift+P, color, Enter` to pick a color scheme for the editor. There |
| 127 | are also tons of [color schemes available for download on the |
| 128 | marketplace](https://marketplace.visualstudio.com/search?target=VSCode&category=Themes&sortBy=Downloads). |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 129 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 130 | ### Usage Tips |
| 131 | * `Ctrl+P` opens a search box to find and open a file. |
| 132 | * `F1` or `Ctrl+Shift+P` opens a search box to find a command (e.g. Tasks: Run |
| 133 | Task). |
| 134 | * `Ctrl+K, Ctrl+S` opens the key bindings editor. |
| 135 | * ``Ctrl+` `` toggles the built-in terminal. |
| 136 | * `Ctrl+Shift+M` toggles the problems view (linter warnings, compile errors |
| 137 | and warnings). You'll swicth a lot between terminal and problem view during |
| 138 | compilation. |
| 139 | * `Alt+O` switches between the source/header file. |
| 140 | * `Ctrl+G` jumps to a line. |
| 141 | * `F12` jumps to the definition of the symbol at the cursor (also available on |
| 142 | right-click context menu). |
| 143 | * `Shift+F12` or `F1, CodeSearchReferences, Return` shows all references of |
| 144 | the symbol at the cursor. |
| 145 | * `F1, CodeSearchOpen, Return` opens the current file in Code Search. |
| 146 | * `Ctrl+D` selects the word at the cursor. Pressing it multiple times |
| 147 | multi-selects the next occurrences, so typing in one types in all of them, |
| 148 | and `Ctrl+U` deselects the last occurrence. |
| 149 | * `Ctrl+K, Z` enters Zen Mode, a fullscreen editing mode with nothing but the |
| 150 | current editor visible. |
| 151 | * `Ctrl+X` without anything selected cuts the current line. `Ctrl+V` pastes |
| 152 | the line. |
| 153 | |
| 154 | ## Setup For Chromium |
| 155 | |
| 156 | VS Code is configured via JSON files. This paragraph contains JSON configuration |
| 157 | files that are useful for Chromium development, in particular. See [VS Code |
| 158 | documentation](https://code.visualstudio.com/docs/customization/overview) for an |
| 159 | introduction to VS Code customization. |
| 160 | |
| 161 | ### Workspace Settings |
| 162 | Open the file chromium/src/.vscode/settings.json and add the following settings. |
| 163 | Remember to replace `<full_path_to_your_home>`! |
| 164 | |
| 165 | ``` |
| 166 | { |
| 167 | // Default tab size of 2. |
| 168 | "editor.tabSize": 2, |
| 169 | // Do not figure out tab size from opening a file. |
| 170 | "editor.detectIndentation": false, |
| 171 | // Add a line at 80 characters. |
| 172 | "editor.rulers": [80], |
| 173 | // Optional: Highlight current line at the left of the editor. |
| 174 | "editor.renderLineHighlight": "gutter", |
| 175 | // Optional: Don't automatically add closing brackets. It gets in the way. |
| 176 | "editor.autoClosingBrackets": false, |
| 177 | // Optional: Enable a tiny 30k feet view of your doc. |
| 178 | "editor.minimap.enabled": true, |
| 179 | "editor.minimap.maxColumn": 80, |
| 180 | "editor.minimap.renderCharacters": false, |
| 181 | // Trim tailing whitespace on save. |
| 182 | "files.trimTrailingWhitespace": true, |
| 183 | // Optional: Do not open files in 'preview' mode. Opening a new file in can |
| 184 | // replace an existing one in preview mode, which can be confusing. |
| 185 | "workbench.editor.enablePreview": false, |
| 186 | // Optional: Same for files opened from quick open (Ctrl+P). |
| 187 | "workbench.editor.enablePreviewFromQuickOpen": false, |
James Cook | 9d7e219 | 2017-06-19 19:59:09 | [diff] [blame] | 188 | // Optional: Don't continuously fetch remote changes. |
| 189 | "git.autofetch": false, |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 190 | |
| 191 | "files.associations": { |
| 192 | // Adds xml syntax highlighting for grd files. |
| 193 | "*.grd" : "xml", |
| 194 | // Optional: .gn and .gni are not JavaScript, but at least it gives some |
| 195 | // approximate syntax highlighting. Ignore the linter warnings! |
| 196 | "*.gni" : "javascript", |
| 197 | "*.gn" : "javascript" |
| 198 | }, |
| 199 | |
| 200 | "files.exclude": { |
| 201 | // Ignore build output folders. |
| 202 | "out*/**": true |
| 203 | }, |
| 204 | |
dullweber | a347f0eb | 2017-04-27 14:20:32 | [diff] [blame] | 205 | "files.watcherExclude": { |
dullweber | 48be158 | 2017-04-28 09:40:25 | [diff] [blame] | 206 | // Don't watch out*/ and third_party/ for changes to fix an issue |
dullweber | a347f0eb | 2017-04-27 14:20:32 | [diff] [blame] | 207 | // where vscode doesn't notice that files have changed. |
| 208 | // https://github.com/Microsoft/vscode/issues/3998 |
dullweber | 48be158 | 2017-04-28 09:40:25 | [diff] [blame] | 209 | // There is currently another issue that requires a leading **/ for |
| 210 | // watcherExlude. Beware that this pattern might affect other out* folders |
| 211 | // like src/cc/output/. |
| 212 | "**/out*/**": true, |
dullweber | a347f0eb | 2017-04-27 14:20:32 | [diff] [blame] | 213 | "**/third_party/**": true |
| 214 | }, |
| 215 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 216 | // Wider author column for annotator extension. |
| 217 | "annotator.annotationColumnWidth": "24em", |
| 218 | |
| 219 | // C++ clang format settings. |
James Cook | 9d7e219 | 2017-06-19 19:59:09 | [diff] [blame] | 220 | "C_Cpp.clang_format_path": "${workspaceRoot}/third_party/depot_tools/clang-format", |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 221 | "C_Cpp.clang_format_sortIncludes": true, |
| 222 | "C_Cpp.clang_format_formatOnSave": true, |
| 223 | |
| 224 | // YouCompleteMe |
James Cook | cb86840 | 2017-06-23 16:04:29 | [diff] [blame] | 225 | "ycmd.path": "<full_path_to_your_home>/.ycmd", |
| 226 | "ycmd.global_extra_config": "${workspaceRoot}/tools/vim/chromium.ycm_extra_conf.py", |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 227 | "ycmd.confirm_extra_conf": false, |
| 228 | } |
| 229 | ``` |
| 230 | |
| 231 | ### Tasks |
| 232 | Next, we'll tell VS Code how to compile our code and how to read warnings and |
| 233 | errors from the build output. Copy the code below to |
| 234 | chromium/src/.vscode/tasks.json. This will provide 5 tasks to do basic things. |
| 235 | You might have to adjust the commands to your situation and needs. |
| 236 | |
| 237 | ``` |
| 238 | { |
| 239 | "version": "0.1.0", |
| 240 | "_runner": "terminal", |
| 241 | "showOutput": "always", |
| 242 | "echoCommand": true, |
| 243 | "tasks": [ |
| 244 | { |
| 245 | "taskName": "1-build_chrome_debug", |
| 246 | "command": "ninja -C out/Debug -j 2000 chrome", |
| 247 | "isShellCommand": true, |
| 248 | "isTestCommand": true, |
Lutz Justen | d498279 | 2017-05-05 15:07:26 | [diff] [blame] | 249 | "problemMatcher": [ |
| 250 | { |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 251 | "owner": "cpp", |
| 252 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 253 | "pattern": { |
| 254 | "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 255 | "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 |
| 256 | } |
Lutz Justen | d498279 | 2017-05-05 15:07:26 | [diff] [blame] | 257 | }, |
| 258 | { |
| 259 | "owner": "cpp", |
| 260 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 261 | "pattern": { |
| 262 | "regexp": "^../../(.*?):(.*):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 263 | "file": 1, "severity": 3, "message": 4 |
| 264 | } |
| 265 | }] |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 266 | }, |
| 267 | { |
| 268 | "taskName": "2-build_chrome_release", |
| 269 | "command": "ninja -C out/Release -j 2000 chrome", |
| 270 | "isShellCommand": true, |
| 271 | "isBuildCommand": true, |
Lutz Justen | d498279 | 2017-05-05 15:07:26 | [diff] [blame] | 272 | "problemMatcher": [ |
| 273 | { |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 274 | "owner": "cpp", |
| 275 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 276 | "pattern": { |
| 277 | "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 278 | "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 |
| 279 | } |
Lutz Justen | d498279 | 2017-05-05 15:07:26 | [diff] [blame] | 280 | }, |
| 281 | { |
| 282 | "owner": "cpp", |
| 283 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 284 | "pattern": { |
| 285 | "regexp": "^../../(.*?):(.*):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 286 | "file": 1, "severity": 3, "message": 4 |
| 287 | } |
| 288 | }] |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 289 | }, |
| 290 | { |
| 291 | "taskName": "3-build_all_debug", |
| 292 | "command": "ninja -C out/Debug -j 2000", |
| 293 | "isShellCommand": true, |
Lutz Justen | d498279 | 2017-05-05 15:07:26 | [diff] [blame] | 294 | "problemMatcher": [ |
| 295 | { |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 296 | "owner": "cpp", |
| 297 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 298 | "pattern": { |
| 299 | "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 300 | "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 |
| 301 | } |
Lutz Justen | d498279 | 2017-05-05 15:07:26 | [diff] [blame] | 302 | }, |
| 303 | { |
| 304 | "owner": "cpp", |
| 305 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 306 | "pattern": { |
| 307 | "regexp": "^../../(.*?):(.*):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 308 | "file": 1, "severity": 3, "message": 4 |
| 309 | } |
| 310 | }] |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 311 | }, |
| 312 | { |
| 313 | "taskName": "4-build_all_release", |
| 314 | "command": "ninja -C out/Release -j 2000", |
| 315 | "isShellCommand": true, |
Lutz Justen | d498279 | 2017-05-05 15:07:26 | [diff] [blame] | 316 | "problemMatcher": [ |
| 317 | { |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 318 | "owner": "cpp", |
| 319 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 320 | "pattern": { |
| 321 | "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 322 | "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 |
| 323 | } |
Lutz Justen | d498279 | 2017-05-05 15:07:26 | [diff] [blame] | 324 | }, |
| 325 | { |
| 326 | "owner": "cpp", |
| 327 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 328 | "pattern": { |
| 329 | "regexp": "^../../(.*?):(.*):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 330 | "file": 1, "severity": 3, "message": 4 |
| 331 | } |
| 332 | }] |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 333 | }, |
| 334 | { |
| 335 | "taskName": "5-build_test_debug", |
| 336 | "command": "ninja -C out/Debug -j 2000 unit_tests components_unittests browser_tests", |
| 337 | "isShellCommand": true, |
Lutz Justen | d498279 | 2017-05-05 15:07:26 | [diff] [blame] | 338 | "problemMatcher": [ |
| 339 | { |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 340 | "owner": "cpp", |
| 341 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 342 | "pattern": { |
| 343 | "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 344 | "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 |
| 345 | } |
Lutz Justen | d498279 | 2017-05-05 15:07:26 | [diff] [blame] | 346 | }, |
| 347 | { |
| 348 | "owner": "cpp", |
| 349 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 350 | "pattern": { |
| 351 | "regexp": "^../../(.*?):(.*):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 352 | "file": 1, "severity": 3, "message": 4 |
| 353 | } |
| 354 | }] |
Sebastien Marchand | 0724732 | 2018-03-08 21:05:23 | [diff] [blame] | 355 | }, |
| 356 | { |
| 357 | "taskName": "6-build_current_file", |
| 358 | "command": "compile_single_file --build-dir=out/Debug --file-path=${file}", |
| 359 | "isShellCommand": true, |
| 360 | "problemMatcher": [ |
| 361 | { |
| 362 | "owner": "cpp", |
| 363 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 364 | "pattern": { |
| 365 | "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 366 | "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 |
| 367 | } |
| 368 | }, |
| 369 | { |
| 370 | "owner": "cpp", |
| 371 | "fileLocation": ["relative", "${workspaceRoot}"], |
| 372 | "pattern": { |
| 373 | "regexp": "^../../(.*?):(.*):\\s+(warning|\\w*\\s?error):\\s+(.*)$", |
| 374 | "file": 1, "severity": 3, "message": 4 |
| 375 | } |
| 376 | }] |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 377 | }] |
| 378 | } |
| 379 | ``` |
| 380 | |
| 381 | ### Launch Commands |
| 382 | Launch commands are the equivalent of `F5` in Visual Studio: They launch some |
| 383 | program or a debugger. Optionally, they can run some task defined in |
| 384 | `tasks.json`. Launch commands can be run from the debug view (`Ctrl+Shift+D`). |
| 385 | Copy the code below to chromium/src/.vscode/launch.json and adjust them to |
| 386 | your situation and needs. |
| 387 | ``` |
| 388 | { |
| 389 | "version": "0.2.0", |
| 390 | "configurations": [ |
| 391 | { |
| 392 | "name": "Chrome Debug", |
| 393 | "type": "cppdbg", |
| 394 | "request": "launch", |
| 395 | "targetArchitecture": "x64", |
| 396 | "program": "${workspaceRoot}/out/Debug/chrome", |
| 397 | "args": [], // Optional command line args |
| 398 | "preLaunchTask": "1-build_chrome_debug", |
| 399 | "stopAtEntry": false, |
| 400 | "cwd": "${workspaceRoot}", |
| 401 | "environment": [], |
| 402 | "externalConsole": true |
| 403 | }, |
| 404 | { |
| 405 | "name": "Chrome Release", |
| 406 | "type": "cppdbg", |
| 407 | "request": "launch", |
| 408 | "targetArchitecture": "x64", |
| 409 | "program": "${workspaceRoot}/out/Release/chrome", |
| 410 | "args": [], // Optional command line args |
| 411 | "preLaunchTask": "2-build_chrome_release", |
| 412 | "stopAtEntry": false, |
| 413 | "cwd": "${workspaceRoot}", |
| 414 | "environment": [], |
| 415 | "externalConsole": true |
| 416 | }, |
| 417 | { |
| 418 | "name": "Custom Test Debug", |
| 419 | "type": "cppdbg", |
| 420 | "request": "launch", |
| 421 | "targetArchitecture": "x64", |
| 422 | "program": "${workspaceRoot}/out/Debug/unit_tests", |
| 423 | "args": ["--gtest_filter=*", |
| 424 | "--single_process", |
| 425 | "--ui-test-action-max-timeout=1000000", |
| 426 | "--test-launcher-timeout=1000000"], |
| 427 | "preLaunchTask": "5-build_test_debug", |
| 428 | "stopAtEntry": false, |
| 429 | "cwd": "${workspaceRoot}", |
| 430 | "environment": [], |
| 431 | "externalConsole": true |
| 432 | }, |
| 433 | { |
| 434 | "name": "Attach Debug", |
| 435 | "type": "cppdbg", |
| 436 | "request": "launch", |
| 437 | "targetArchitecture": "x64", |
| 438 | "program": "${workspaceRoot}/out/Debug/chrome", |
| 439 | "args": ["--remote-debugging-port=2224"], |
| 440 | "stopAtEntry": false, |
| 441 | "cwd": "${workspaceRoot}", |
| 442 | "environment": [], |
| 443 | "externalConsole": false |
| 444 | }] |
| 445 | } |
| 446 | ``` |
| 447 | |
| 448 | ### Key Bindings |
| 449 | To edit key bindings, press `Ctrl+K, Ctrl+S`. You'll see the defaults on the |
| 450 | left and your overrides on the right stored in the file `keybindings.json`. To |
| 451 | change a key binding, copy the corresponding key binding to the right. It's |
| 452 | fairly self-explanatory. |
| 453 | |
| 454 | You can bind any command to a key, even commands specified by extensions like |
| 455 | `CodeSearchOpen`. For instance, to bind `CodeSearchOpen` to `F2` to , simply add |
| 456 | `{ "key": "F2", "command": "cs.open" },`. |
| 457 | Note that the command title `CodeSearchOpen` won't work. You have to get the |
| 458 | actual command name from the [package.json |
| 459 | file](https://github.com/chaopeng/vscode-chromium-codesearch/blob/master/package.json) |
| 460 | of the extension. |
| 461 | |
| 462 | If you are used to other editors, you can also install your favorite keymap. |
| 463 | For instance, to install eclipse keymaps, install the |
| 464 | `vscode-eclipse-keybindings` extension. More keymaps can be found |
| 465 | [in the marketplace](https://marketplace.visualstudio.com/search?target=vscode&category=Keymaps). |
| 466 | |
| 467 | Here are some key bindings that are likely to be useful for you: |
| 468 | |
| 469 | ``` |
| 470 | // Place your key bindings in this file to overwrite the defaults |
| 471 | [ |
| 472 | // Run the task marked as "isTestCommand": true, see tasks.json. |
| 473 | { "key": "ctrl+shift+t", "command": "workbench.action.tasks.test" }, |
| 474 | // Jump to the previous change in the built-in diff tool. |
| 475 | { "key": "ctrl+up", "command": "workbench.action.compareEditor.previousChange" }, |
| 476 | // Jump to the next change in the built-in diff tool. |
| 477 | { "key": "ctrl+down", "command": "workbench.action.compareEditor.nextChange" }, |
| 478 | // Jump to previous location in the editor (useful to get back from viewing a symbol definition). |
| 479 | { "key": "alt+left", "command": "workbench.action.navigateBack" }, |
| 480 | // Jump to next location in the editor. |
| 481 | { "key": "alt+right", "command": "workbench.action.navigateForward" }, |
| 482 | // Get a blame view of the current file. Requires the annotator extension. |
| 483 | { "key": "ctrl+alt+a", "command": "annotator.annotate" }, |
| 484 | // Toggle header/source with the Toggle Header/Source extension (overrides the |
| 485 | // key binding from the C/C++ extension as I found it to be slow). |
| 486 | { "key": "alt+o", "command": "togglehs.toggleHS" }, |
| 487 | // Quickly run a task, see tasks.json. Since we named them 1-, 2- etc., it is |
| 488 | // suffucient to press the corresponding number. |
| 489 | { "key": "ctrl+r", "command": "workbench.action.tasks.runTask", |
| 490 | "when": "!inDebugMode" }, |
| 491 | // The following keybindings are useful on laptops with small keyboards such as |
| 492 | // Chromebooks that don't provide all keys. |
| 493 | { "key": "shift+alt+down", "command": "cursorColumnSelectDown", |
| 494 | "when": "editorTextFocus" }, |
| 495 | { "key": "shift+alt+left", "command": "cursorColumnSelectLeft", |
| 496 | "when": "editorTextFocus" }, |
| 497 | { "key": "shift+alt+pagedown", "command": "cursorColumnSelectPageDown", |
| 498 | "when": "editorTextFocus" }, |
| 499 | { "key": "shift+alt+pageup", "command": "cursorColumnSelectPageUp", |
| 500 | "when": "editorTextFocus" }, |
| 501 | { "key": "shift+alt+right", "command": "cursorColumnSelectRight", |
| 502 | "when": "editorTextFocus" }, |
| 503 | { "key": "shift+alt+up", "command": "cursorColumnSelectUp", |
| 504 | "when": "editorTextFocus" }, |
| 505 | { "key": "alt+down", "command": "scrollPageDown", |
| 506 | "when": "editorTextFocus" }, |
| 507 | { "key": "alt+up", "command": "scrollPageUp", |
| 508 | "when": "editorTextFocus" }, |
| 509 | { "key": "alt+backspace", "command": "deleteRight", |
| 510 | "when": "editorTextFocus && !editorReadonly" }, |
| 511 | { "key": "ctrl+right", "command": "cursorEnd", |
| 512 | "when": "editorTextFocus" }, |
| 513 | { "key": "ctrl+shift+right", "command": "cursorEndSelect", |
| 514 | "when": "editorTextFocus" }, |
| 515 | { "key": "ctrl+left", "command": "cursorHome", |
| 516 | "when": "editorTextFocus" }, |
| 517 | { "key": "ctrl+shift+left", "command": "cursorHomeSelect", |
| 518 | "when": "editorTextFocus" }, |
| 519 | ] |
| 520 | ``` |
| 521 | |
| 522 | ### Tips |
| 523 | |
| 524 | #### The `out` folder |
| 525 | Automatically generated code is put into a subfolder of out/, which means that |
| 526 | 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] | 527 | opened e.g. from quick-open (`Ctrl+P`). |
| 528 | As of version 1.21, VS Code does not support negated glob commands, but you can |
| 529 | define a set of exclude pattern to include only out/Debug/gen: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 530 | |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 531 | "files.exclude": { |
| 532 | // Ignore build output folders. Except out/Debug/gen/ |
| 533 | "out/[^D]*/": true, |
| 534 | "out/Debug/[^g]*": true, |
| 535 | "out/Debug/g[^e]*": true, |
| 536 | "out_*/**": true, |
| 537 | }, |
| 538 | |
| 539 | Once it does, you can use |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 540 | ``` |
| 541 | "!out/Debug/gen/**": true |
| 542 | ``` |
| 543 | in files.exclude instead of the symlink. |
| 544 | |
| 545 | #### Using VS Code as git editor |
| 546 | Add `[core] editor = "code --wait"` to your `~/.gitconfig` file in order to use |
| 547 | VS Code as editor for git commit messages etc. Note that the editor starts up |
| 548 | significantly slower than nano or vim. To use VS Code as merge tool, add |
| 549 | `[merge] tool = code`. |
| 550 | |
| 551 | #### Task Names |
| 552 | Note that we named the tasks `1-build_chrome_debug`, `2-build_chrome_release` |
| 553 | etc. This allows you to quickly execute tasks by pressing their number: |
| 554 | Press `Ctrl+P` and enter `task <n>`, where `<n>` is the number of the task. You |
| 555 | can also create a keyboard shortcut for running a task. `File > Preferences > |
| 556 | Keyboard Shortcuts` and add `{ "key": "ctrl+r", "command": |
| 557 | "workbench.action.tasks.runTask", "when": "!inDebugMode" }`. Then it's |
| 558 | sufficient to press `Ctrl+R` and enter `<n>`. |
| 559 | |
| 560 | #### Working on Laptop |
| 561 | Because autocomplete is provided by the You-Complete-Me extension, consider |
| 562 | disabling C/C++ autocomplete and indexing to save battery. In addition, you |
| 563 | might want to disable git status autorefresh as well. |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 564 | |
| 565 | ``` |
chaopeng | 5c66dfe | 2017-03-22 13:51:45 | [diff] [blame] | 566 | "git.autorefresh": false, |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 567 | "C_Cpp.autocomplete": "Disabled", |
| 568 | "C_Cpp.addWorkspaceRootToIncludePath": false |
| 569 | ``` |
| 570 | |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 571 | ### More |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 572 | More tips and tricks can be found |
sangwoo.ko | 5fe74c73 | 2017-09-01 14:44:56 | [diff] [blame] | 573 | [here](https://github.com/Microsoft/vscode-tips-and-tricks/blob/master/README.md). |