blob: 72f4b34a29c986f71a3a2af844f97e156182d30f [file] [log] [blame] [view]
ljustene262c8412017-04-12 08:29:041# Visual Studio Code Dev
2
Ming-Ying Chunga7db9dde82022-07-12 06:31:543**Get started [here](#setup)**.
4
Tiago Vignatti3e5b18bc2023-03-30 13:13:465[Visual Studio Code (VS Code)](https://code.visualstudio.com) is a free, open
6source, lightweight and powerful code editor for Windows, macOS and Linux, based
7on [Electron](https://www.electronjs.org/)/Chromium. It has built-in support for
8JavaScript, TypeScript and Node.js and a rich extension ecosystem that adds
9intellisense, debugging, syntax highlighting etc. For many languages like C++,
10Python, Go, Java, it works without too much setup.
ljustene262c8412017-04-12 08:29:0411
Carlos Knippschild58445cb2025-06-09 18:27:3112It is NOT a full-fledged IDE like Visual Studio. The two are completely separate
13products. The only commonality with Visual Studio is that both are from
14Microsoft.
ljustene262c8412017-04-12 08:29:0415
16Here's what works well:
17
Carlos Knippschild58445cb2025-06-09 18:27:3118* **Editing code** works well especially when you get used to the
19 [keyboard shortcuts](#Keyboard-Shortcuts). VS Code is very responsive and
20 can handle even big code bases like Chromium.
Ming-Ying Chunga7db9dde82022-07-12 06:31:5421* **Git integration** is a blast. Built-in side-by-side view, local commit and
ljustene262c8412017-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
Carlos Knippschild58445cb2025-06-09 18:27:3127 well, even though startup times can be fairly high (~40 seconds with gdb on
28 Linux, much lower on Windows). You can step through code, inspect variables,
29 view call stacks for multiple threads etc.
30 * For more information on debugging Python code, see
31 [here](vscode_python.md).
Ming-Ying Chunga7db9dde82022-07-12 06:31:5432* **Command Palette** makes opening files and searching solution really easy.
Carlos Knippschild58445cb2025-06-09 18:27:3133* **Building** works well. Build tools are easy to integrate. Warnings and
34 errors are displayed on a separate page and you can click to jump to the
ljustene262c8412017-04-12 08:29:0435 corresponding line of code.
Ming-Ying Chunga7db9dde82022-07-12 06:31:5436* **VS Code Remote**, which allows you to edit remotely-hosted code, and even
37 run computationally expensive plugins like vscode-clangd on the remote
38 server. Great for working from home. See the [Remote section](#Remote) for
39 more details.
chaopengba312ce2017-02-12 03:38:2540
chaopengca285112017-03-02 15:39:0441[TOC]
42
ljustene262c8412017-04-12 08:29:0443## Updating This Page
chaopengba312ce2017-02-12 03:38:2544
ljustene262c8412017-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
Carlos Knippschild58445cb2025-06-09 18:27:3147make changes, read the [documentation guidelines](documentation_guidelines.md)
48and [submit a change list](contributing.md).
chaopengba312ce2017-02-12 03:38:2549
Tiago Vignatti3e5b18bc2023-03-30 13:13:4650All file paths and commands have been tested on Linux and macOS. Windows might
51require a slightly different setup. Please update this page accordingly.
chaopengba312ce2017-02-12 03:38:2552
ljustene262c8412017-04-12 08:29:0453## Setup
chaopengba312ce2017-02-12 03:38:2554
ljustene262c8412017-04-12 08:29:0455### Installation
chaopengba312ce2017-02-12 03:38:2556
Ming-Ying Chunga7db9dde82022-07-12 06:31:5457*** promo
Ming-Ying Chung8dadf3f32024-03-12 18:47:2758Googlers: See [go/vscode/install](http://go/vscode/install) instead.
Ming-Ying Chunga7db9dde82022-07-12 06:31:5459***
60
Ming-Ying Chung8dadf3f32024-03-12 18:47:2761Follow the steps on [Setting up Visual Studio Code][setup] to install a proper
62version for you development platform.
63
64[setup]: https://code.visualstudio.com/docs/setup/setup-overview
Ming-Ying Chunga7db9dde82022-07-12 06:31:5465
66### Usage
67
Ming-Ying Chung8dadf3f32024-03-12 18:47:2768To run it on Linux or on macOS:
69
70```bash
71cd /path/to/chromium/src
72code .
73```
chaopengba312ce2017-02-12 03:38:2574
Daniel Cheng2d4c2d192022-07-01 01:38:3175If you installed Code Insiders, the binary name is `code-insiders` instead.
76
Ming-Ying Chung8dadf3f32024-03-12 18:47:2777Note that VS Code does not require project or solution files. However, it does
78store workspace settings in a `.vscode` folder in your base directory (i.e. your
79project root folder). See the [Chromium Workspace Settings](#setup-for-chromium)
80section for details.
Daniel Cheng2d4c2d192022-07-01 01:38:3181
ljustene262c8412017-04-12 08:29:0482### Useful Extensions
chaopengba312ce2017-02-12 03:38:2583
ljustene262c8412017-04-12 08:29:0484Up to now, you have a basic version of VS Code without much language support.
Ming-Ying Chung8dadf3f32024-03-12 18:47:2785Next, we will install some useful extensions.
86
87#### Recommended Extensions
chaopengba312ce2017-02-12 03:38:2588
Ming-Ying Chunga7db9dde82022-07-12 06:31:5489You will most likely use the following extensions every day:
90
Ming-Ying Chung8dadf3f32024-03-12 18:47:2791There are 2 ways to install them:
Ming-Ying Chunga7db9dde82022-07-12 06:31:5492
Ming-Ying Chung8dadf3f32024-03-12 18:47:2793* Follow the instructions from
94 [Install Recommended Extensions](#install-recommended-extensions).
95* Manual installation. Jump to the extensions window (`Ctrl+Shift+X`, or
96 `Cmd+Shift+X` in macOS) and search the names of the following extensions.
97
98*** aside
99Note: All the extension settings mentioned below are already set in
100`tools/vscode/settings.json`. You don't have do anything if you have followed
101[the instructions](#setup-for-chromium) to copy that file into your workspace.
102***
103
104* [**ChromiumIDE**](https://marketplace.visualstudio.com/items?itemName=Google.cros-ide) -
105 The critical extension to make Chromium/ChromiumOS development easier and
106 faster by anchoring core tools in one place.
107* [**Chromium Context**](https://marketplace.visualstudio.com/items?itemName=solomonkinard.chromium-context) -
108 Provides Chromium-specific context, e.g. code owners, release version,
109 author blame list, in a single tab for an opened file.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54110* [**C/C++**](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) -
Jesse McKennafffd8112020-05-08 19:18:48111 Code formatting, debugging, Intellisense. Enables the use of clang-format
112 (via the `C_Cpp.clang_format_path` setting) and format-on-save (via the
113 `editor.formatOnSave` setting).
Ming-Ying Chunga7db9dde82022-07-12 06:31:54114* [**vscode-clangd**](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd) -
115 Enables VS Code to compile Chromium, provide Chromium XRefs to support
Ming-Ying Chung8dadf3f32024-03-12 18:47:27116 functions like jumping to definition, and provide a clangd
117 [language server][lang-server] powering smarter autocompletion than
Carlos Knippschild58445cb2025-06-09 18:27:31118 **C/C++** extension's IntelliSense, but they also conflicts with each other.
119 To resolve the conflict, add the following to `settings.json`:
120 `"C_Cpp.intelliSenseEngine": "disabled"`. See [clangd.md](clangd.md) for
Ming-Ying Chunga7db9dde82022-07-12 06:31:54121 setup instructions.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54122* [**Toggle Header/Source**](https://marketplace.visualstudio.com/items?itemName=bbenoist.togglehs) -
James Cook9f7c73d2017-06-20 15:06:19123 Toggles between .cc and .h with `F4`. The C/C++ extension supports this as
124 well through `Alt+O` but sometimes chooses the wrong file when there are
125 multiple files in the workspace that have the same name.
Ming-Ying Chung8dadf3f32024-03-12 18:47:27126* [**vscode-proto3**](https://marketplace.visualstudio.com/items?itemName=zxh404.vscode-proto3) -
ljustene262c8412017-04-12 08:29:04127 Syntax highlighting for .proto files.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54128* [**Mojom IDL support**](https://marketplace.visualstudio.com/items?itemName=Google.vscode-mojom) -
Ming-Ying Chung8dadf3f32024-03-12 18:47:27129 Syntax highlighting and a [language server][lang-server] for .mojom files.
Shuhei Takahashi077dbd47c2025-07-08 01:08:01130* [**GN**](https://marketplace.visualstudio.com/items?itemName=google.gn) -
131 [Language server][lang-server] for the GN build system.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54132* [**Rewrap**](https://marketplace.visualstudio.com/items?itemName=stkb.rewrap) -
ljustene262c8412017-04-12 08:29:04133 Wrap lines at 80 characters with `Alt+Q`.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54134* [**Remote**](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) -
Daniel Murphyd9e88fbb2020-03-17 19:26:23135 Remotely connect to your workstation through SSH using your laptop. See the
136 [Remote](#Remote) section for more information about how to set this up.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54137* [**GitLens**](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) -
138 Git supercharged. A Powerful, feature rich, and highly customizable git
139 extension.
Ming-Ying Chung8dadf3f32024-03-12 18:47:27140* [**Python**](https://marketplace.visualstudio.com/items?itemName=ms-python.python) -
141 Linting, intellisense, code formatting, refactoring, debugging, snippets.
Carlos Knippschild58445cb2025-06-09 18:27:31142 * If you want type checking, add: `"python.analysis.typeCheckingMode":
143 "basic",` to your `settings.json` file (you can also find it in the
144 settings UI).
chaopengba312ce2017-02-12 03:38:25145
Ming-Ying Chung8dadf3f32024-03-12 18:47:27146[lang-server]: https://microsoft.github.io/language-server-protocol/
147
148#### Optional Extensions
149
150The following extensions are not included in
151[//tools/vscode/settings.json](/tools/vscode/settings.json), but they might be
152useful for you as well:
chaopengba312ce2017-02-12 03:38:25153
Ming-Ying Chunga7db9dde82022-07-12 06:31:54154```bash
Carlos Knippschild32f9beb62025-06-06 16:56:35155$ echo "ryu1kn.annotator wmaurer.change-case" \
156 "shd101wyy.markdown-preview-enhanced" \
157 "Gruntfuggly.todo-tree" \
158 "alefragnani.Bookmarks" \
159 "spmeesseman.vscode-taskexplorer" \
160 "streetsidesoftware.code-spell-checker" \
161 "george-alisson.html-preview-vscode anseki.vscode-color" \
162 | xargs -n 1 code --force --install-extension
Ming-Ying Chunga7db9dde82022-07-12 06:31:54163```
164
Ho Cheunga645ddc2024-07-02 05:02:09165* [**Annotator**](https://marketplace.visualstudio.com/items?itemName=ryu1kn.annotator) -
Carlos Knippschild58445cb2025-06-09 18:27:31166 Display git blame info along with your code. Can open the diff of a
167 particular commit from there.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54168* [**change-case**](https://marketplace.visualstudio.com/items?itemName=wmaurer.change-case) -
ljustene262c8412017-04-12 08:29:04169 Quickly change the case of the current selection or current word.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54170* [**Markdown Preview Enhanced**](https://marketplace.visualstudio.com/items?itemName=shd101wyy.markdown-preview-enhanced) -
171 Preview markdown side-by-side with automatic scroll sync and many other
Tiago Vignatti3e5b18bc2023-03-30 13:13:46172 features with `Ctrl+k v`. This document was written with this extension!
Ming-Ying Chunga7db9dde82022-07-12 06:31:54173* [**Todo Tree**](https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree) -
174 Displays comment tags like TODO/FIXME in a tree view in a dedicated sidebar.
175* [**Bookmarks**](https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks) -
176 Supports easy mark/unmark positions in the codebase and displays them in a
177 dedicated sidebar. Very useful for a large codebase like Chromium.
178* [**Task Explorer**](https://marketplace.visualstudio.com/items?itemName=spmeesseman.vscode-taskexplorer) -
179 Displays supported tasks, e.g. vscode tasks, shell scripts and others,
180 organized into a treeview in sidebar.
181* [**Code Spell Checker**](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) -
182 A basic spell checker that works well with camelCase code. It helps catch
183 common spelling errors.
Ho Cheungc4cd9e52023-04-05 01:32:21184* [**HTML Preview**](https://marketplace.visualstudio.com/items?itemName=george-alisson.html-preview-vscode) -
Tiago Vignatti3e5b18bc2023-03-30 13:13:46185 Previews HTML files while editing with `Ctrl+k v`.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54186* [**Color Picker**](https://marketplace.visualstudio.com/items?itemName=anseki.vscode-color) -
187 Visualizes color codes inline and provides color picker GUI to generates new
188 color codes.
Peter Wenba247f542024-03-15 19:37:47189* [**Bazel**](https://marketplace.visualstudio.com/items?itemName=BazelBuild.vscode-bazel) -
Carlos Knippschild58445cb2025-06-09 18:27:31190 This is very useful for editing `*.star` starlark files. If you want "Go to
191 definition" to work in our `infra/config` directory, see the
Peter Wenba247f542024-03-15 19:37:47192 [//tools/vscode/bazel_lsp/README.md][lsp_patches_readme]
Justin Lulejian2e35ceb2025-09-08 17:03:15193* [**Gerrit**](https://marketplace.visualstudio.com/items?itemName=SanderRonde.vscode--gerrit) -
194 Interact with [Chromium's Gerrit instance](https://chromium-review.googlesource.com/) for code review. Note: Chromium's Gerrit cannot provide the Stream Events permission.
Peter Wenba247f542024-03-15 19:37:47195
196[lsp_patches_readme]: ../tools/vscode/bazel_lsp/README.md
Ming-Ying Chunga7db9dde82022-07-12 06:31:54197
ljustene262c8412017-04-12 08:29:04198Also be sure to take a look at the
Jesse McKennafffd8112020-05-08 19:18:48199[VS Code marketplace](https://marketplace.visualstudio.com/VSCode) to check out
200other useful extensions.
chaopengba312ce2017-02-12 03:38:25201
ljustene262c8412017-04-12 08:29:04202### Color Scheme
Ming-Ying Chunga7db9dde82022-07-12 06:31:54203
Carlos Knippschild58445cb2025-06-09 18:27:31204Press `Ctrl+Shift+P` (`Cmd+Shift+P` in macOS), type `color`, `Enter` to pick a
Carlos Knippschild32f9beb62025-06-06 16:56:35205color scheme for the editor. There are also tons of [color schemes available for
Tiago Vignatti3e5b18bc2023-03-30 13:13:46206download on the
Carlos Knippschild32f9beb62025-06-06 16:56:35207[marketplace](https://marketplace.visualstudio.com/search?target=VSCode&category=Themes&sortBy=Downloads).
chaopengba312ce2017-02-12 03:38:25208
Ming-Ying Chunga7db9dde82022-07-12 06:31:54209### Keyboard Shortcuts
210
211#### CheatSheet
212
213* [Windows](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf)
Tiago Vignatti3e5b18bc2023-03-30 13:13:46214* [macOS](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf)
Ming-Ying Chunga7db9dde82022-07-12 06:31:54215
Tiago Vignatti3e5b18bc2023-03-30 13:13:46216#### Useful Shortcuts (Linux)
Ming-Ying Chunga7db9dde82022-07-12 06:31:54217
ljustene262c8412017-04-12 08:29:04218* `Ctrl+P` opens a search box to find and open a file.
219* `F1` or `Ctrl+Shift+P` opens a search box to find a command (e.g. Tasks: Run
Carlos Knippschild58445cb2025-06-09 18:27:31220 Task). Note: if you want to run one of the
221 [Predefined tasks in tasks.json](#Tasks), it is faster to just use `Ctrl+P`
222 &gt; "task <n>".
ljustene262c8412017-04-12 08:29:04223* `Ctrl+K, Ctrl+S` opens the key bindings editor.
224* ``Ctrl+` `` toggles the built-in terminal.
225* `Ctrl+Shift+M` toggles the problems view (linter warnings, compile errors
Quinten Yearsley317532d2021-10-20 17:10:31226 and warnings). You'll switch a lot between terminal and problem view during
ljustene262c8412017-04-12 08:29:04227 compilation.
228* `Alt+O` switches between the source/header file.
229* `Ctrl+G` jumps to a line.
230* `F12` jumps to the definition of the symbol at the cursor (also available on
231 right-click context menu).
232* `Shift+F12` or `F1, CodeSearchReferences, Return` shows all references of
233 the symbol at the cursor.
234* `F1, CodeSearchOpen, Return` opens the current file in Code Search.
235* `Ctrl+D` selects the word at the cursor. Pressing it multiple times
236 multi-selects the next occurrences, so typing in one types in all of them,
237 and `Ctrl+U` deselects the last occurrence.
238* `Ctrl+K, Z` enters Zen Mode, a fullscreen editing mode with nothing but the
239 current editor visible.
240* `Ctrl+X` without anything selected cuts the current line. `Ctrl+V` pastes
241 the line.
242
Ming-Ying Chunga7db9dde82022-07-12 06:31:54243*** aside
Carlos Knippschild58445cb2025-06-09 18:27:31244Note: See also
245[Key Bindings for Visual Studio Code](https://code.visualstudio.com/docs/getstarted/keybindings).
Ming-Ying Chunga7db9dde82022-07-12 06:31:54246***
247
Michael Thiessenf643e29f2020-03-24 20:23:01248### Java/Android Support
Victor Hugo Vianna Silvac37c9b72021-10-28 00:32:32249
Shuhei Takahashic2a265322025-01-10 02:20:16250There are two extensions you can use to get Java/Android support in VSCode:
251
Carlos Knippschild58445cb2025-06-09 18:27:31252* a.
253 [ChromiumIDE](https://marketplace.visualstudio.com/items?itemName=Google.cros-ide)
254* b.
255 [Language Support for Javaâ„ĸ by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java)
Shuhei Takahashic2a265322025-01-10 02:20:16256
257ChromiumIDE is much faster and more stable than the other extension, mainly
258because it does not rely on background indexing and persistent cache. It works
259without manually running scripts from the command line as the extension knows
260how to extract build configurations from GN. On the other hand, its features are
261limited compared to the other extension (e.g. debugger is not supported yet).
262
263Language Support for Javaâ„ĸ by Red Hat has more features as it is based on the
264Eclipse JDT Language Server. But it is known to be very slow (it takes tens of
265minutes to index the whole project in a single thread before serving requests
266from VSCode) and less stable (it often gets confused when you sync the source
267checkout, forcing you to clear the cache and wait indexing again).
268
269#### a. ChromiumIDE
270
271Install the latest **pre-release** version of
272[ChromiumIDE](https://marketplace.visualstudio.com/items?itemName=Google.cros-ide)
Shuhei Takahashid12f0d22025-01-20 02:22:20273from the VSCode marketplace. Make sure the extension version is **0.35.32** or
Shuhei Takahashic2a265322025-01-10 02:20:16274later.
275
Shuhei Takahashid12f0d22025-01-20 02:22:20276Then just open a VSCode workspace containing Chromium source tree (opening
Shuhei Takahashic2a265322025-01-10 02:20:16277subdirectories is fine) and open a Java file. If you haven't, you're prompted to
278select the default build output directory (e.g. `out/Default`).
279
280#### b. Language Support for Javaâ„ĸ by Red Hat
Michael Thiessenf643e29f2020-03-24 20:23:01281
Carlos Knippschild58445cb2025-06-09 18:27:312821. **Add the following to your VS Code workspace `settings.json`:**
Ho Cheung7c53eaf2024-05-31 00:31:26283
Carlos Knippschild58445cb2025-06-09 18:27:31284 ```
285 "java.import.gradle.enabled": false,
286 "java.import.maven.enabled": false
287 ```
Ho Cheung7c53eaf2024-05-31 00:31:26288
Carlos Knippschild58445cb2025-06-09 18:27:31289 This will prevent the language server from attempting to build *all* Gradle
290 and Maven projects that can be found anywhere in the Chromium source tree,
291 which typically results in hilarity.
Ho Cheung7c53eaf2024-05-31 00:31:26292
Carlos Knippschild58445cb2025-06-09 18:27:31293 ```
294 "java.jdt.ls.java.home": "<< ABSOLUTE PATH TO YOUR WORKING COPY OF CHROMIUM >>/src/third_party/jdk/current"
295 ```
Ho Cheung7c53eaf2024-05-31 00:31:26296
Carlos Knippschild58445cb2025-06-09 18:27:31297 This one is optional but reduces the likelihood of problems by making sure
298 the language server uses the same JDK as the Chromium build system (as
299 opposed to some random JDK from your host system).
Ho Cheung7c53eaf2024-05-31 00:31:26300
Carlos Knippschild58445cb2025-06-09 18:27:31301 Also increase the resources available to the Java Language Server, for
302 example:
Aldo Culquicondor329da1832024-11-07 19:11:08303
Carlos Knippschild58445cb2025-06-09 18:27:31304 ```
305 "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx64G -Xms100m -Xlog:disable"
306 ```
Aldo Culquicondor329da1832024-11-07 19:11:08307
Carlos Knippschild58445cb2025-06-09 18:27:313082. **Install the
309 [*Language Support for Javaâ„ĸ by Red Hat*](https://marketplace.visualstudio.com/items?itemName=redhat.java)
310 extension.** You do not need any other extension.
311
3123. **Build your code** in the usual way (i.e. using gn and ninja commands).
313 This will produce build config files that are necessary for the next step.
314 It will also make autogenerated code visible to the language server.
315
3164. **Generate the Eclipse JDT project** by running
317 `build/android/generate_vscode_project.py` from the `src` directory. For
318 example, if your build output directory is `out/Debug-x86` and your build
319 target is `//chrome/android:chrome_java`, run:
320 `build/android/generate_vscode_project.py --output-dir out/Debug-x86
321 --build-config gen/chrome/android/chrome_java.build_config.json`. This will
322 create `.project` and `.classpath` in the `src` directory.
323
3245. **Reload** your VS Code window to let it start importing the generated
325 project.
326
3276. **Open a Java source file then wait a couple of minutes** for the language
328 server to build the project.
329
3307. **Done!** You should now have full Java language support for any `.java`
331 file that is included in the build.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54332
Shuhei Takahashic2a265322025-01-10 02:20:16333##### Known issues
Michael Thiessenf643e29f2020-03-24 20:23:01334
Carlos Knippschild58445cb2025-06-09 18:27:31335* Errors related to `GEN_JNI` are caused by the language server (rightfully)
336 getting confused about multiple definitions of the
337 [autogenerated](/third_party/jni_zero/README.md) `GEN_JNI` class. This is a
338 known quirk of the JNI generator.
Michael Thiessene057a6c2020-03-25 19:24:01339
Shuhei Takahashic2a265322025-01-10 02:20:16340##### Troubleshooting
Shuhei Takahashi8b053392024-06-14 01:50:13341
Carlos Knippschild58445cb2025-06-09 18:27:31342* If you have used the previous instructions to use
343 `generate_vscode_classpath.py` or you think something went wrong, try
344 clearing the internal state of the language server by executing `Java: Clean
345 Java Language Server Workspace` from the command palette. This will force
346 the language server to rebuild its internal workspace by importing the
347 generated Eclipse JDT project.
Shuhei Takahashi8b053392024-06-14 01:50:13348
Etienne Dechamps2fba5252023-06-15 18:39:45349#### Automatic formatting
350
351Java code in Chromium is formatted using [clang-format](/docs/clang_format.md).
352To get VS Code to use clang-format to format Java files, install the
353[*Clang-Format* extension](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format)
354and set it as the default formatter for Java in your workspace `settings.json`:
355
356```json
357"[java]": {
358 "editor.defaultFormatter": "xaver.clang-format"
359}
360```
361
362To avoid potential formatting differences due to clang-format version skew, it
Carlos Knippschild58445cb2025-06-09 18:27:31363makes sense to configure the extension to run clang-format in the same way `git
364cl format` would. You can do this by adding the following to your workspace
365`settings.json`:
Etienne Dechamps2fba5252023-06-15 18:39:45366
367```json
368"clang-format.executable": "<< PATH TO YOUR CHROMIUM WORKING COPY >>/src/buildtools/linux64/clang-format"
369```
370
ljustene262c8412017-04-12 08:29:04371## Setup For Chromium
372
Carlos Knippschild58445cb2025-06-09 18:27:31373VS Code is configured via JSON files. This section describes how to configure it
374for a better Chromium development experience.
ljustene262c8412017-04-12 08:29:04375
Ming-Ying Chung8dadf3f32024-03-12 18:47:27376*** aside
Carlos Knippschild58445cb2025-06-09 18:27:31377Note: See
378[VS Code documentation](https://code.visualstudio.com/docs/customization/overview)
379for a more general introduction to VS Code customization.
Ming-Ying Chung8dadf3f32024-03-12 18:47:27380***
381
382The Chromium repository comes with some basic configuration. Run the following
383commands to initialize VS Code for your Chromium checkout:
384
385```bash
386cd /path/to/chromium/src
387mkdir .vscode
388cp tools/vscode/*.json .vscode/
389cp tools/vscode/cpp.code-snippets .vscode/
390```
391
392Once you have done, proceed to the next sections to install recommended
393extensions and perform customization.
394
395### Install Recommended Extensions
396
397As described in the [Useful Extensions](#useful-extensions) sections, there are
398essential extensions to help Chromium development. Follow the steps below:
399
Carlos Knippschild58445cb2025-06-09 18:27:314001. In VS Code's Command Palette (`Ctrl+Shift+P`, or `Cmd+Shift+P` in macOS),
401 type `Show Recommended Extensions`, and press `Enter`.
4022. In the WORKSPACE RECOMMENDATIONS section of the EXTENSIONS sidebar, click
403 the `Install Workspace Recommended Extensions` (shown as a cloud icon).
Ming-Ying Chung8dadf3f32024-03-12 18:47:27404
405Now you are all set.
406
407### Customize Workspace Settings
Ming-Ying Chunga7db9dde82022-07-12 06:31:54408
Carlos Knippschild58445cb2025-06-09 18:27:31409Open the file [//tools/vscode/settings.json](/tools/vscode/settings.json), and
410check out the default settings there. Feel free to commit added or removed
Ming-Ying Chung8dadf3f32024-03-12 18:47:27411settings to enable better team development, or change settings locally in
412`.vscode/settings.json` to suit personal preference.
Raphael Kubo da Costae6e63d32022-09-14 18:17:18413
Ming-Ying Chung8dadf3f32024-03-12 18:47:27414*** aside
Carlos Knippschild58445cb2025-06-09 18:27:31415Note: these settings assume that the workspace folder (the root folder
416displayed in the Explorer tab) is Chromium's `src/` directory. If this is not
417the case, replace any references to `${workspaceFolder}` with the path to your
418`src/`.
Ming-Ying Chung8dadf3f32024-03-12 18:47:27419***
Jesse McKennafffd8112020-05-08 19:18:48420
ljustene262c8412017-04-12 08:29:04421### Tasks
Ming-Ying Chunga7db9dde82022-07-12 06:31:54422
Dan Harringtonb426cf9b2020-09-10 19:47:08423Next, we'll tell VS Code how to compile our code, run tests, and to read
Ming-Ying Chung8dadf3f32024-03-12 18:47:27424warnings and errors from the build output.
ljustene262c8412017-04-12 08:29:04425
Ming-Ying Chung8dadf3f32024-03-12 18:47:27426Open the file `.vscode/tasks.json`. This will provide tasks to do basic things.
427You might have to adjust the commands to your situation and needs. For example,
428before running most of the tasks, you'll need to set the `chromeOutputDir` value
429in that file.
Daniel Cheng2d4c2d192022-07-01 01:38:31430
Tiago Vignatti3e5b18bc2023-03-30 13:13:46431Now you can run tasks by using `Ctrl+P` (`Cmd+Shift+P` in macOS) and typing
432"task " and then a number of your choice. If you select one of the build tasks,
433the build output will display in the terminal pane. Jump through build problems
Ming-Ying Chung8dadf3f32024-03-12 18:47:27434quickly using `F8` / `Shift-F8`. See [task names](#task-names) for more info on
Tiago Vignatti3e5b18bc2023-03-30 13:13:46435running tasks.
Daniel Cheng2d4c2d192022-07-01 01:38:31436
437If you have intellisense enabled but do not have include paths set up correctly,
438jumping through problems will also try to navigate through all the include files
439it cannot locate and add a lot of noise. You can fix your include path or simply
440set intellisense to "tag parser" mode by doing the following:
441
Carlos Knippschild58445cb2025-06-09 18:27:314421. Open Preferences (`Ctrl+Shift+P` &gt; "Preferences: Open User Settings").
4432. Type "intellisense engine" in the settings search box.
4443. Select "Tag Parser" as the provider.
Daniel Cheng2d4c2d192022-07-01 01:38:31445
Ming-Ying Chung8dadf3f32024-03-12 18:47:27446Note: on a Chromebook, use **🔍+<8th button in the top row that's not ESC>**. In
Daniel Cheng2d4c2d192022-07-01 01:38:31447most cases, this is the top row button that is the closest to be directly above
448the 8 key.
449
ljustene262c8412017-04-12 08:29:04450### Launch Commands
Ming-Ying Chunga7db9dde82022-07-12 06:31:54451
ljustene262c8412017-04-12 08:29:04452Launch commands are the equivalent of `F5` in Visual Studio: They launch some
453program or a debugger. Optionally, they can run some task defined in
454`tasks.json`. Launch commands can be run from the debug view (`Ctrl+Shift+D`).
Ming-Ying Chunga7db9dde82022-07-12 06:31:54455
Ming-Ying Chung8dadf3f32024-03-12 18:47:27456Open the file at `.vscode/launch.json` and adjust the example launch commands to
457your situation and needs (e.g., the value of "type" needs adjustment for
458Windows).
ljustene262c8412017-04-12 08:29:04459
460### Key Bindings
Ming-Ying Chunga7db9dde82022-07-12 06:31:54461
ljustene262c8412017-04-12 08:29:04462To edit key bindings, press `Ctrl+K, Ctrl+S`. You'll see the defaults on the
Ming-Ying Chung8dadf3f32024-03-12 18:47:27463left and your overrides on the right stored in the file
464`.vscode/keybindings.json`. Please take a look and adjust them to your situation
465and needs. To change a key binding, copy the corresponding key binding to the
466right. It's fairly self-explanatory.
ljustene262c8412017-04-12 08:29:04467
468You can bind any command to a key, even commands specified by extensions like
469`CodeSearchOpen`. For instance, to bind `CodeSearchOpen` to `F2` to , simply add
Carlos Knippschild58445cb2025-06-09 18:27:31470`{ "key": "F2", "command": "cs.open" },`. Note that the command title
471`CodeSearchOpen` won't work. You have to get the actual command name from the
472[package.json file](https://github.com/chaopeng/vscode-chromium-codesearch/blob/master/package.json)
ljustene262c8412017-04-12 08:29:04473of the extension.
474
Carlos Knippschild58445cb2025-06-09 18:27:31475If you are used to other editors, you can also install your favorite keymap. For
476instance, to install eclipse keymaps, install the `vscode-eclipse-keybindings`
477extension. More keymaps can be found
ljustene262c8412017-04-12 08:29:04478[in the marketplace](https://marketplace.visualstudio.com/search?target=vscode&category=Keymaps).
479
Ming-Ying Chung8dadf3f32024-03-12 18:47:27480### Fixes for Known Issues
Ming-Ying Chunga7db9dde82022-07-12 06:31:54481
Ming-Ying Chung8dadf3f32024-03-12 18:47:27482#### Git on Windows
483
484If you only have the `depot_tools` Git installed on your machine, even though it
485is in your PATH, VS Code will ignore it as it seems to be looking for `git.exe`.
486You will have to add the following to your settings in order for the Git
487integration to work:
488
489```json
490{
491 "git.path": "C:\\src\\depot_tools\\git.bat"
492
493 // more settings here...
494}
ljustene262c8412017-04-12 08:29:04495```
496
Ming-Ying Chung8dadf3f32024-03-12 18:47:27497Tip: you can jump to the settings JSON file by using `Ctrl+Shift+P` and using
498the "Preferences: Open User Settings (JSON)" verb (for whatever reason, setting
499`git.path` as a folder setting does not appear to work).
500
Daniel Murphyd9e88fbb2020-03-17 19:26:23501### Remote
Ming-Ying Chunga7db9dde82022-07-12 06:31:54502
503*** promo
Ming-Ying Chung8dadf3f32024-03-12 18:47:27504Googlers: See [go/vscode-remote](http://go/vscode-remote) instead.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54505***
506
507VS Code now has a
Daniel Murphyd9e88fbb2020-03-17 19:26:23508[Remote](https://code.visualstudio.com/docs/remote/remote-overview) framework
Ming-Ying Chunga7db9dde82022-07-12 06:31:54509that allows you to use VS Code on your laptop while your code is hosted
Carlos Knippschild58445cb2025-06-09 18:27:31510elsewhere. This really shines when used in conjunction with the vscode-clangd
511plugin, which allows clangd to run remotely as well.
Daniel Murphyd9e88fbb2020-03-17 19:26:23512
513To get this to run, install the Remote pack extension, and then make sure your
514ssh config file has your remote connection:
515
516`~/.ssh/config`:
Carlos Knippschild58445cb2025-06-09 18:27:31517
Daniel Murphyd9e88fbb2020-03-17 19:26:23518```
519Host my-connection
520 HostName my-remote-host.corp.company.com
521```
522
Ming-Ying Chunga7db9dde82022-07-12 06:31:54523VS Code will then list this connection in the 'Remote Explorer' section on the
524left. To launch VS Code with this connection, click on the '+window' icon next
Daniel Murphyd9e88fbb2020-03-17 19:26:23525to the listed hostname. It has you choose a folder - use the 'src' folder root.
Ming-Ying Chunga7db9dde82022-07-12 06:31:54526This will open a new VS Code window in 'Remote' mode. ***Now you can install
Daniel Murphyd9e88fbb2020-03-17 19:26:23527extensions specifically for your remote connection, like vscode-clangd, etc.***
528
Peter Wen3ba91202020-06-17 15:56:54529#### Chromebooks
530
531For Googlers, [here](http://go/vscode/remote_development_via_web) are
532Google-specific instructions for setting up remote development on chromebooks
533without using Crostini.
534
Daniel Murphyd9e88fbb2020-03-17 19:26:23535#### Windows & SSH
Yuwei Huang1c4f50c2021-08-06 22:41:56536
Ming-Ying Chunga7db9dde82022-07-12 06:31:54537VS Code remote tools requires 'sshd' which isn't installed on Windows by
538default.
Yuwei Huang1c4f50c2021-08-06 22:41:56539
Ming-Ying Chunga7db9dde82022-07-12 06:31:54540For Googlers, sshd should already be installed on your workstation, and VS Code
Yuwei Huang1c4f50c2021-08-06 22:41:56541should work remotely if you followed the setup instructions at
542[go/building-chrome-win](http://go/building-chrome-win). If you are still having
543problems, please refer to
544[go/vscode-remote#windows](http://go/vscode-remote#windows).
545
Ho Cheungc083ca12023-04-06 14:22:07546Non-Googlers may follow Microsoft's instructions for
Yuwei Huang1c4f50c2021-08-06 22:41:56547[installing the OpenSSH server](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse).
Ming-Ying Chunga7db9dde82022-07-12 06:31:54548VS Code should work remotely after following this step.
Daniel Murphyd9e88fbb2020-03-17 19:26:23549
Dan Harringtonb06ce2f2019-04-09 15:35:29550### Snippets
Yuki Osaki0a255c582021-12-20 05:35:26551
Dan Harringtonb06ce2f2019-04-09 15:35:29552There are some useful snippets provided in
Carlos Knippschild32f9beb62025-06-06 16:56:35553[//tools/vscode/cpp.code-snippets](/tools/vscode/cpp.code-snippets), which are
554already installed to your workspace at `.vscode/cpp.code-snippets`.
Mounir Lamouri3b9e31d2019-07-30 20:14:41555
ljustene262c8412017-04-12 08:29:04556### Tips
557
558#### The `out` folder
Ming-Ying Chunga7db9dde82022-07-12 06:31:54559
Tiago Vignatti3e5b18bc2023-03-30 13:13:46560Automatically generated code is put into a subfolder of `out/`, which means that
ljustene262c8412017-04-12 08:29:04561these files are ignored by VS Code (see files.exclude above) and cannot be
Tiago Vignatti3e5b18bc2023-03-30 13:13:46562opened e.g. from quick-open (`Ctrl+P`). As of version 1.21, VS Code does not
563support negated glob commands, but you can define a set of exclude pattern to
564include only `out/Debug/gen`:
Carlos Knippschild58445cb2025-06-09 18:27:31565
Christian Dullweberbabb96e12018-05-28 14:00:14566```
Christian Dullweberd67c9b32018-04-03 08:30:42567"files.exclude": {
568 // Ignore build output folders. Except out/Debug/gen/
569 "out/[^D]*/": true,
570 "out/Debug/[^g]*": true,
571 "out/Debug/g[^e]*": true,
572 "out_*/**": true,
573},
Christian Dullweberbabb96e12018-05-28 14:00:14574```
Christian Dullweberd67c9b32018-04-03 08:30:42575
576Once it does, you can use
Carlos Knippschild58445cb2025-06-09 18:27:31577
ljustene262c8412017-04-12 08:29:04578```
579"!out/Debug/gen/**": true
580```
Carlos Knippschild58445cb2025-06-09 18:27:31581
ljustene262c8412017-04-12 08:29:04582in files.exclude instead of the symlink.
583
584#### Using VS Code as git editor
Ming-Ying Chunga7db9dde82022-07-12 06:31:54585
ljustene262c8412017-04-12 08:29:04586Add `[core] editor = "code --wait"` to your `~/.gitconfig` file in order to use
587VS Code as editor for git commit messages etc. Note that the editor starts up
588significantly slower than nano or vim. To use VS Code as merge tool, add
589`[merge] tool = code`.
590
591#### Task Names
Ming-Ying Chunga7db9dde82022-07-12 06:31:54592
ljustene262c8412017-04-12 08:29:04593Note that we named the tasks `1-build_chrome_debug`, `2-build_chrome_release`
Carlos Knippschild58445cb2025-06-09 18:27:31594etc. This allows you to quickly execute tasks by pressing their number: Press
595`Ctrl+P` and enter `task <n>`, where `<n>` is the number of the task. You can
596also create a keyboard shortcut for running a task. `File > Preferences >
ljustene262c8412017-04-12 08:29:04597Keyboard Shortcuts` and add `{ "key": "ctrl+r", "command":
598"workbench.action.tasks.runTask", "when": "!inDebugMode" }`. Then it's
599sufficient to press `Ctrl+R` and enter `<n>`.
600
601#### Working on Laptop
Ming-Ying Chunga7db9dde82022-07-12 06:31:54602
Bartek Nowierskifa835f8c2021-02-24 00:36:02603You might want to disable git status autorefresh to save battery.
chaopengca285112017-03-02 15:39:04604
605```
chaopeng5c66dfe2017-03-22 13:51:45606"git.autorefresh": false,
chaopengca285112017-03-02 15:39:04607```
608
Tommy Nyquistdc2ceaa42021-03-15 20:29:04609#### Editing in multiple Git repositories
Ming-Ying Chunga7db9dde82022-07-12 06:31:54610
Carlos Knippschild58445cb2025-06-09 18:27:31611If you frequently work in multiple Git repositories that are part of the
612Chromium repository, you might find that the built-in tooling does not work as
613expected for files that exist below folders that are part of a `.gitignore` file
614checked in to Chromium.
Tommy Nyquistdc2ceaa42021-03-15 20:29:04615
Carlos Knippschild58445cb2025-06-09 18:27:31616To work around this, you can add the directories you edit as separate `folders`
617entries in your workspace configuration, and ensure that the directories that
618are ignored in Chromium are listed **before** the Chromium `src` path.
Tommy Nyquistdc2ceaa42021-03-15 20:29:04619
Carlos Knippschild58445cb2025-06-09 18:27:31620To edit this, go to `Settings` -> Select the `Workspace` tab, and choose to open
621as JSON (button in the top right), and configure `folders` like this (change
622paths to match your local setup and usage):
Tommy Nyquistdc2ceaa42021-03-15 20:29:04623
624```
625{
626 "folders": [
627 {
628 "path": "chromium/src/third_party/perfetto"
629 },
630 {
631 "path": "chromium/src"
632 }
633 ]
634}
635```
636
Jianpeng Chaob4048b82018-08-28 23:40:01637### Unable to open $File resource is not available when debugging Chromium on Linux
Ming-Ying Chunga7db9dde82022-07-12 06:31:54638
Carlos Knippschild58445cb2025-06-09 18:27:31639Chromium
640[recently changed](https://docs.google.com/document/d/1OX4jY_bOCeNK7PNjVRuBQE9s6BQKS8XRNWGK8FEyh-E/edit?usp=sharing)
641the file path to be relative to the output dir. Check `gn args out/$dir --list`
642if `strip_absolute_paths_from_debug_symbols` is true (which is the default), set
643`cwd` to the output dir. otherwise, set `cwd` to `${workspaceFolder}`.
Jianpeng Chaob4048b82018-08-28 23:40:01644
chaopengba312ce2017-02-12 03:38:25645### More
Ming-Ying Chunga7db9dde82022-07-12 06:31:54646
ljustene262c8412017-04-12 08:29:04647More tips and tricks can be found
Ryan Tarpine78d07f82022-11-14 16:19:27648[here](https://code.visualstudio.com/docs/getstarted/tips-and-tricks).