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 |
James Cook | 9d7e219 | 2017-06-19 19:59:09 | [diff] [blame] | 46 | guidelines](https://chromium.googlesource.com/chromium/src/+/master/docs/documentation_guidelines.md) |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 47 | and [submit a change list](https://www.chromium.org/developers/contributing-code). |
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 |
| 58 | run it on Linux, just navigate to `chromium/src` folder and type `code .` in a |
| 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 | |
Mounir Lamouri | 1679feab | 2019-01-25 19:30:03 | [diff] [blame] | 78 | #### Rendering of underscore on Linux |
| 79 | |
| 80 | As mentioned in [#35901](https://github.com/Microsoft/vscode/issues/35901), VS |
| 81 | Code will not show underscore (`_`) properly on Linux by default. You can work |
| 82 | around this issue by forcing another font such as the default `monospace` or |
| 83 | changing the font size in your settings: |
| 84 | |
| 85 | ```json |
| 86 | { |
| 87 | // If you want to use the default "monospace" font: |
| 88 | //"terminal.integrated.fontFamily": "monospace" |
| 89 | // If you would rather just increase the size of the font: |
| 90 | //"terminal.integrated.fontSize": 15 |
| 91 | // If you would rather decrease the size of the font: |
Mounir Lamouri | a1e5a9e | 2019-07-30 20:06:00 | [diff] [blame] | 92 | //"terminal.integrated.fontSize": 13 |
Mounir Lamouri | 1679feab | 2019-01-25 19:30:03 | [diff] [blame] | 93 | } |
| 94 | ``` |
| 95 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 96 | ### Useful Extensions |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 97 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 98 | Up to now, you have a basic version of VS Code without much language support. |
| 99 | Next, we will install some useful extensions. Jump to the extensions window |
| 100 | (`Ctrl+Shift+X`) and install these extensions, you will most likely use them |
| 101 | every day: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 102 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 103 | * ***C/C++*** - |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 104 | Code formatting, debugging, Intellisense. Enables the use of clang-format |
| 105 | (via the `C_Cpp.clang_format_path` setting) and format-on-save (via the |
| 106 | `editor.formatOnSave` setting). |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 107 | * ***Python*** - |
| 108 | Linting, intellisense, code formatting, refactoring, debugging, snippets. |
James Cook | 9f7c73d | 2017-06-20 15:06:19 | [diff] [blame] | 109 | * ***Toggle Header/Source*** - |
| 110 | Toggles between .cc and .h with `F4`. The C/C++ extension supports this as |
| 111 | well through `Alt+O` but sometimes chooses the wrong file when there are |
| 112 | multiple files in the workspace that have the same name. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 113 | * ***Protobuf support*** - |
| 114 | Syntax highlighting for .proto files. |
Kenichi Ishibashi | b6d2e3b | 2020-04-22 18:16:07 | [diff] [blame] | 115 | * [***Mojom IDL support***](https://github.com/GoogleChromeLabs/mojom-language-support) - |
| 116 | Syntax highlighting and a |
| 117 | [language server](https://microsoft.github.io/language-server-protocol/) |
| 118 | for .mojom files. This isn't available on the VS Code marketplace for now. |
| 119 | You need to install it manually. |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 120 | * ***vscode-clangd*** - |
| 121 | If you do not plan to use VSCode for debugging, vscode-clangd is a great |
| 122 | alternative to C/C++ IntelliSense. It knows about how to compile Chromium, |
| 123 | enabling it to provide smarter autocomplete than C/C++ IntelliSense as well |
| 124 | as allowing you to jump from functions to their definitions. See |
| 125 | [clangd.md](clangd.md) for setup instructions. |
Tal Pressman | bcb58ae9 | 2020-06-02 23:36:10 | [diff] [blame] | 126 | If you need to debug, enable C/C++ extension but set "C_Cpp: Intelli Sense Engine" to disabled, |
| 127 | and restart VSCode. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 128 | * ***Rewrap*** - |
| 129 | Wrap lines at 80 characters with `Alt+Q`. |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 130 | * ***Remote*** - |
| 131 | Remotely connect to your workstation through SSH using your laptop. See the |
| 132 | [Remote](#Remote) section for more information about how to set this up. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 133 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 134 | The following extensions might be useful for you as well: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 135 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 136 | * ***Annotator*** - |
| 137 | Git blame view. |
| 138 | * ***Git History (git log)*** - |
| 139 | Git history view. |
| 140 | * ***chromium-codesearch*** - |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 141 | Mac and Linux only: adds ability to open the current line in [Chromium Code |
| 142 | Search](https://cs.chromium.org/). All other functionality is deprecated, so |
| 143 | currently only of limited usefulness. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 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! |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 149 | * ***you-complete-me*** - |
| 150 | Alternative autocomplete extension. Can be configured to use a variety of |
| 151 | language servers, so helpful if not using clangd for code completion. |
| 152 | See [You-Complete-Me extension setup](#You-Complete-Me-extension-setup) |
| 153 | for additional setup instructions. |
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 |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 156 | [VS Code marketplace](https://marketplace.visualstudio.com/VSCode) to check out |
| 157 | other 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 | |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 188 | ### Java/Android Support |
| 189 | To get Java support in VS Code, you'll need to install the |
| 190 | 'Java Extension Pack' extension, but you'll want to immediately uninstall or |
| 191 | disable the Maven for Java extension so it stops nagging you as we won't need |
| 192 | it. |
| 193 | |
| 194 | #### Setting up code completion/reference finding/etc. |
Mehran Mahmoudi | b96ca41 | 2020-03-25 21:48:14 | [diff] [blame] | 195 | You'll need to generate a placeholder .classpath file and locate it. In order |
| 196 | to generate it, right click on any Java source folder in the left panel and |
| 197 | choose "Add folder to java source path". Its location will depend on whether |
| 198 | you're doing local or remote development. Local path on linux will look |
| 199 | something like: |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 200 | |
| 201 | `~/.vscode/data/User/workspaceStorage/<hash>/redhat.java/jdt_ws/<project>/.classpath` |
| 202 | |
Mehran Mahmoudi | b96ca41 | 2020-03-25 21:48:14 | [diff] [blame] | 203 | You might find multiple folders when looking for `<project>`. Choose anything except |
| 204 | `jdt.ls-java-project`. If you only see `jdt.ls-java-project`, try using the |
| 205 | "Add folder to java source path" option again. |
| 206 | |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 207 | If doing remote development, the file will be under `~/.vscode-server/` on your |
| 208 | remote machine. |
| 209 | |
Michael Thiessen | e057a6c | 2020-03-25 19:24:01 | [diff] [blame] | 210 | You'll need to replace all of the contents of that file with the contents of |
| 211 | `tools/android/eclipse/.classpath` (external) or |
| 212 | `clank/development/ide/eclipse/.classpath` (generated by gclient runhooks for |
| 213 | Chrome developers), and then replace some paths as vscode interprets some paths |
| 214 | differently from eclipse. |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 215 | * Replace: `kind="src" path="` with `kind="src" path="_/` |
Michael Thiessen | e057a6c | 2020-03-25 19:24:01 | [diff] [blame] | 216 | * eg. `<classpathentry kind="src" path="_/android_webview/glue/java/src"/>` |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 217 | * Replace: `kind="lib" path="../src` with `kind="lib" path="_` |
Michael Thiessen | e057a6c | 2020-03-25 19:24:01 | [diff] [blame] | 218 | * eg. |
| 219 | `<classpathentry kind="lib" path="_/out/Debug/lib.java/base/base_java.jar"/>` |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 220 | * Remove all nested paths (or exclude them from their parents). At time of |
| 221 | writing: |
| 222 | * `third_party/android_protobuf/src/java/src/main/java` |
| 223 | * `third_party/junit/src/src/main/java` |
| 224 | |
Henry Jian | dabdddf | 2020-03-26 17:59:39 | [diff] [blame] | 225 | Also, make sure |
| 226 | `export ANDROID_HOME=/usr/local/google/home/{your_ldap}/Android/Sdk` is in the |
| 227 | remote machine's `~/.bashrc`. |
| 228 | |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 229 | Then restart vscode, open a Java file, and wait for a bit. |
| 230 | |
Michael Thiessen | e057a6c | 2020-03-25 19:24:01 | [diff] [blame] | 231 | Debugging tips: |
| 232 | * Right clicking on a folder in vscode and clicking "Add folder to java source |
| 233 | path" will error if there are syntax problems with your classpath. (Don't use |
| 234 | this actually add new paths to your classpath as it won't work correctly) |
| 235 | * If there are no syntax errors, ensure the correct .classpath file is being |
| 236 | used by seeing if the folder was actually added to the .classpath file you |
| 237 | edited. |
| 238 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 239 | ## Setup For Chromium |
| 240 | |
| 241 | VS Code is configured via JSON files. This paragraph contains JSON configuration |
| 242 | files that are useful for Chromium development, in particular. See [VS Code |
| 243 | documentation](https://code.visualstudio.com/docs/customization/overview) for an |
| 244 | introduction to VS Code customization. |
| 245 | |
| 246 | ### Workspace Settings |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 247 | Open the file [//tools/vscode/settings.json5](/tools/vscode/settings.json5), |
| 248 | and check out the default settings there. Feel free to commit added or removed |
| 249 | settings to enable better team development, or change settings locally to suit |
| 250 | personal preference. Remember to replace `<full_path_to_your_home>`! To use |
| 251 | these settings wholesale, enter the following commands into your terminal while |
| 252 | at the src directory: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 253 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 254 | $ mkdir .vscode/ |
| 255 | $ cp tools/vscode/settings.json5 .vscode/settings.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 256 | ``` |
| 257 | |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 258 | Note: these settings assume that the workspace folder (the root folder displayed |
| 259 | in the Explorer tab) is chromium/src. If this is not the case, replace any |
| 260 | references to ${workspaceFolder} with the path to chromium/src. |
| 261 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 262 | ### Tasks |
Dan Harrington | b426cf9b | 2020-09-10 19:47:08 | [diff] [blame] | 263 | Next, we'll tell VS Code how to compile our code, run tests, and to read |
| 264 | warnings and errors from the build output. Open the file |
| 265 | [//tools/vscode/tasks.json5](/tools/vscode/tasks.json5). This will provide tasks |
| 266 | to do basic things. You might have to adjust the commands to your situation and |
| 267 | needs. To use these settings wholesale, enter the following command into your |
| 268 | 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/tasks.json5 .vscode/tasks.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 271 | ``` |
| 272 | |
| 273 | ### Launch Commands |
| 274 | Launch commands are the equivalent of `F5` in Visual Studio: They launch some |
| 275 | program or a debugger. Optionally, they can run some task defined in |
| 276 | `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] | 277 | Open the file at [//tools/vscode/launch.json5](/tools/vscode/launch.json5) and |
Jesse McKenna | 37eceb8 | 2020-06-02 00:03:50 | [diff] [blame] | 278 | adjust the example launch commands to your situation and needs (e.g., the value |
| 279 | of "type" needs adjustment for Windows). To use these settings wholesale, enter |
| 280 | the following command into your terminal: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 281 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 282 | $ cp tools/vscode/launch.json5 .vscode/launch.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 283 | ``` |
| 284 | |
| 285 | ### Key Bindings |
| 286 | To edit key bindings, press `Ctrl+K, Ctrl+S`. You'll see the defaults on the |
| 287 | left and your overrides on the right stored in the file `keybindings.json`. To |
| 288 | change a key binding, copy the corresponding key binding to the right. It's |
| 289 | fairly self-explanatory. |
| 290 | |
| 291 | You can bind any command to a key, even commands specified by extensions like |
| 292 | `CodeSearchOpen`. For instance, to bind `CodeSearchOpen` to `F2` to , simply add |
| 293 | `{ "key": "F2", "command": "cs.open" },`. |
| 294 | Note that the command title `CodeSearchOpen` won't work. You have to get the |
| 295 | actual command name from the [package.json |
| 296 | file](https://github.com/chaopeng/vscode-chromium-codesearch/blob/master/package.json) |
| 297 | of the extension. |
| 298 | |
| 299 | If you are used to other editors, you can also install your favorite keymap. |
| 300 | For instance, to install eclipse keymaps, install the |
| 301 | `vscode-eclipse-keybindings` extension. More keymaps can be found |
| 302 | [in the marketplace](https://marketplace.visualstudio.com/search?target=vscode&category=Keymaps). |
| 303 | |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 304 | Some key bindings that are likely to be useful for you are available at |
| 305 | [//tools/vscode/keybindings.json5](/tools/vscode/keybindings.json5). Please |
| 306 | take a look and adjust them to your situation and needs. To use these settings |
| 307 | wholesale, enter the following command into your terminal: |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 308 | ``` |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 309 | $ cp tools/vscode/keybindings.json5 .vscode/keybindings.json |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 310 | ``` |
| 311 | |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 312 | ### Remote |
| 313 | VSCode now has a |
| 314 | [Remote](https://code.visualstudio.com/docs/remote/remote-overview) framework |
| 315 | that allows you to use VSCode on your laptop while your code is hosted |
| 316 | elsewhere. This really shines when used in conjunction with the vscode-clangd plugin, |
| 317 | which allows clangd to run remotely as well. |
| 318 | |
| 319 | To get this to run, install the Remote pack extension, and then make sure your |
| 320 | ssh config file has your remote connection: |
| 321 | |
| 322 | `~/.ssh/config`: |
| 323 | ``` |
| 324 | Host my-connection |
| 325 | HostName my-remote-host.corp.company.com |
| 326 | ``` |
| 327 | |
| 328 | VSCode will then list this connection in the 'Remote Explorer' section on the |
| 329 | left. To launch VSCode with this connection, click on the '+window' icon next |
| 330 | to the listed hostname. It has you choose a folder - use the 'src' folder root. |
| 331 | This will open a new VSCode window in 'Remote' mode. ***Now you can install |
| 332 | extensions specifically for your remote connection, like vscode-clangd, etc.*** |
| 333 | |
Peter Wen | 3ba9120 | 2020-06-17 15:56:54 | [diff] [blame] | 334 | #### Chromebooks |
| 335 | |
| 336 | For Googlers, [here](http://go/vscode/remote_development_via_web) are |
| 337 | Google-specific instructions for setting up remote development on chromebooks |
| 338 | without using Crostini. |
| 339 | |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 340 | #### Windows & SSH |
| 341 | This currently is difficult on Windows because VSCode remote tools assumes |
| 342 | 'sshd' is installed, which isn't the case on Windows. If someone figures out |
| 343 | how to get vscode remote working on windows with ssh please update this |
| 344 | document :) |
| 345 | |
Dan Harrington | b06ce2f | 2019-04-09 15:35:29 | [diff] [blame] | 346 | ### Snippets |
| 347 | There are some useful snippets provided in |
| 348 | [//tools/vscode/cpp.json5](/tools/vscode/cpp.json5). |
| 349 | |
Mounir Lamouri | 3b9e31d | 2019-07-30 20:14:41 | [diff] [blame] | 350 | You can either install them in your user profile (path may vary depending on the |
| 351 | platform): |
| 352 | ``` |
| 353 | $ cp tools/vscode/cpp.json5 ~/.config/Code/User/snippets/cpp.json |
| 354 | ``` |
| 355 | |
| 356 | Or install them as project snippets after installing the [Project |
| 357 | Snippets](https://marketplace.visualstudio.com/items?itemName=rebornix.project-snippets) |
| 358 | extension: |
| 359 | ``` |
| 360 | $ cp tools/vscode/cpp.json5 .vscode/snippets/cpp.json |
| 361 | ``` |
| 362 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 363 | ### Tips |
| 364 | |
| 365 | #### The `out` folder |
| 366 | Automatically generated code is put into a subfolder of out/, which means that |
| 367 | 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] | 368 | opened e.g. from quick-open (`Ctrl+P`). |
| 369 | As of version 1.21, VS Code does not support negated glob commands, but you can |
| 370 | define a set of exclude pattern to include only out/Debug/gen: |
Christian Dullweber | babb96e1 | 2018-05-28 14:00:14 | [diff] [blame] | 371 | ``` |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 372 | "files.exclude": { |
| 373 | // Ignore build output folders. Except out/Debug/gen/ |
| 374 | "out/[^D]*/": true, |
| 375 | "out/Debug/[^g]*": true, |
| 376 | "out/Debug/g[^e]*": true, |
| 377 | "out_*/**": true, |
| 378 | }, |
Christian Dullweber | babb96e1 | 2018-05-28 14:00:14 | [diff] [blame] | 379 | ``` |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 380 | |
| 381 | Once it does, you can use |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 382 | ``` |
| 383 | "!out/Debug/gen/**": true |
| 384 | ``` |
| 385 | in files.exclude instead of the symlink. |
| 386 | |
| 387 | #### Using VS Code as git editor |
| 388 | Add `[core] editor = "code --wait"` to your `~/.gitconfig` file in order to use |
| 389 | VS Code as editor for git commit messages etc. Note that the editor starts up |
| 390 | significantly slower than nano or vim. To use VS Code as merge tool, add |
| 391 | `[merge] tool = code`. |
| 392 | |
| 393 | #### Task Names |
| 394 | Note that we named the tasks `1-build_chrome_debug`, `2-build_chrome_release` |
| 395 | etc. This allows you to quickly execute tasks by pressing their number: |
| 396 | Press `Ctrl+P` and enter `task <n>`, where `<n>` is the number of the task. You |
| 397 | can also create a keyboard shortcut for running a task. `File > Preferences > |
| 398 | Keyboard Shortcuts` and add `{ "key": "ctrl+r", "command": |
| 399 | "workbench.action.tasks.runTask", "when": "!inDebugMode" }`. Then it's |
| 400 | sufficient to press `Ctrl+R` and enter `<n>`. |
| 401 | |
| 402 | #### Working on Laptop |
| 403 | Because autocomplete is provided by the You-Complete-Me extension, consider |
| 404 | disabling C/C++ autocomplete and indexing to save battery. In addition, you |
| 405 | might want to disable git status autorefresh as well. |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 406 | |
| 407 | ``` |
chaopeng | 5c66dfe | 2017-03-22 13:51:45 | [diff] [blame] | 408 | "git.autorefresh": false, |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 409 | "C_Cpp.autocomplete": "Disabled", |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 410 | ``` |
| 411 | |
Jianpeng Chao | b4048b8 | 2018-08-28 23:40:01 | [diff] [blame] | 412 | ### Unable to open $File resource is not available when debugging Chromium on Linux |
| 413 | Chromium [recently changed](https://docs.google.com/document/d/1OX4jY_bOCeNK7PNjVRuBQE9s6BQKS8XRNWGK8FEyh-E/edit?usp=sharing) |
| 414 | the file path to be relative to the output dir. Check |
| 415 | `gn args out/$dir --list` if `strip_absolute_paths_from_debug_symbols` is true (which is the default), |
| 416 | set `cwd` to the output dir. otherwise, set `cwd` to `${workspaceRoot}`. |
| 417 | |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 418 | ### You-Complete-Me extension setup |
| 419 | If using the You-Complete-Me extension, complete its installation by entering |
| 420 | these commands in a terminal: |
| 421 | |
| 422 | ``` |
| 423 | $ git clone https://github.com/Valloric/ycmd.git ~/.ycmd |
| 424 | $ cd ~/.ycmd |
| 425 | $ git submodule update --init --recursive |
| 426 | $ ./build.py --clang-completer |
| 427 | ``` |
| 428 | If it fails with "Your C++ compiler does NOT fully support C++11." but you know |
| 429 | you have a good compiler, hack cpp/CMakeLists.txt to set CPP11_AVAILABLE true. |
| 430 | |
| 431 | On Mac, replace the last command above with the following. |
| 432 | |
| 433 | ``` |
| 434 | $ ./build.py --clang-completer --system-libclang |
| 435 | ``` |
| 436 | |
| 437 | On Windows, if depot_tools' Python is the only one installed, a separate Python |
| 438 | 3 install is needed. The last command should then be run as follows. |
| 439 | |
| 440 | ``` |
| 441 | > <Python 3 directory>/python.exe build.py --clang-completer |
| 442 | ``` |
| 443 | |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 444 | ### More |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 445 | More tips and tricks can be found |
sangwoo.ko | 5fe74c73 | 2017-09-01 14:44:56 | [diff] [blame] | 446 | [here](https://github.com/Microsoft/vscode-tips-and-tricks/blob/master/README.md). |