blob: c8c46f456174628ea1aee1a44d4211c324f624cf [file] [log] [blame] [view]
ljustene262c842017-04-12 08:29:041# Visual Studio Code Dev
2
Ming-Ying Chunga7db9dde82022-07-12 06:31:543**Get started [here](#setup)**.
4
5[Visual Studio Code (VS Code)](https://code.visualstudio.com) is a free,
6open source, lightweight and powerful code editor for Windows, Mac and Linux,
7based on [Electron](https://www.electronjs.org/)/Chromium.
8It has built-in support for JavaScript, TypeScript and Node.js and a rich
9extension ecosystem that adds intellisense, debugging, syntax highlighting etc.
10For many languages like C++, Python, Go, Java, it works without too much setup.
ljustene262c842017-04-12 08:29:0411
12It is NOT a full-fledged IDE like Visual Studio. The two are completely
13separate products. The only commonality with Visual Studio is that both are
14from Microsoft.
15
16Here's what works well:
17
Ming-Ying Chunga7db9dde82022-07-12 06:31:5418* **Editing code** works well especially when you get used to the [keyboard
19 shortcuts](#Keyboard-Shortcuts). VS Code is very responsive and can handle
20 even big code bases like Chromium.
21* **Git integration** is a blast. Built-in side-by-side view, local commit and
ljustene262c842017-04-12 08:29:0422 even extensions for
23 [history](https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory)
24 and
25 [blame view](https://marketplace.visualstudio.com/items?itemName=ryu1kn.annotator).
Ming-Ying Chunga7db9dde82022-07-12 06:31:5426* [**Debugging**](https://code.visualstudio.com/Docs/editor/debugging) works
ljustene262c842017-04-12 08:29:0427 well, even though startup times can be fairly high (~40 seconds with
28 gdb on Linux, much lower on Windows). You can step through code, inspect
29 variables, view call stacks for multiple threads etc.
Ryan Heise9a711432020-10-14 23:55:3930 * For more information on debugging Python code, see [here](vscode_python.md).
Ming-Ying Chunga7db9dde82022-07-12 06:31:5431* **Command Palette** makes opening files and searching solution really easy.
32* **Building** works well. Build tools are easy to integrate. Warnings and errors
ljustene262c842017-04-12 08:29:0433 are displayed on a separate page and you can click to jump to the
34 corresponding line of code.
Ming-Ying Chunga7db9dde82022-07-12 06:31:5435* **VS Code Remote**, which allows you to edit remotely-hosted code, and even
36 run computationally expensive plugins like vscode-clangd on the remote
37 server. Great for working from home. See the [Remote section](#Remote) for
38 more details.
chaopengba312ce2017-02-12 03:38:2539
chaopengca285112017-03-02 15:39:0440[TOC]
41
Ming-Ying Chunga7db9dde82022-07-12 06:31:5442
ljustene262c842017-04-12 08:29:0443## Updating This Page
chaopengba312ce2017-02-12 03:38:2544
ljustene262c842017-04-12 08:29:0445Please keep this doc up-to-date. VS Code is still in active development and
46subject to changes. This doc is checked into the Chromium git repo, so if you
47make changes, read the [documentation
Ming-Ying Chunga7db9dde82022-07-12 06:31:5448guidelines](documentation_guidelines.md) and
49[submit a change list](contributing.md).
chaopengba312ce2017-02-12 03:38:2550
ljustene262c842017-04-12 08:29:0451All file paths and commands have been tested on Linux. Windows and Mac might
52require a slightly different setup (e.g. `Ctrl` -> `Cmd`). Please update this
53page accordingly.
chaopengba312ce2017-02-12 03:38:2554
Ming-Ying Chunga7db9dde82022-07-12 06:31:5455
ljustene262c842017-04-12 08:29:0456## Setup
chaopengba312ce2017-02-12 03:38:2557
ljustene262c842017-04-12 08:29:0458### Installation
chaopengba312ce2017-02-12 03:38:2559
Ming-Ying Chunga7db9dde82022-07-12 06:31:5460*** promo
61Googlers: See [go/vscode/install](http://go/vscode/install).
62***
63
64Follow the steps on [Setting up Visual Studio Code](https://code.visualstudio.com/docs/setup/setup-overview).
65
66### Usage
67
68To run it on Linux, just navigate to Chromium's `src` folder and type `code .`
69in a terminal. The argument to `code` is the base directory of the workspace. VS
ljustene262c842017-04-12 08:29:0470Code does not require project or solution files. However, it does store
71workspace settings in a `.vscode` folder in your base directory.
chaopengba312ce2017-02-12 03:38:2572
Daniel Cheng2d4c2d192022-07-01 01:38:3173If you installed Code Insiders, the binary name is `code-insiders` instead.
74
Mounir Lamouri1679feab2019-01-25 19:30:0375### Fixes for Known Issues
76
77#### Git on Windows
Mounir Lamouri8202f362019-01-14 11:48:2678
79If you only have the `depot_tools` Git installed on your machine, even though it
80is in your PATH, VS Code will ignore it as it seems to be looking for `git.exe`.
81You will have to add the following to your settings in order for the Git
82integration to work:
83
Mounir Lamouri1679feab2019-01-25 19:30:0384```json
Mounir Lamouri8202f362019-01-14 11:48:2685{
86 "git.path": "C:\\src\\depot_tools\\git.bat"
Daniel Cheng2d4c2d192022-07-01 01:38:3187
88 // more settings here...
Mounir Lamouri8202f362019-01-14 11:48:2689}
90```
91
Daniel Cheng2d4c2d192022-07-01 01:38:3192Tip: you can jump to the settings JSON file by using `Ctrl+Shift+P` and using
93the "Preferences: Open User Settings (JSON)" verb (for whatever reason, setting
94`git.path` as a folder setting does not appear to work).
95
ljustene262c842017-04-12 08:29:0496### Useful Extensions
chaopengba312ce2017-02-12 03:38:2597
ljustene262c842017-04-12 08:29:0498Up to now, you have a basic version of VS Code without much language support.
99Next, we will install some useful extensions. Jump to the extensions window
Ming-Ying Chunga7db9dde82022-07-12 06:31:54100(`Ctrl+Shift+X`) and install the extensions, or run the following commands.
chaopengba312ce2017-02-12 03:38:25101
Ming-Ying Chunga7db9dde82022-07-12 06:31:54102You will most likely use the following extensions every day:
103
104```bash
105$ echo "ms-vscode.cpptools llvm-vs-code-extensions.vscode-clangd ms-python.python bbenoist.togglehs peterj.proto Google.vscode-mojom npclaudiu.vscode-gn stkb.rewrap ms-vscode-remote.remote-ssh eamodio.gitlens" | xargs -n 1 code --install-extension --force
106```
107
108* [**C/C++**](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) -
Jesse McKennafffd8112020-05-08 19:18:48109 Code formatting, debugging, Intellisense. Enables the use of clang-format
110 (via the `C_Cpp.clang_format_path` setting) and format-on-save (via the
111 `editor.formatOnSave` setting).
Ming-Ying Chunga7db9dde82022-07-12 06:31:54112* [**vscode-clangd**](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd) -
113 Enables VS Code to compile Chromium, provide Chromium XRefs to support
114 functions like jumping to definition, and provide smarter autocompletion
115 than **C/C++** extension's IntelliSense, but they also conflicts with each
116 other. To resolve the conflict, add the following to `settings.json`:
117 `"C_Cpp.intelliSenseEngine": "Disabled"`. See [clangd.md](clangd.md) for
118 setup instructions.
119* [**Python**](https://marketplace.visualstudio.com/items?itemName=ms-python.python) -
ljustene262c842017-04-12 08:29:04120 Linting, intellisense, code formatting, refactoring, debugging, snippets.
Peter Wena7551d96b2022-05-30 17:21:22121 * If you want type checking, add: `"python.analysis.typeCheckingMode": "basic",`
122 to your `settings.json` file (you can also find it in the settings UI).
Ming-Ying Chunga7db9dde82022-07-12 06:31:54123* [**Toggle Header/Source**](https://marketplace.visualstudio.com/items?itemName=bbenoist.togglehs) -
James Cook9f7c73d2017-06-20 15:06:19124 Toggles between .cc and .h with `F4`. The C/C++ extension supports this as
125 well through `Alt+O` but sometimes chooses the wrong file when there are
126 multiple files in the workspace that have the same name.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54127* [**Protobuf support**](https://marketplace.visualstudio.com/items?itemName=peterj.proto) -
ljustene262c842017-04-12 08:29:04128 Syntax highlighting for .proto files.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54129* [**Mojom IDL support**](https://marketplace.visualstudio.com/items?itemName=Google.vscode-mojom) -
Kenichi Ishibashib6d2e3b2020-04-22 18:16:07130 Syntax highlighting and a
131 [language server](https://microsoft.github.io/language-server-protocol/)
Kenichi Ishibashi93c7b8e2021-11-05 05:42:23132 for .mojom files.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54133* [**GN**](https://marketplace.visualstudio.com/items?itemName=npclaudiu.vscode-gn) -
134 Syntax highlighting for .gn files.
135* [**Rewrap**](https://marketplace.visualstudio.com/items?itemName=stkb.rewrap) -
ljustene262c842017-04-12 08:29:04136 Wrap lines at 80 characters with `Alt+Q`.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54137* [**Remote**](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) -
Daniel Murphyd9e88fb2020-03-17 19:26:23138 Remotely connect to your workstation through SSH using your laptop. See the
139 [Remote](#Remote) section for more information about how to set this up.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54140* [**GitLens**](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) -
141 Git supercharged. A Powerful, feature rich, and highly customizable git
142 extension.
chaopengba312ce2017-02-12 03:38:25143
ljustene262c842017-04-12 08:29:04144The following extensions might be useful for you as well:
chaopengba312ce2017-02-12 03:38:25145
Ming-Ying Chunga7db9dde82022-07-12 06:31:54146```bash
147$ echo "wmaurer.change-case shd101wyy.markdown-preview-enhanced Gruntfuggly.todo-tree alefragnani.Bookmarks spmeesseman.vscode-taskexplorer streetsidesoftware.code-spell-checker tht13.html-preview-vscode anseki.vscode-color" | xargs -n 1 code --install-extension --force
148```
149
150* **chromium-codesearch** -
Jesse McKennafffd8112020-05-08 19:18:48151 Mac and Linux only: adds ability to open the current line in [Chromium Code
152 Search](https://cs.chromium.org/). All other functionality is deprecated, so
153 currently only of limited usefulness.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54154* [**change-case**](https://marketplace.visualstudio.com/items?itemName=wmaurer.change-case) -
ljustene262c842017-04-12 08:29:04155 Quickly change the case of the current selection or current word.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54156* [**Markdown Preview Enhanced**](https://marketplace.visualstudio.com/items?itemName=shd101wyy.markdown-preview-enhanced) -
157 Preview markdown side-by-side with automatic scroll sync and many other
158 features with `ctrl+k v`. This document was written with this extension!
159* [**Todo Tree**](https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree) -
160 Displays comment tags like TODO/FIXME in a tree view in a dedicated sidebar.
161* [**Bookmarks**](https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks) -
162 Supports easy mark/unmark positions in the codebase and displays them in a
163 dedicated sidebar. Very useful for a large codebase like Chromium.
164* [**Task Explorer**](https://marketplace.visualstudio.com/items?itemName=spmeesseman.vscode-taskexplorer) -
165 Displays supported tasks, e.g. vscode tasks, shell scripts and others,
166 organized into a treeview in sidebar.
167* [**Code Spell Checker**](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) -
168 A basic spell checker that works well with camelCase code. It helps catch
169 common spelling errors.
170* [**HTML Preview**](https://marketplace.visualstudio.com/items?itemName=tht13.html-preview-vscode) -
171 Previews HTML files while editing with `ctrl+k v`.
172* [**Color Picker**](https://marketplace.visualstudio.com/items?itemName=anseki.vscode-color) -
173 Visualizes color codes inline and provides color picker GUI to generates new
174 color codes.
175
chaopengba312ce2017-02-12 03:38:25176
ljustene262c842017-04-12 08:29:04177Also be sure to take a look at the
Jesse McKennafffd8112020-05-08 19:18:48178[VS Code marketplace](https://marketplace.visualstudio.com/VSCode) to check out
179other useful extensions.
chaopengba312ce2017-02-12 03:38:25180
ljustene262c842017-04-12 08:29:04181### Color Scheme
Ming-Ying Chunga7db9dde82022-07-12 06:31:54182
ljustene262c842017-04-12 08:29:04183Press `Ctrl+Shift+P, color, Enter` to pick a color scheme for the editor. There
184are also tons of [color schemes available for download on the
185marketplace](https://marketplace.visualstudio.com/search?target=VSCode&category=Themes&sortBy=Downloads).
chaopengba312ce2017-02-12 03:38:25186
Ming-Ying Chunga7db9dde82022-07-12 06:31:54187### Keyboard Shortcuts
188
189#### CheatSheet
190
191* [Windows](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf)
192* [Mac](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf)
193
194#### Useful Shortcuts
195
ljustene262c842017-04-12 08:29:04196* `Ctrl+P` opens a search box to find and open a file.
197* `F1` or `Ctrl+Shift+P` opens a search box to find a command (e.g. Tasks: Run
Daniel Cheng2d4c2d192022-07-01 01:38:31198 Task). Note: if you want to run one of the [Predefined tasks in
199 tasks.json](#Tasks), it is faster to just use `Ctrl+P` &gt; "task <n>".
ljustene262c842017-04-12 08:29:04200* `Ctrl+K, Ctrl+S` opens the key bindings editor.
201* ``Ctrl+` `` toggles the built-in terminal.
202* `Ctrl+Shift+M` toggles the problems view (linter warnings, compile errors
Quinten Yearsley317532d2021-10-20 17:10:31203 and warnings). You'll switch a lot between terminal and problem view during
ljustene262c842017-04-12 08:29:04204 compilation.
205* `Alt+O` switches between the source/header file.
206* `Ctrl+G` jumps to a line.
207* `F12` jumps to the definition of the symbol at the cursor (also available on
208 right-click context menu).
209* `Shift+F12` or `F1, CodeSearchReferences, Return` shows all references of
210 the symbol at the cursor.
211* `F1, CodeSearchOpen, Return` opens the current file in Code Search.
212* `Ctrl+D` selects the word at the cursor. Pressing it multiple times
213 multi-selects the next occurrences, so typing in one types in all of them,
214 and `Ctrl+U` deselects the last occurrence.
215* `Ctrl+K, Z` enters Zen Mode, a fullscreen editing mode with nothing but the
216 current editor visible.
217* `Ctrl+X` without anything selected cuts the current line. `Ctrl+V` pastes
218 the line.
219
Ming-Ying Chunga7db9dde82022-07-12 06:31:54220*** aside
221Note: See also [Key Bindings for Visual Studio Code
222](https://code.visualstudio.com/docs/getstarted/keybindings).
223***
224
Michael Thiessenf643e29f2020-03-24 20:23:01225### Java/Android Support
Victor Hugo Vianna Silvac37c9b72021-10-28 00:32:32226
227*Before anything*, add these to your settings.json.
228```
229// LightWeight is the language support, the feature we care about. The other
230// modes include build functionality with Maven and Gradle. They try to build
231// on their own and end up showing thousands of errors.
232"java.server.launchMode": "LightWeight",
233// Avoids overwriting the custom .classpath file (c.f. next section).
234"java.configuration.updateBuildConfiguration": "disabled",
235```
236Then install the "Language Support for Java" extension. If you installed it
237before setting the configs above, uninstall, delete the <project> folder (c.f.
238next section) and reinstall. You also don't need any of the remaining extensions
239in "Extension Pack for Java".
Michael Thiessenf643e29f2020-03-24 20:23:01240
241#### Setting up code completion/reference finding/etc.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54242
Mehran Mahmoudib96ca412020-03-25 21:48:14243You'll need to generate a placeholder .classpath file and locate it. In order
244to generate it, right click on any Java source folder in the left panel and
245choose "Add folder to java source path". Its location will depend on whether
246you're doing local or remote development. Local path on linux will look
247something like:
Michael Thiessenf643e29f2020-03-24 20:23:01248
249`~/.vscode/data/User/workspaceStorage/<hash>/redhat.java/jdt_ws/<project>/.classpath`
250
Mehran Mahmoudib96ca412020-03-25 21:48:14251You might find multiple folders when looking for `<project>`. Choose anything except
252`jdt.ls-java-project`. If you only see `jdt.ls-java-project`, try using the
253"Add folder to java source path" option again.
254
Michael Thiessenf643e29f2020-03-24 20:23:01255If doing remote development, the file will be under `~/.vscode-server/` on your
256remote machine.
257
Michael Thiessene057a6c2020-03-25 19:24:01258You'll need to replace all of the contents of that file with the contents of
259`tools/android/eclipse/.classpath` (external) or
260`clank/development/ide/eclipse/.classpath` (generated by gclient runhooks for
261Chrome developers), and then replace some paths as vscode interprets some paths
262differently from eclipse.
Michael Thiessenf643e29f2020-03-24 20:23:01263* Replace: `kind="src" path="` with `kind="src" path="_/`
Michael Thiessene057a6c2020-03-25 19:24:01264 * eg. `<classpathentry kind="src" path="_/android_webview/glue/java/src"/>`
Michael Thiessenf643e29f2020-03-24 20:23:01265* Replace: `kind="lib" path="../src` with `kind="lib" path="_`
Michael Thiessene057a6c2020-03-25 19:24:01266 * eg.
267`<classpathentry kind="lib" path="_/out/Debug/lib.java/base/base_java.jar"/>`
Michael Thiessenf643e29f2020-03-24 20:23:01268* Remove all nested paths (or exclude them from their parents). At time of
269writing:
270 * `third_party/android_protobuf/src/java/src/main/java`
271 * `third_party/junit/src/src/main/java`
272
Henry Jiandabdddf2020-03-26 17:59:39273Also, make sure
274`export ANDROID_HOME=/usr/local/google/home/{your_ldap}/Android/Sdk` is in the
275remote machine's `~/.bashrc`.
276
Michael Thiessenf643e29f2020-03-24 20:23:01277Then restart vscode, open a Java file, and wait for a bit.
278
Michael Thiessene057a6c2020-03-25 19:24:01279Debugging tips:
280* Right clicking on a folder in vscode and clicking "Add folder to java source
281path" will error if there are syntax problems with your classpath. (Don't use
282this actually add new paths to your classpath as it won't work correctly)
283 * If there are no syntax errors, ensure the correct .classpath file is being
284 used by seeing if the folder was actually added to the .classpath file you
285 edited.
286
ljustene262c842017-04-12 08:29:04287## Setup For Chromium
288
289VS Code is configured via JSON files. This paragraph contains JSON configuration
290files that are useful for Chromium development, in particular. See [VS Code
291documentation](https://code.visualstudio.com/docs/customization/overview) for an
292introduction to VS Code customization.
293
294### Workspace Settings
Ming-Ying Chunga7db9dde82022-07-12 06:31:54295
Daniel Cheng2d4c2d192022-07-01 01:38:31296Open the file [//tools/vscode/settings.json](/tools/vscode/settings.json),
Darwin Huang985c38a2018-11-21 19:24:13297and check out the default settings there. Feel free to commit added or removed
298settings to enable better team development, or change settings locally to suit
299personal preference. Remember to replace `<full_path_to_your_home>`! To use
300these settings wholesale, enter the following commands into your terminal while
301at the src directory:
Ming-Ying Chunga7db9dde82022-07-12 06:31:54302```bash
Darwin Huang985c38a2018-11-21 19:24:13303$ mkdir .vscode/
Daniel Cheng2d4c2d192022-07-01 01:38:31304$ cp tools/vscode/settings.json .vscode
ljustene262c842017-04-12 08:29:04305```
306
Jesse McKennafffd8112020-05-08 19:18:48307Note: these settings assume that the workspace folder (the root folder displayed
Bartek Nowierskifa835f8c2021-02-24 00:36:02308in the Explorer tab) is Chromium's `src/` directory. If this is not the case,
309replace any references to ${workspaceFolder} with the path to your `src/`.
Jesse McKennafffd8112020-05-08 19:18:48310
ljustene262c842017-04-12 08:29:04311### Tasks
Ming-Ying Chunga7db9dde82022-07-12 06:31:54312
Dan Harringtonb426cf9b2020-09-10 19:47:08313Next, we'll tell VS Code how to compile our code, run tests, and to read
314warnings and errors from the build output. Open the file
Daniel Cheng2d4c2d192022-07-01 01:38:31315[//tools/vscode/tasks.json](/tools/vscode/tasks.json). This will provide tasks
Dan Harringtonb426cf9b2020-09-10 19:47:08316to do basic things. You might have to adjust the commands to your situation and
317needs. To use these settings wholesale, enter the following command into your
318terminal:
Ming-Ying Chunga7db9dde82022-07-12 06:31:54319```bash
Daniel Cheng2d4c2d192022-07-01 01:38:31320$ cp tools/vscode/tasks.json .vscode
ljustene262c842017-04-12 08:29:04321```
322
Daniel Cheng2d4c2d192022-07-01 01:38:31323Before running most of the tasks, you'll need to set `chrome.outputDir`. You can
324do this by typing `Ctrl+Shift+P` &gt; "Preferences: Open Folder Settings (JSON)"
325and adding something like:
326
327```json
328{
329 "chrome.outputDir": "C:\\src\\chrome\\src\\out\\release"
330
331 // more settings here...
332}
333
334```
335
336Now you can run tasks by using `Ctrl+P` and typing "task " and then a number
337of your choice. If you select one of the build tasks, the build output will
338display in the terminal pane. Jump through build problems quickly using F8 /
339Shift-F8. See [task names](#task-names) for more info on running tasks.
340
341If you have intellisense enabled but do not have include paths set up correctly,
342jumping through problems will also try to navigate through all the include files
343it cannot locate and add a lot of noise. You can fix your include path or simply
344set intellisense to "tag parser" mode by doing the following:
345
3461. Open Preferences (`Ctrl+Shift+P` &gt; "Preferences: Open User Settings").
3472. Type "intellisense engine" in the settings search box.
3483. Select "Tag Parser" as the provider.
349
350Note: on a Chromebook, use 🔍+<8th button in the top row that's not ESC>. In
351most cases, this is the top row button that is the closest to be directly above
352the 8 key.
353
ljustene262c842017-04-12 08:29:04354### Launch Commands
Ming-Ying Chunga7db9dde82022-07-12 06:31:54355
ljustene262c842017-04-12 08:29:04356Launch commands are the equivalent of `F5` in Visual Studio: They launch some
357program or a debugger. Optionally, they can run some task defined in
358`tasks.json`. Launch commands can be run from the debug view (`Ctrl+Shift+D`).
Daniel Cheng2d4c2d192022-07-01 01:38:31359Open the file at [//tools/vscode/launch.json](/tools/vscode/launch.json) and
Jesse McKenna37eceb82020-06-02 00:03:50360adjust the example launch commands to your situation and needs (e.g., the value
361of "type" needs adjustment for Windows). To use these settings wholesale, enter
362the following command into your terminal:
Ming-Ying Chunga7db9dde82022-07-12 06:31:54363
364```bash
Daniel Cheng2d4c2d192022-07-01 01:38:31365$ cp tools/vscode/launch.json .vscode
ljustene262c842017-04-12 08:29:04366```
367
368### Key Bindings
Ming-Ying Chunga7db9dde82022-07-12 06:31:54369
ljustene262c842017-04-12 08:29:04370To edit key bindings, press `Ctrl+K, Ctrl+S`. You'll see the defaults on the
371left and your overrides on the right stored in the file `keybindings.json`. To
372change a key binding, copy the corresponding key binding to the right. It's
373fairly self-explanatory.
374
375You can bind any command to a key, even commands specified by extensions like
376`CodeSearchOpen`. For instance, to bind `CodeSearchOpen` to `F2` to , simply add
377`{ "key": "F2", "command": "cs.open" },`.
378Note that the command title `CodeSearchOpen` won't work. You have to get the
379actual command name from the [package.json
380file](https://github.com/chaopeng/vscode-chromium-codesearch/blob/master/package.json)
381of the extension.
382
383If you are used to other editors, you can also install your favorite keymap.
384For instance, to install eclipse keymaps, install the
385`vscode-eclipse-keybindings` extension. More keymaps can be found
386[in the marketplace](https://marketplace.visualstudio.com/search?target=vscode&category=Keymaps).
387
Darwin Huang985c38a2018-11-21 19:24:13388Some key bindings that are likely to be useful for you are available at
Daniel Cheng2d4c2d192022-07-01 01:38:31389[//tools/vscode/keybindings.json](/tools/vscode/keybindings.json). Please
Darwin Huang985c38a2018-11-21 19:24:13390take a look and adjust them to your situation and needs. To use these settings
391wholesale, enter the following command into your terminal:
Ming-Ying Chunga7db9dde82022-07-12 06:31:54392
393```bash
Daniel Cheng2d4c2d192022-07-01 01:38:31394$ cp tools/vscode/keybindings.json .vscode
ljustene262c842017-04-12 08:29:04395```
396
Daniel Murphyd9e88fb2020-03-17 19:26:23397### Remote
Ming-Ying Chunga7db9dde82022-07-12 06:31:54398
399*** promo
400Googlers: See [go/vscode-remote](http://go/vscode-remote).
401***
402
403VS Code now has a
Daniel Murphyd9e88fb2020-03-17 19:26:23404[Remote](https://code.visualstudio.com/docs/remote/remote-overview) framework
Ming-Ying Chunga7db9dde82022-07-12 06:31:54405that allows you to use VS Code on your laptop while your code is hosted
Daniel Murphyd9e88fb2020-03-17 19:26:23406elsewhere. This really shines when used in conjunction with the vscode-clangd plugin,
407which allows clangd to run remotely as well.
408
409To get this to run, install the Remote pack extension, and then make sure your
410ssh config file has your remote connection:
411
412`~/.ssh/config`:
413```
414Host my-connection
415 HostName my-remote-host.corp.company.com
416```
417
Ming-Ying Chunga7db9dde82022-07-12 06:31:54418VS Code will then list this connection in the 'Remote Explorer' section on the
419left. To launch VS Code with this connection, click on the '+window' icon next
Daniel Murphyd9e88fb2020-03-17 19:26:23420to the listed hostname. It has you choose a folder - use the 'src' folder root.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54421This will open a new VS Code window in 'Remote' mode. ***Now you can install
Daniel Murphyd9e88fb2020-03-17 19:26:23422extensions specifically for your remote connection, like vscode-clangd, etc.***
423
Peter Wen3ba91202020-06-17 15:56:54424#### Chromebooks
425
426For Googlers, [here](http://go/vscode/remote_development_via_web) are
427Google-specific instructions for setting up remote development on chromebooks
428without using Crostini.
429
Daniel Murphyd9e88fb2020-03-17 19:26:23430#### Windows & SSH
Yuwei Huang1c4f50c2021-08-06 22:41:56431
Ming-Ying Chunga7db9dde82022-07-12 06:31:54432VS Code remote tools requires 'sshd' which isn't installed on Windows by
433default.
Yuwei Huang1c4f50c2021-08-06 22:41:56434
Ming-Ying Chunga7db9dde82022-07-12 06:31:54435For Googlers, sshd should already be installed on your workstation, and VS Code
Yuwei Huang1c4f50c2021-08-06 22:41:56436should work remotely if you followed the setup instructions at
437[go/building-chrome-win](http://go/building-chrome-win). If you are still having
438problems, please refer to
439[go/vscode-remote#windows](http://go/vscode-remote#windows).
440
441Non-Googlers may follow may follow Microsoft's instructions for
442[installing the OpenSSH server](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse).
Ming-Ying Chunga7db9dde82022-07-12 06:31:54443VS Code should work remotely after following this step.
Daniel Murphyd9e88fb2020-03-17 19:26:23444
Dan Harringtonb06ce2f2019-04-09 15:35:29445### Snippets
Yuki Osaki0a255c52021-12-20 05:35:26446
Dan Harringtonb06ce2f2019-04-09 15:35:29447There are some useful snippets provided in
Daniel Cheng2d4c2d192022-07-01 01:38:31448[//tools/vscode/cpp.json](/tools/vscode/cpp.json).
Dan Harringtonb06ce2f2019-04-09 15:35:29449
Mounir Lamouri3b9e31d2019-07-30 20:14:41450You can either install them in your user profile (path may vary depending on the
451platform):
Ming-Ying Chunga7db9dde82022-07-12 06:31:54452```bash
Daniel Cheng2d4c2d192022-07-01 01:38:31453$ mkdir -p ~/.config/Code/User/snippets
454$ cp tools/vscode/cpp.json ~/.config/Code/User/snippets
Mounir Lamouri3b9e31d2019-07-30 20:14:41455```
456
Yuki Osaki0a255c52021-12-20 05:35:26457Or install them as project snippets:
Ming-Ying Chunga7db9dde82022-07-12 06:31:54458```bash
Daniel Cheng2d4c2d192022-07-01 01:38:31459$ cp tools/vscode/cpp.json .vscode/cpp.code-snippets
Mounir Lamouri3b9e31d2019-07-30 20:14:41460```
461
ljustene262c842017-04-12 08:29:04462### Tips
463
464#### The `out` folder
Ming-Ying Chunga7db9dde82022-07-12 06:31:54465
ljustene262c842017-04-12 08:29:04466Automatically generated code is put into a subfolder of out/, which means that
467these files are ignored by VS Code (see files.exclude above) and cannot be
Christian Dullweberd67c9b32018-04-03 08:30:42468opened e.g. from quick-open (`Ctrl+P`).
469As of version 1.21, VS Code does not support negated glob commands, but you can
470define a set of exclude pattern to include only out/Debug/gen:
Christian Dullweberbabb96e12018-05-28 14:00:14471```
Christian Dullweberd67c9b32018-04-03 08:30:42472"files.exclude": {
473 // Ignore build output folders. Except out/Debug/gen/
474 "out/[^D]*/": true,
475 "out/Debug/[^g]*": true,
476 "out/Debug/g[^e]*": true,
477 "out_*/**": true,
478},
Christian Dullweberbabb96e12018-05-28 14:00:14479```
Christian Dullweberd67c9b32018-04-03 08:30:42480
481Once it does, you can use
ljustene262c842017-04-12 08:29:04482```
483"!out/Debug/gen/**": true
484```
485in files.exclude instead of the symlink.
486
487#### Using VS Code as git editor
Ming-Ying Chunga7db9dde82022-07-12 06:31:54488
ljustene262c842017-04-12 08:29:04489Add `[core] editor = "code --wait"` to your `~/.gitconfig` file in order to use
490VS Code as editor for git commit messages etc. Note that the editor starts up
491significantly slower than nano or vim. To use VS Code as merge tool, add
492`[merge] tool = code`.
493
494#### Task Names
Ming-Ying Chunga7db9dde82022-07-12 06:31:54495
ljustene262c842017-04-12 08:29:04496Note that we named the tasks `1-build_chrome_debug`, `2-build_chrome_release`
497etc. This allows you to quickly execute tasks by pressing their number:
498Press `Ctrl+P` and enter `task <n>`, where `<n>` is the number of the task. You
499can also create a keyboard shortcut for running a task. `File > Preferences >
500Keyboard Shortcuts` and add `{ "key": "ctrl+r", "command":
501"workbench.action.tasks.runTask", "when": "!inDebugMode" }`. Then it's
502sufficient to press `Ctrl+R` and enter `<n>`.
503
504#### Working on Laptop
Ming-Ying Chunga7db9dde82022-07-12 06:31:54505
Bartek Nowierskifa835f8c2021-02-24 00:36:02506You might want to disable git status autorefresh to save battery.
chaopengca285112017-03-02 15:39:04507
508```
chaopeng5c66dfe2017-03-22 13:51:45509"git.autorefresh": false,
chaopengca285112017-03-02 15:39:04510```
511
Tommy Nyquistdc2ceaa42021-03-15 20:29:04512#### Editing in multiple Git repositories
Ming-Ying Chunga7db9dde82022-07-12 06:31:54513
Tommy Nyquistdc2ceaa42021-03-15 20:29:04514If 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.
515
516To 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.
517
518To 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):
519
520```
521{
522 "folders": [
523 {
524 "path": "chromium/src/third_party/perfetto"
525 },
526 {
527 "path": "chromium/src"
528 }
529 ]
530}
531```
532
Jianpeng Chaob4048b82018-08-28 23:40:01533### Unable to open $File resource is not available when debugging Chromium on Linux
Ming-Ying Chunga7db9dde82022-07-12 06:31:54534
Jianpeng Chaob4048b82018-08-28 23:40:01535Chromium [recently changed](https://docs.google.com/document/d/1OX4jY_bOCeNK7PNjVRuBQE9s6BQKS8XRNWGK8FEyh-E/edit?usp=sharing)
536the file path to be relative to the output dir. Check
537`gn args out/$dir --list` if `strip_absolute_paths_from_debug_symbols` is true (which is the default),
538set `cwd` to the output dir. otherwise, set `cwd` to `${workspaceRoot}`.
539
chaopengba312ce2017-02-12 03:38:25540### More
Ming-Ying Chunga7db9dde82022-07-12 06:31:54541
ljustene262c842017-04-12 08:29:04542More tips and tricks can be found
sangwoo.ko5fe74c732017-09-01 14:44:56543[here](https://github.com/Microsoft/vscode-tips-and-tricks/blob/master/README.md).