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. |
Ryan Heise | 9a71143 | 2020-10-14 23:55:39 | [diff] [blame] | 28 | * For more information on debugging Python code, see [here](vscode_python.md). |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 29 | * Opening files and searching solution-wide works well now after having |
| 30 | problems in earlier versions. |
| 31 | * Building works well. Build tools are easy to integrate. Warnings and errors |
| 32 | are displayed on a separate page and you can click to jump to the |
| 33 | corresponding line of code. |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 34 | * VSCode Remote, which allows you to edit remotely-hosted code, and even run |
| 35 | computationally expensive plugins like vscode-clangd on the remote |
| 36 | server/workstation (see the [Remote section](#Remote)). Great for working- |
James Cook | 3a41598 | 2020-03-25 18:47:38 | [diff] [blame] | 37 | from-home. (Googlers: See [go/vscode-remote](http://go/vscode-remote)].) |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 38 | |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 39 | [TOC] |
| 40 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 41 | ## Updating This Page |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 42 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 43 | Please keep this doc up-to-date. VS Code is still in active development and |
| 44 | subject to changes. This doc is checked into the Chromium git repo, so if you |
| 45 | make changes, read the [documentation |
Johann | 48fbca9 | 2021-07-16 18:29:41 | [diff] [blame] | 46 | guidelines](documentation_guidelines.md) |
| 47 | and [submit a change list](contributing.md). |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 48 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 49 | All file paths and commands have been tested on Linux. Windows and Mac might |
| 50 | require a slightly different setup (e.g. `Ctrl` -> `Cmd`). Please update this |
| 51 | page accordingly. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 52 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 53 | ## Setup |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 54 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 55 | ### Installation |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 56 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 57 | Follow the steps on https://code.visualstudio.com/docs/setup/setup-overview. To |
Bartek Nowierski | fa835f8c | 2021-02-24 00:36:02 | [diff] [blame] | 58 | run it on Linux, just navigate to Chromium's `src` folder and type `code .` in a |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 59 | terminal. The argument to `code` is the base directory of the workspace. VS |
| 60 | Code does not require project or solution files. However, it does store |
| 61 | workspace settings in a `.vscode` folder in your base directory. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 62 | |
Mounir Lamouri | 1679feab | 2019-01-25 19:30:03 | [diff] [blame] | 63 | ### Fixes for Known Issues |
| 64 | |
| 65 | #### Git on Windows |
Mounir Lamouri | 8202f36 | 2019-01-14 11:48:26 | [diff] [blame] | 66 | |
| 67 | If you only have the `depot_tools` Git installed on your machine, even though it |
| 68 | is in your PATH, VS Code will ignore it as it seems to be looking for `git.exe`. |
| 69 | You will have to add the following to your settings in order for the Git |
| 70 | integration to work: |
| 71 | |
Mounir Lamouri | 1679feab | 2019-01-25 19:30:03 | [diff] [blame] | 72 | ```json |
Mounir Lamouri | 8202f36 | 2019-01-14 11:48:26 | [diff] [blame] | 73 | { |
| 74 | "git.path": "C:\\src\\depot_tools\\git.bat" |
| 75 | } |
| 76 | ``` |
| 77 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 78 | ### Useful Extensions |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 79 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 80 | Up to now, you have a basic version of VS Code without much language support. |
| 81 | Next, we will install some useful extensions. Jump to the extensions window |
| 82 | (`Ctrl+Shift+X`) and install these extensions, you will most likely use them |
| 83 | every day: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 84 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 85 | * ***C/C++*** - |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 86 | Code formatting, debugging, Intellisense. Enables the use of clang-format |
| 87 | (via the `C_Cpp.clang_format_path` setting) and format-on-save (via the |
| 88 | `editor.formatOnSave` setting). |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 89 | * ***Python*** - |
| 90 | Linting, intellisense, code formatting, refactoring, debugging, snippets. |
James Cook | 9f7c73d | 2017-06-20 15:06:19 | [diff] [blame] | 91 | * ***Toggle Header/Source*** - |
| 92 | Toggles between .cc and .h with `F4`. The C/C++ extension supports this as |
| 93 | well through `Alt+O` but sometimes chooses the wrong file when there are |
| 94 | multiple files in the workspace that have the same name. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 95 | * ***Protobuf support*** - |
| 96 | Syntax highlighting for .proto files. |
Kenichi Ishibashi | b6d2e3b | 2020-04-22 18:16:07 | [diff] [blame] | 97 | * [***Mojom IDL support***](https://github.com/GoogleChromeLabs/mojom-language-support) - |
| 98 | Syntax highlighting and a |
| 99 | [language server](https://microsoft.github.io/language-server-protocol/) |
| 100 | for .mojom files. This isn't available on the VS Code marketplace for now. |
| 101 | You need to install it manually. |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 102 | * ***vscode-clangd*** - |
| 103 | If you do not plan to use VSCode for debugging, vscode-clangd is a great |
| 104 | alternative to C/C++ IntelliSense. It knows about how to compile Chromium, |
| 105 | enabling it to provide smarter autocomplete than C/C++ IntelliSense as well |
| 106 | as allowing you to jump from functions to their definitions. See |
| 107 | [clangd.md](clangd.md) for setup instructions. |
Tal Pressman | bcb58ae9 | 2020-06-02 23:36:10 | [diff] [blame] | 108 | If you need to debug, enable C/C++ extension but set "C_Cpp: Intelli Sense Engine" to disabled, |
| 109 | and restart VSCode. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 110 | * ***Rewrap*** - |
| 111 | Wrap lines at 80 characters with `Alt+Q`. |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 112 | * ***Remote*** - |
| 113 | Remotely connect to your workstation through SSH using your laptop. See the |
| 114 | [Remote](#Remote) section for more information about how to set this up. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 115 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 116 | The following extensions might be useful for you as well: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 117 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 118 | * ***Annotator*** - |
| 119 | Git blame view. |
| 120 | * ***Git History (git log)*** - |
| 121 | Git history view. |
| 122 | * ***chromium-codesearch*** - |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 123 | Mac and Linux only: adds ability to open the current line in [Chromium Code |
| 124 | Search](https://cs.chromium.org/). All other functionality is deprecated, so |
| 125 | currently only of limited usefulness. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 126 | * ***change-case*** - |
| 127 | Quickly change the case of the current selection or current word. |
| 128 | * ***Instant Markdown*** - |
| 129 | Instant markdown (.md) preview in your browser as you type. This document |
| 130 | was written with this extension! |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 131 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 132 | Also be sure to take a look at the |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 133 | [VS Code marketplace](https://marketplace.visualstudio.com/VSCode) to check out |
| 134 | other useful extensions. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 135 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 136 | ### Color Scheme |
| 137 | Press `Ctrl+Shift+P, color, Enter` to pick a color scheme for the editor. There |
| 138 | are also tons of [color schemes available for download on the |
| 139 | marketplace](https://marketplace.visualstudio.com/search?target=VSCode&category=Themes&sortBy=Downloads). |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 140 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 141 | ### Usage Tips |
| 142 | * `Ctrl+P` opens a search box to find and open a file. |
| 143 | * `F1` or `Ctrl+Shift+P` opens a search box to find a command (e.g. Tasks: Run |
| 144 | Task). |
| 145 | * `Ctrl+K, Ctrl+S` opens the key bindings editor. |
| 146 | * ``Ctrl+` `` toggles the built-in terminal. |
| 147 | * `Ctrl+Shift+M` toggles the problems view (linter warnings, compile errors |
Quinten Yearsley | 317532d | 2021-10-20 17:10:31 | [diff] [blame] | 148 | and warnings). You'll switch a lot between terminal and problem view during |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 149 | compilation. |
| 150 | * `Alt+O` switches between the source/header file. |
| 151 | * `Ctrl+G` jumps to a line. |
| 152 | * `F12` jumps to the definition of the symbol at the cursor (also available on |
| 153 | right-click context menu). |
| 154 | * `Shift+F12` or `F1, CodeSearchReferences, Return` shows all references of |
| 155 | the symbol at the cursor. |
| 156 | * `F1, CodeSearchOpen, Return` opens the current file in Code Search. |
| 157 | * `Ctrl+D` selects the word at the cursor. Pressing it multiple times |
| 158 | multi-selects the next occurrences, so typing in one types in all of them, |
| 159 | and `Ctrl+U` deselects the last occurrence. |
| 160 | * `Ctrl+K, Z` enters Zen Mode, a fullscreen editing mode with nothing but the |
| 161 | current editor visible. |
| 162 | * `Ctrl+X` without anything selected cuts the current line. `Ctrl+V` pastes |
| 163 | the line. |
| 164 | |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 165 | ### Java/Android Support |
Victor Hugo Vianna Silva | c37c9b7 | 2021-10-28 00:32:32 | [diff] [blame^] | 166 | |
| 167 | *Before anything*, add these to your settings.json. |
| 168 | ``` |
| 169 | // LightWeight is the language support, the feature we care about. The other |
| 170 | // modes include build functionality with Maven and Gradle. They try to build |
| 171 | // on their own and end up showing thousands of errors. |
| 172 | "java.server.launchMode": "LightWeight", |
| 173 | // Avoids overwriting the custom .classpath file (c.f. next section). |
| 174 | "java.configuration.updateBuildConfiguration": "disabled", |
| 175 | ``` |
| 176 | Then install the "Language Support for Java" extension. If you installed it |
| 177 | before setting the configs above, uninstall, delete the <project> folder (c.f. |
| 178 | next section) and reinstall. You also don't need any of the remaining extensions |
| 179 | in "Extension Pack for Java". |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 180 | |
| 181 | #### Setting up code completion/reference finding/etc. |
Mehran Mahmoudi | b96ca41 | 2020-03-25 21:48:14 | [diff] [blame] | 182 | You'll need to generate a placeholder .classpath file and locate it. In order |
| 183 | to generate it, right click on any Java source folder in the left panel and |
| 184 | choose "Add folder to java source path". Its location will depend on whether |
| 185 | you're doing local or remote development. Local path on linux will look |
| 186 | something like: |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 187 | |
| 188 | `~/.vscode/data/User/workspaceStorage/<hash>/redhat.java/jdt_ws/<project>/.classpath` |
| 189 | |
Mehran Mahmoudi | b96ca41 | 2020-03-25 21:48:14 | [diff] [blame] | 190 | You might find multiple folders when looking for `<project>`. Choose anything except |
| 191 | `jdt.ls-java-project`. If you only see `jdt.ls-java-project`, try using the |
| 192 | "Add folder to java source path" option again. |
| 193 | |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 194 | If doing remote development, the file will be under `~/.vscode-server/` on your |
| 195 | remote machine. |
| 196 | |
Michael Thiessen | e057a6c | 2020-03-25 19:24:01 | [diff] [blame] | 197 | You'll need to replace all of the contents of that file with the contents of |
| 198 | `tools/android/eclipse/.classpath` (external) or |
| 199 | `clank/development/ide/eclipse/.classpath` (generated by gclient runhooks for |
| 200 | Chrome developers), and then replace some paths as vscode interprets some paths |
| 201 | differently from eclipse. |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 202 | * Replace: `kind="src" path="` with `kind="src" path="_/` |
Michael Thiessen | e057a6c | 2020-03-25 19:24:01 | [diff] [blame] | 203 | * eg. `<classpathentry kind="src" path="_/android_webview/glue/java/src"/>` |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 204 | * Replace: `kind="lib" path="../src` with `kind="lib" path="_` |
Michael Thiessen | e057a6c | 2020-03-25 19:24:01 | [diff] [blame] | 205 | * eg. |
| 206 | `<classpathentry kind="lib" path="_/out/Debug/lib.java/base/base_java.jar"/>` |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 207 | * Remove all nested paths (or exclude them from their parents). At time of |
| 208 | writing: |
| 209 | * `third_party/android_protobuf/src/java/src/main/java` |
| 210 | * `third_party/junit/src/src/main/java` |
| 211 | |
Henry Jian | dabdddf | 2020-03-26 17:59:39 | [diff] [blame] | 212 | Also, make sure |
| 213 | `export ANDROID_HOME=/usr/local/google/home/{your_ldap}/Android/Sdk` is in the |
| 214 | remote machine's `~/.bashrc`. |
| 215 | |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 216 | Then restart vscode, open a Java file, and wait for a bit. |
| 217 | |
Michael Thiessen | e057a6c | 2020-03-25 19:24:01 | [diff] [blame] | 218 | Debugging tips: |
| 219 | * Right clicking on a folder in vscode and clicking "Add folder to java source |
| 220 | path" will error if there are syntax problems with your classpath. (Don't use |
| 221 | this actually add new paths to your classpath as it won't work correctly) |
| 222 | * If there are no syntax errors, ensure the correct .classpath file is being |
| 223 | used by seeing if the folder was actually added to the .classpath file you |
| 224 | edited. |
| 225 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 226 | ## Setup For Chromium |
| 227 | |
| 228 | VS Code is configured via JSON files. This paragraph contains JSON configuration |
| 229 | files that are useful for Chromium development, in particular. See [VS Code |
| 230 | documentation](https://code.visualstudio.com/docs/customization/overview) for an |
| 231 | introduction to VS Code customization. |
| 232 | |
| 233 | ### Workspace Settings |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 234 | Open the file [//tools/vscode/settings.json5](/tools/vscode/settings.json5), |
| 235 | and check out the default settings there. Feel free to commit added or removed |
| 236 | settings to enable better team development, or change settings locally to suit |
| 237 | personal preference. Remember to replace `<full_path_to_your_home>`! To use |
| 238 | these settings wholesale, enter the following commands into your terminal while |
| 239 | at the src directory: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 240 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 241 | $ mkdir .vscode/ |
| 242 | $ cp tools/vscode/settings.json5 .vscode/settings.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 243 | ``` |
| 244 | |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 245 | Note: these settings assume that the workspace folder (the root folder displayed |
Bartek Nowierski | fa835f8c | 2021-02-24 00:36:02 | [diff] [blame] | 246 | in the Explorer tab) is Chromium's `src/` directory. If this is not the case, |
| 247 | replace any references to ${workspaceFolder} with the path to your `src/`. |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 248 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 249 | ### Tasks |
Dan Harrington | b426cf9b | 2020-09-10 19:47:08 | [diff] [blame] | 250 | Next, we'll tell VS Code how to compile our code, run tests, and to read |
| 251 | warnings and errors from the build output. Open the file |
| 252 | [//tools/vscode/tasks.json5](/tools/vscode/tasks.json5). This will provide tasks |
| 253 | to do basic things. You might have to adjust the commands to your situation and |
| 254 | needs. To use these settings wholesale, enter the following command into your |
| 255 | terminal: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 256 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 257 | $ cp tools/vscode/tasks.json5 .vscode/tasks.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 258 | ``` |
| 259 | |
| 260 | ### Launch Commands |
| 261 | Launch commands are the equivalent of `F5` in Visual Studio: They launch some |
| 262 | program or a debugger. Optionally, they can run some task defined in |
| 263 | `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] | 264 | Open the file at [//tools/vscode/launch.json5](/tools/vscode/launch.json5) and |
Jesse McKenna | 37eceb8 | 2020-06-02 00:03:50 | [diff] [blame] | 265 | adjust the example launch commands to your situation and needs (e.g., the value |
| 266 | of "type" needs adjustment for Windows). To use these settings wholesale, enter |
| 267 | the following command into your terminal: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 268 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 269 | $ cp tools/vscode/launch.json5 .vscode/launch.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 270 | ``` |
| 271 | |
| 272 | ### Key Bindings |
| 273 | To edit key bindings, press `Ctrl+K, Ctrl+S`. You'll see the defaults on the |
| 274 | left and your overrides on the right stored in the file `keybindings.json`. To |
| 275 | change a key binding, copy the corresponding key binding to the right. It's |
| 276 | fairly self-explanatory. |
| 277 | |
| 278 | You can bind any command to a key, even commands specified by extensions like |
| 279 | `CodeSearchOpen`. For instance, to bind `CodeSearchOpen` to `F2` to , simply add |
| 280 | `{ "key": "F2", "command": "cs.open" },`. |
| 281 | Note that the command title `CodeSearchOpen` won't work. You have to get the |
| 282 | actual command name from the [package.json |
| 283 | file](https://github.com/chaopeng/vscode-chromium-codesearch/blob/master/package.json) |
| 284 | of the extension. |
| 285 | |
| 286 | If you are used to other editors, you can also install your favorite keymap. |
| 287 | For instance, to install eclipse keymaps, install the |
| 288 | `vscode-eclipse-keybindings` extension. More keymaps can be found |
| 289 | [in the marketplace](https://marketplace.visualstudio.com/search?target=vscode&category=Keymaps). |
| 290 | |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 291 | Some key bindings that are likely to be useful for you are available at |
| 292 | [//tools/vscode/keybindings.json5](/tools/vscode/keybindings.json5). Please |
| 293 | take a look and adjust them to your situation and needs. To use these settings |
| 294 | wholesale, enter the following command into your terminal: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 295 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 296 | $ cp tools/vscode/keybindings.json5 .vscode/keybindings.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 297 | ``` |
| 298 | |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 299 | ### Remote |
| 300 | VSCode now has a |
| 301 | [Remote](https://code.visualstudio.com/docs/remote/remote-overview) framework |
| 302 | that allows you to use VSCode on your laptop while your code is hosted |
| 303 | elsewhere. This really shines when used in conjunction with the vscode-clangd plugin, |
| 304 | which allows clangd to run remotely as well. |
| 305 | |
| 306 | To get this to run, install the Remote pack extension, and then make sure your |
| 307 | ssh config file has your remote connection: |
| 308 | |
| 309 | `~/.ssh/config`: |
| 310 | ``` |
| 311 | Host my-connection |
| 312 | HostName my-remote-host.corp.company.com |
| 313 | ``` |
| 314 | |
| 315 | VSCode will then list this connection in the 'Remote Explorer' section on the |
| 316 | left. To launch VSCode with this connection, click on the '+window' icon next |
| 317 | to the listed hostname. It has you choose a folder - use the 'src' folder root. |
| 318 | This will open a new VSCode window in 'Remote' mode. ***Now you can install |
| 319 | extensions specifically for your remote connection, like vscode-clangd, etc.*** |
| 320 | |
Peter Wen | 3ba9120 | 2020-06-17 15:56:54 | [diff] [blame] | 321 | #### Chromebooks |
| 322 | |
| 323 | For Googlers, [here](http://go/vscode/remote_development_via_web) are |
| 324 | Google-specific instructions for setting up remote development on chromebooks |
| 325 | without using Crostini. |
| 326 | |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 327 | #### Windows & SSH |
Yuwei Huang | 1c4f50c | 2021-08-06 22:41:56 | [diff] [blame] | 328 | |
| 329 | VSCode remote tools requires 'sshd' which isn't installed on Windows by default. |
| 330 | |
| 331 | For Googlers, sshd should already be installed on your workstation, and VSCode |
| 332 | should work remotely if you followed the setup instructions at |
| 333 | [go/building-chrome-win](http://go/building-chrome-win). If you are still having |
| 334 | problems, please refer to |
| 335 | [go/vscode-remote#windows](http://go/vscode-remote#windows). |
| 336 | |
| 337 | Non-Googlers may follow may follow Microsoft's instructions for |
| 338 | [installing the OpenSSH server](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse). |
| 339 | VSCode should work remotely after following this step. |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 340 | |
Dan Harrington | b06ce2f | 2019-04-09 15:35:29 | [diff] [blame] | 341 | ### Snippets |
| 342 | There are some useful snippets provided in |
| 343 | [//tools/vscode/cpp.json5](/tools/vscode/cpp.json5). |
| 344 | |
Mounir Lamouri | 3b9e31d | 2019-07-30 20:14:41 | [diff] [blame] | 345 | You can either install them in your user profile (path may vary depending on the |
| 346 | platform): |
| 347 | ``` |
| 348 | $ cp tools/vscode/cpp.json5 ~/.config/Code/User/snippets/cpp.json |
| 349 | ``` |
| 350 | |
| 351 | Or install them as project snippets after installing the [Project |
| 352 | Snippets](https://marketplace.visualstudio.com/items?itemName=rebornix.project-snippets) |
| 353 | extension: |
| 354 | ``` |
| 355 | $ cp tools/vscode/cpp.json5 .vscode/snippets/cpp.json |
| 356 | ``` |
| 357 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 358 | ### Tips |
| 359 | |
| 360 | #### The `out` folder |
| 361 | Automatically generated code is put into a subfolder of out/, which means that |
| 362 | 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] | 363 | opened e.g. from quick-open (`Ctrl+P`). |
| 364 | As of version 1.21, VS Code does not support negated glob commands, but you can |
| 365 | define a set of exclude pattern to include only out/Debug/gen: |
Christian Dullweber | babb96e1 | 2018-05-28 14:00:14 | [diff] [blame] | 366 | ``` |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 367 | "files.exclude": { |
| 368 | // Ignore build output folders. Except out/Debug/gen/ |
| 369 | "out/[^D]*/": true, |
| 370 | "out/Debug/[^g]*": true, |
| 371 | "out/Debug/g[^e]*": true, |
| 372 | "out_*/**": true, |
| 373 | }, |
Christian Dullweber | babb96e1 | 2018-05-28 14:00:14 | [diff] [blame] | 374 | ``` |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 375 | |
| 376 | Once it does, you can use |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 377 | ``` |
| 378 | "!out/Debug/gen/**": true |
| 379 | ``` |
| 380 | in files.exclude instead of the symlink. |
| 381 | |
| 382 | #### Using VS Code as git editor |
| 383 | Add `[core] editor = "code --wait"` to your `~/.gitconfig` file in order to use |
| 384 | VS Code as editor for git commit messages etc. Note that the editor starts up |
| 385 | significantly slower than nano or vim. To use VS Code as merge tool, add |
| 386 | `[merge] tool = code`. |
| 387 | |
| 388 | #### Task Names |
| 389 | Note that we named the tasks `1-build_chrome_debug`, `2-build_chrome_release` |
| 390 | etc. This allows you to quickly execute tasks by pressing their number: |
| 391 | Press `Ctrl+P` and enter `task <n>`, where `<n>` is the number of the task. You |
| 392 | can also create a keyboard shortcut for running a task. `File > Preferences > |
| 393 | Keyboard Shortcuts` and add `{ "key": "ctrl+r", "command": |
| 394 | "workbench.action.tasks.runTask", "when": "!inDebugMode" }`. Then it's |
| 395 | sufficient to press `Ctrl+R` and enter `<n>`. |
| 396 | |
| 397 | #### Working on Laptop |
Bartek Nowierski | fa835f8c | 2021-02-24 00:36:02 | [diff] [blame] | 398 | You might want to disable git status autorefresh to save battery. |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 399 | |
| 400 | ``` |
chaopeng | 5c66dfe | 2017-03-22 13:51:45 | [diff] [blame] | 401 | "git.autorefresh": false, |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 402 | ``` |
| 403 | |
Tommy Nyquist | dc2ceaa4 | 2021-03-15 20:29:04 | [diff] [blame] | 404 | #### Editing in multiple Git repositories |
| 405 | If you frequently work in multiple Git repositories that are part of the Chromium repository, you might find that the built-in tooling does not work as expected for files that exist below folders that are part of a `.gitignore` file checked in to Chromium. |
| 406 | |
| 407 | To work around this, you can add the directories you edit as separate `folders` entries in your workspace configuration, and ensure that the directories that are ignored in Chromium are listed **before** the Chromium `src` path. |
| 408 | |
| 409 | To edit this, go to `Settings` -> Select the `Workspace` tab, and choose to open as JSON (button in the top right), and configure `folders` like this (change paths to match your local setup and usage): |
| 410 | |
| 411 | ``` |
| 412 | { |
| 413 | "folders": [ |
| 414 | { |
| 415 | "path": "chromium/src/third_party/perfetto" |
| 416 | }, |
| 417 | { |
| 418 | "path": "chromium/src" |
| 419 | } |
| 420 | ] |
| 421 | } |
| 422 | ``` |
| 423 | |
Jianpeng Chao | b4048b8 | 2018-08-28 23:40:01 | [diff] [blame] | 424 | ### Unable to open $File resource is not available when debugging Chromium on Linux |
| 425 | Chromium [recently changed](https://docs.google.com/document/d/1OX4jY_bOCeNK7PNjVRuBQE9s6BQKS8XRNWGK8FEyh-E/edit?usp=sharing) |
| 426 | the file path to be relative to the output dir. Check |
| 427 | `gn args out/$dir --list` if `strip_absolute_paths_from_debug_symbols` is true (which is the default), |
| 428 | set `cwd` to the output dir. otherwise, set `cwd` to `${workspaceRoot}`. |
| 429 | |
Bartek Nowierski | fa835f8c | 2021-02-24 00:36:02 | [diff] [blame] | 430 | ### You-Complete-Me |
| 431 | The You-Complete-Me VS Code extension is now |
| 432 | [deprecated](https://github.com/richard1122/vscode-youcompleteme#deprecated) |
| 433 | with a suggestion to use clangd. |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 434 | |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 435 | ### More |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 436 | More tips and tricks can be found |
sangwoo.ko | 5fe74c73 | 2017-09-01 14:44:56 | [diff] [blame] | 437 | [here](https://github.com/Microsoft/vscode-tips-and-tricks/blob/master/README.md). |