ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 1 | # Visual Studio Code Dev |
| 2 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 3 | **Get started [here](#setup)**. |
| 4 | |
Tiago Vignatti | 3e5b18bc | 2023-03-30 13:13:46 | [diff] [blame] | 5 | [Visual Studio Code (VS Code)](https://code.visualstudio.com) is a free, open |
| 6 | source, lightweight and powerful code editor for Windows, macOS and Linux, based |
| 7 | on [Electron](https://www.electronjs.org/)/Chromium. It has built-in support for |
| 8 | JavaScript, TypeScript and Node.js and a rich extension ecosystem that adds |
| 9 | intellisense, debugging, syntax highlighting etc. For many languages like C++, |
| 10 | Python, Go, Java, it works without too much setup. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 11 | |
| 12 | It is NOT a full-fledged IDE like Visual Studio. The two are completely |
| 13 | separate products. The only commonality with Visual Studio is that both are |
| 14 | from Microsoft. |
| 15 | |
| 16 | Here's what works well: |
| 17 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 18 | * **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 |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 22 | 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 Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 26 | * [**Debugging**](https://code.visualstudio.com/Docs/editor/debugging) works |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 27 | 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 Heise | 9a71143 | 2020-10-14 23:55:39 | [diff] [blame] | 30 | * For more information on debugging Python code, see [here](vscode_python.md). |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 31 | * **Command Palette** makes opening files and searching solution really easy. |
| 32 | * **Building** works well. Build tools are easy to integrate. Warnings and errors |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 33 | are displayed on a separate page and you can click to jump to the |
| 34 | corresponding line of code. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 35 | * **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. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 39 | |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 40 | [TOC] |
| 41 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 42 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 43 | ## Updating This Page |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 44 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 45 | Please keep this doc up-to-date. VS Code is still in active development and |
| 46 | subject to changes. This doc is checked into the Chromium git repo, so if you |
| 47 | make changes, read the [documentation |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 48 | guidelines](documentation_guidelines.md) and |
| 49 | [submit a change list](contributing.md). |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 50 | |
Tiago Vignatti | 3e5b18bc | 2023-03-30 13:13:46 | [diff] [blame] | 51 | All file paths and commands have been tested on Linux and macOS. Windows might |
| 52 | require a slightly different setup. Please update this page accordingly. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 53 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 54 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 55 | ## Setup |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 56 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 57 | ### Installation |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 58 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 59 | *** promo |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 60 | Googlers: See [go/vscode/install](http://go/vscode/install) instead. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 61 | *** |
| 62 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 63 | Follow the steps on [Setting up Visual Studio Code][setup] to install a proper |
| 64 | version for you development platform. |
| 65 | |
| 66 | [setup]: https://code.visualstudio.com/docs/setup/setup-overview |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 67 | |
| 68 | ### Usage |
| 69 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 70 | To run it on Linux or on macOS: |
| 71 | |
| 72 | ```bash |
| 73 | cd /path/to/chromium/src |
| 74 | code . |
| 75 | ``` |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 76 | |
Daniel Cheng | 2d4c2d19 | 2022-07-01 01:38:31 | [diff] [blame] | 77 | If you installed Code Insiders, the binary name is `code-insiders` instead. |
| 78 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 79 | Note that VS Code does not require project or solution files. However, it does |
| 80 | store workspace settings in a `.vscode` folder in your base directory (i.e. your |
| 81 | project root folder). See the [Chromium Workspace Settings](#setup-for-chromium) |
| 82 | section for details. |
Daniel Cheng | 2d4c2d19 | 2022-07-01 01:38:31 | [diff] [blame] | 83 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 84 | ### Useful Extensions |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 85 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 86 | Up to now, you have a basic version of VS Code without much language support. |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 87 | Next, we will install some useful extensions. |
| 88 | |
| 89 | #### Recommended Extensions |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 90 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 91 | You will most likely use the following extensions every day: |
| 92 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 93 | There are 2 ways to install them: |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 94 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 95 | * Follow the instructions from |
| 96 | [Install Recommended Extensions](#install-recommended-extensions). |
| 97 | * Manual installation. Jump to the extensions window (`Ctrl+Shift+X`, or |
| 98 | `Cmd+Shift+X` in macOS) and search the names of the following extensions. |
| 99 | |
| 100 | *** aside |
| 101 | Note: All the extension settings mentioned below are already set in |
| 102 | `tools/vscode/settings.json`. You don't have do anything if you have followed |
| 103 | [the instructions](#setup-for-chromium) to copy that file into your workspace. |
| 104 | *** |
| 105 | |
| 106 | * [**ChromiumIDE**](https://marketplace.visualstudio.com/items?itemName=Google.cros-ide) - |
| 107 | The critical extension to make Chromium/ChromiumOS development easier and |
| 108 | faster by anchoring core tools in one place. |
| 109 | * [**Chromium Context**](https://marketplace.visualstudio.com/items?itemName=solomonkinard.chromium-context) - |
| 110 | Provides Chromium-specific context, e.g. code owners, release version, |
| 111 | author blame list, in a single tab for an opened file. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 112 | * [**C/C++**](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) - |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 113 | Code formatting, debugging, Intellisense. Enables the use of clang-format |
| 114 | (via the `C_Cpp.clang_format_path` setting) and format-on-save (via the |
| 115 | `editor.formatOnSave` setting). |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 116 | * [**vscode-clangd**](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd) - |
| 117 | Enables VS Code to compile Chromium, provide Chromium XRefs to support |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 118 | functions like jumping to definition, and provide a clangd |
| 119 | [language server][lang-server] powering smarter autocompletion than |
| 120 | **C/C++** extension's IntelliSense, but they also conflicts with each |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 121 | other. To resolve the conflict, add the following to `settings.json`: |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 122 | `"C_Cpp.intelliSenseEngine": "disabled"`. See [clangd.md](clangd.md) for |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 123 | setup instructions. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 124 | * [**Toggle Header/Source**](https://marketplace.visualstudio.com/items?itemName=bbenoist.togglehs) - |
James Cook | 9f7c73d | 2017-06-20 15:06:19 | [diff] [blame] | 125 | Toggles between .cc and .h with `F4`. The C/C++ extension supports this as |
| 126 | well through `Alt+O` but sometimes chooses the wrong file when there are |
| 127 | multiple files in the workspace that have the same name. |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 128 | * [**vscode-proto3**](https://marketplace.visualstudio.com/items?itemName=zxh404.vscode-proto3) - |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 129 | Syntax highlighting for .proto files. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 130 | * [**Mojom IDL support**](https://marketplace.visualstudio.com/items?itemName=Google.vscode-mojom) - |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 131 | Syntax highlighting and a [language server][lang-server] for .mojom files. |
James Lee | 36970c24 | 2022-07-12 11:44:27 | [diff] [blame] | 132 | * [**GN**](https://marketplace.visualstudio.com/items?itemName=msedge-dev.gnls) - |
| 133 | Code IntelliSense for the GN build system. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 134 | * [**Rewrap**](https://marketplace.visualstudio.com/items?itemName=stkb.rewrap) - |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 135 | Wrap lines at 80 characters with `Alt+Q`. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 136 | * [**Remote**](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) - |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 137 | Remotely connect to your workstation through SSH using your laptop. See the |
| 138 | [Remote](#Remote) section for more information about how to set this up. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 139 | * [**GitLens**](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) - |
| 140 | Git supercharged. A Powerful, feature rich, and highly customizable git |
| 141 | extension. |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 142 | * [**Python**](https://marketplace.visualstudio.com/items?itemName=ms-python.python) - |
| 143 | Linting, intellisense, code formatting, refactoring, debugging, snippets. |
| 144 | * If you want type checking, add: `"python.analysis.typeCheckingMode": "basic",` |
| 145 | to your `settings.json` file (you can also find it in the settings UI). |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 146 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 147 | [lang-server]: https://microsoft.github.io/language-server-protocol/ |
| 148 | |
| 149 | #### Optional Extensions |
| 150 | |
| 151 | The following extensions are not included in |
| 152 | [//tools/vscode/settings.json](/tools/vscode/settings.json), but they might be |
| 153 | useful for you as well: |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 154 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 155 | ```bash |
Ho Cheung | a645ddc | 2024-07-02 05:02:09 | [diff] [blame] | 156 | $ echo "ryu1kn.annotator wmaurer.change-case shd101wyy.markdown-preview-enhanced Gruntfuggly.todo-tree alefragnani.Bookmarks spmeesseman.vscode-taskexplorer streetsidesoftware.code-spell-checker george-alisson.html-preview-vscode anseki.vscode-color" | xargs -n 1 code --force --install-extension |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 157 | ``` |
| 158 | |
Ho Cheung | a645ddc | 2024-07-02 05:02:09 | [diff] [blame] | 159 | * [**Annotator**](https://marketplace.visualstudio.com/items?itemName=ryu1kn.annotator) - |
| 160 | Display git blame info along with your code. Can open the diff of a particular commit from there. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 161 | * [**change-case**](https://marketplace.visualstudio.com/items?itemName=wmaurer.change-case) - |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 162 | Quickly change the case of the current selection or current word. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 163 | * [**Markdown Preview Enhanced**](https://marketplace.visualstudio.com/items?itemName=shd101wyy.markdown-preview-enhanced) - |
| 164 | Preview markdown side-by-side with automatic scroll sync and many other |
Tiago Vignatti | 3e5b18bc | 2023-03-30 13:13:46 | [diff] [blame] | 165 | features with `Ctrl+k v`. This document was written with this extension! |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 166 | * [**Todo Tree**](https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree) - |
| 167 | Displays comment tags like TODO/FIXME in a tree view in a dedicated sidebar. |
| 168 | * [**Bookmarks**](https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks) - |
| 169 | Supports easy mark/unmark positions in the codebase and displays them in a |
| 170 | dedicated sidebar. Very useful for a large codebase like Chromium. |
| 171 | * [**Task Explorer**](https://marketplace.visualstudio.com/items?itemName=spmeesseman.vscode-taskexplorer) - |
| 172 | Displays supported tasks, e.g. vscode tasks, shell scripts and others, |
| 173 | organized into a treeview in sidebar. |
| 174 | * [**Code Spell Checker**](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) - |
| 175 | A basic spell checker that works well with camelCase code. It helps catch |
| 176 | common spelling errors. |
Ho Cheung | c4cd9e5 | 2023-04-05 01:32:21 | [diff] [blame] | 177 | * [**HTML Preview**](https://marketplace.visualstudio.com/items?itemName=george-alisson.html-preview-vscode) - |
Tiago Vignatti | 3e5b18bc | 2023-03-30 13:13:46 | [diff] [blame] | 178 | Previews HTML files while editing with `Ctrl+k v`. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 179 | * [**Color Picker**](https://marketplace.visualstudio.com/items?itemName=anseki.vscode-color) - |
| 180 | Visualizes color codes inline and provides color picker GUI to generates new |
| 181 | color codes. |
Peter Wen | ba247f54 | 2024-03-15 19:37:47 | [diff] [blame] | 182 | * [**Bazel**](https://marketplace.visualstudio.com/items?itemName=BazelBuild.vscode-bazel) - |
| 183 | This is very useful for editing `*.star` starlark files. If you want "Go |
| 184 | to definition" to work in our `infra/config` directory, see the |
| 185 | [//tools/vscode/bazel_lsp/README.md][lsp_patches_readme] |
| 186 | |
| 187 | [lsp_patches_readme]: ../tools/vscode/bazel_lsp/README.md |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 188 | |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 189 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 190 | Also be sure to take a look at the |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 191 | [VS Code marketplace](https://marketplace.visualstudio.com/VSCode) to check out |
| 192 | other useful extensions. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 193 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 194 | ### Color Scheme |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 195 | |
Tiago Vignatti | 3e5b18bc | 2023-03-30 13:13:46 | [diff] [blame] | 196 | Press `Ctrl+Shift+P (Cmd+Shift+P `in macOS`), color, Enter` to pick a color |
| 197 | scheme for the editor. There are also tons of [color schemes available for |
| 198 | download on the |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 199 | marketplace](https://marketplace.visualstudio.com/search?target=VSCode&category=Themes&sortBy=Downloads). |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 200 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 201 | ### Keyboard Shortcuts |
| 202 | |
| 203 | #### CheatSheet |
| 204 | |
| 205 | * [Windows](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf) |
Tiago Vignatti | 3e5b18bc | 2023-03-30 13:13:46 | [diff] [blame] | 206 | * [macOS](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf) |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 207 | |
Tiago Vignatti | 3e5b18bc | 2023-03-30 13:13:46 | [diff] [blame] | 208 | #### Useful Shortcuts (Linux) |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 209 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 210 | * `Ctrl+P` opens a search box to find and open a file. |
| 211 | * `F1` or `Ctrl+Shift+P` opens a search box to find a command (e.g. Tasks: Run |
Daniel Cheng | 2d4c2d19 | 2022-07-01 01:38:31 | [diff] [blame] | 212 | Task). Note: if you want to run one of the [Predefined tasks in |
| 213 | tasks.json](#Tasks), it is faster to just use `Ctrl+P` > "task <n>". |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 214 | * `Ctrl+K, Ctrl+S` opens the key bindings editor. |
| 215 | * ``Ctrl+` `` toggles the built-in terminal. |
| 216 | * `Ctrl+Shift+M` toggles the problems view (linter warnings, compile errors |
Quinten Yearsley | 317532d | 2021-10-20 17:10:31 | [diff] [blame] | 217 | and warnings). You'll switch a lot between terminal and problem view during |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 218 | compilation. |
| 219 | * `Alt+O` switches between the source/header file. |
| 220 | * `Ctrl+G` jumps to a line. |
| 221 | * `F12` jumps to the definition of the symbol at the cursor (also available on |
| 222 | right-click context menu). |
| 223 | * `Shift+F12` or `F1, CodeSearchReferences, Return` shows all references of |
| 224 | the symbol at the cursor. |
| 225 | * `F1, CodeSearchOpen, Return` opens the current file in Code Search. |
| 226 | * `Ctrl+D` selects the word at the cursor. Pressing it multiple times |
| 227 | multi-selects the next occurrences, so typing in one types in all of them, |
| 228 | and `Ctrl+U` deselects the last occurrence. |
| 229 | * `Ctrl+K, Z` enters Zen Mode, a fullscreen editing mode with nothing but the |
| 230 | current editor visible. |
| 231 | * `Ctrl+X` without anything selected cuts the current line. `Ctrl+V` pastes |
| 232 | the line. |
| 233 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 234 | *** aside |
| 235 | Note: See also [Key Bindings for Visual Studio Code |
| 236 | ](https://code.visualstudio.com/docs/getstarted/keybindings). |
| 237 | *** |
| 238 | |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 239 | ### Java/Android Support |
Victor Hugo Vianna Silva | c37c9b7 | 2021-10-28 00:32:32 | [diff] [blame] | 240 | |
Shuhei Takahashi | c2a26532 | 2025-01-10 02:20:16 | [diff] [blame] | 241 | There are two extensions you can use to get Java/Android support in VSCode: |
| 242 | |
Shuhei Takahashi | d12f0d2 | 2025-01-20 02:22:20 | [diff] [blame] | 243 | * a. [ChromiumIDE](https://marketplace.visualstudio.com/items?itemName=Google.cros-ide) |
| 244 | * b. [Language Support for Java™ by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java) |
Shuhei Takahashi | c2a26532 | 2025-01-10 02:20:16 | [diff] [blame] | 245 | |
| 246 | ChromiumIDE is much faster and more stable than the other extension, mainly |
| 247 | because it does not rely on background indexing and persistent cache. It works |
| 248 | without manually running scripts from the command line as the extension knows |
| 249 | how to extract build configurations from GN. On the other hand, its features are |
| 250 | limited compared to the other extension (e.g. debugger is not supported yet). |
| 251 | |
| 252 | Language Support for Java™ by Red Hat has more features as it is based on the |
| 253 | Eclipse JDT Language Server. But it is known to be very slow (it takes tens of |
| 254 | minutes to index the whole project in a single thread before serving requests |
| 255 | from VSCode) and less stable (it often gets confused when you sync the source |
| 256 | checkout, forcing you to clear the cache and wait indexing again). |
| 257 | |
| 258 | #### a. ChromiumIDE |
| 259 | |
| 260 | Install the latest **pre-release** version of |
| 261 | [ChromiumIDE](https://marketplace.visualstudio.com/items?itemName=Google.cros-ide) |
Shuhei Takahashi | d12f0d2 | 2025-01-20 02:22:20 | [diff] [blame] | 262 | from the VSCode marketplace. Make sure the extension version is **0.35.32** or |
Shuhei Takahashi | c2a26532 | 2025-01-10 02:20:16 | [diff] [blame] | 263 | later. |
| 264 | |
Shuhei Takahashi | d12f0d2 | 2025-01-20 02:22:20 | [diff] [blame] | 265 | Then just open a VSCode workspace containing Chromium source tree (opening |
Shuhei Takahashi | c2a26532 | 2025-01-10 02:20:16 | [diff] [blame] | 266 | subdirectories is fine) and open a Java file. If you haven't, you're prompted to |
| 267 | select the default build output directory (e.g. `out/Default`). |
| 268 | |
| 269 | #### b. Language Support for Java™ by Red Hat |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 270 | |
Etienne Dechamps | 2d40c55 | 2023-06-12 15:52:24 | [diff] [blame] | 271 | 1. **Add the following to your VS Code workspace `settings.json`:** |
Ho Cheung | 7c53eaf | 2024-05-31 00:31:26 | [diff] [blame] | 272 | |
| 273 | ``` |
| 274 | "java.import.gradle.enabled": false, |
| 275 | "java.import.maven.enabled": false |
| 276 | ``` |
| 277 | |
| 278 | This will prevent the language server from attempting to build *all* Gradle |
| 279 | and Maven projects that can be found anywhere in the Chromium source tree, |
| 280 | which typically results in hilarity. |
| 281 | |
| 282 | ``` |
| 283 | "java.jdt.ls.java.home": "<< ABSOLUTE PATH TO YOUR WORKING COPY OF CHROMIUM >>/src/third_party/jdk/current" |
| 284 | ``` |
| 285 | |
| 286 | This one is optional but reduces the likelihood of problems by making sure |
| 287 | the language server uses the same JDK as the Chromium build system (as |
| 288 | opposed to some random JDK from your host system). |
| 289 | |
Aldo Culquicondor | 329da18 | 2024-11-07 19:11:08 | [diff] [blame] | 290 | Also increase the resources available to the Java Language Server, for |
| 291 | example: |
| 292 | |
| 293 | ``` |
| 294 | "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx64G -Xms100m -Xlog:disable" |
| 295 | ``` |
| 296 | |
Etienne Dechamps | 2d40c55 | 2023-06-12 15:52:24 | [diff] [blame] | 297 | 2. **Install the |
| 298 | [*Language Support for Java™ by Red Hat*](https://marketplace.visualstudio.com/items?itemName=redhat.java) |
Etienne Dechamps | 2fba525 | 2023-06-15 18:39:45 | [diff] [blame] | 299 | extension.** |
Etienne Dechamps | 2d40c55 | 2023-06-12 15:52:24 | [diff] [blame] | 300 | You do not need any other extension. |
Shuhei Takahashi | 8b05339 | 2024-06-14 01:50:13 | [diff] [blame] | 301 | 3. **Build your code** in the usual way (i.e. using gn and ninja commands). |
Etienne Dechamps | 2d40c55 | 2023-06-12 15:52:24 | [diff] [blame] | 302 | This will produce build config files that are necessary for the next step. It |
| 303 | will also make autogenerated code visible to the language server. |
Shuhei Takahashi | 8b05339 | 2024-06-14 01:50:13 | [diff] [blame] | 304 | 4. **Generate the Eclipse JDT project** by running |
| 305 | `build/android/generate_vscode_project.py` from the `src` directory. |
| 306 | For example, if your build output directory is `out/Debug-x86` and your build |
| 307 | target is `//chrome/android:chrome_java`, run: |
| 308 | `build/android/generate_vscode_project.py --output-dir out/Debug-x86 --build-config gen/chrome/android/chrome_java.build_config.json`. |
| 309 | This will create `.project` and `.classpath` in the `src` directory. |
| 310 | 5. **Reload** your VS Code window to let it start importing the generated |
| 311 | project. |
| 312 | 6. **Open a Java source file then wait a couple of minutes** for the language |
Etienne Dechamps | 2d40c55 | 2023-06-12 15:52:24 | [diff] [blame] | 313 | server to build the project. |
Shuhei Takahashi | 8b05339 | 2024-06-14 01:50:13 | [diff] [blame] | 314 | 7. **Done!** You should now have full Java language support for any `.java` file |
Etienne Dechamps | 2d40c55 | 2023-06-12 15:52:24 | [diff] [blame] | 315 | that is included in the build. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 316 | |
Shuhei Takahashi | c2a26532 | 2025-01-10 02:20:16 | [diff] [blame] | 317 | ##### Known issues |
Michael Thiessen | f643e29f | 2020-03-24 20:23:01 | [diff] [blame] | 318 | |
Etienne Dechamps | 2d40c55 | 2023-06-12 15:52:24 | [diff] [blame] | 319 | * Errors related to `GEN_JNI` are caused by the language server (rightfully) |
| 320 | getting confused about multiple definitions of the |
Sam Maier | e1df6f2 | 2023-08-11 14:20:40 | [diff] [blame] | 321 | [autogenerated](/third_party/jni_zero/README.md) `GEN_JNI` class. This |
Etienne Dechamps | 2d40c55 | 2023-06-12 15:52:24 | [diff] [blame] | 322 | is a known quirk of the JNI generator. |
Michael Thiessen | e057a6c | 2020-03-25 19:24:01 | [diff] [blame] | 323 | |
Shuhei Takahashi | c2a26532 | 2025-01-10 02:20:16 | [diff] [blame] | 324 | ##### Troubleshooting |
Shuhei Takahashi | 8b05339 | 2024-06-14 01:50:13 | [diff] [blame] | 325 | |
| 326 | * If you have used the previous instructions to use |
| 327 | `generate_vscode_classpath.py` or you think something went wrong, try clearing |
| 328 | the internal state of the language server by executing |
| 329 | `Java: Clean Java Language Server Workspace` from the command palette. This |
| 330 | will force the language server to rebuild its internal workspace by importing |
| 331 | the generated Eclipse JDT project. |
| 332 | |
Etienne Dechamps | 2fba525 | 2023-06-15 18:39:45 | [diff] [blame] | 333 | #### Automatic formatting |
| 334 | |
| 335 | Java code in Chromium is formatted using [clang-format](/docs/clang_format.md). |
| 336 | To get VS Code to use clang-format to format Java files, install the |
| 337 | [*Clang-Format* extension](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format) |
| 338 | and set it as the default formatter for Java in your workspace `settings.json`: |
| 339 | |
| 340 | ```json |
| 341 | "[java]": { |
| 342 | "editor.defaultFormatter": "xaver.clang-format" |
| 343 | } |
| 344 | ``` |
| 345 | |
| 346 | To avoid potential formatting differences due to clang-format version skew, it |
| 347 | makes sense to configure the extension to run clang-format in the same way |
| 348 | `git cl format` would. You can do this by adding the following to your |
| 349 | workspace `settings.json`: |
| 350 | |
| 351 | ```json |
| 352 | "clang-format.executable": "<< PATH TO YOUR CHROMIUM WORKING COPY >>/src/buildtools/linux64/clang-format" |
| 353 | ``` |
| 354 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 355 | ## Setup For Chromium |
| 356 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 357 | VS Code is configured via JSON files. This section describes how to configure |
| 358 | it for a better Chromium development experience. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 359 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 360 | *** aside |
| 361 | Note: See [VS Code |
| 362 | documentation](https://code.visualstudio.com/docs/customization/overview) for a |
| 363 | more general introduction to VS Code customization. |
| 364 | *** |
| 365 | |
| 366 | The Chromium repository comes with some basic configuration. Run the following |
| 367 | commands to initialize VS Code for your Chromium checkout: |
| 368 | |
| 369 | ```bash |
| 370 | cd /path/to/chromium/src |
| 371 | mkdir .vscode |
| 372 | cp tools/vscode/*.json .vscode/ |
| 373 | cp tools/vscode/cpp.code-snippets .vscode/ |
| 374 | ``` |
| 375 | |
| 376 | Once you have done, proceed to the next sections to install recommended |
| 377 | extensions and perform customization. |
| 378 | |
| 379 | ### Install Recommended Extensions |
| 380 | |
| 381 | As described in the [Useful Extensions](#useful-extensions) sections, there are |
| 382 | essential extensions to help Chromium development. Follow the steps below: |
| 383 | |
Lalit Rana | 82332dd | 2024-11-18 18:20:55 | [diff] [blame] | 384 | 1. In VS Code's Command Palette (`Ctrl+Shift+P`, or `Cmd+Shift+P` in macOS), |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 385 | type `Show Recommended Extensions`, and press `Enter`. |
| 386 | 2. In the WORKSPACE RECOMMENDATIONS section of the EXTENSIONS sidebar, click the |
| 387 | `Install Workspace Recommended Extensions` (shown as a cloud icon). |
| 388 | |
| 389 | Now you are all set. |
| 390 | |
| 391 | ### Customize Workspace Settings |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 392 | |
Daniel Cheng | 2d4c2d19 | 2022-07-01 01:38:31 | [diff] [blame] | 393 | Open the file [//tools/vscode/settings.json](/tools/vscode/settings.json), |
Darwin Huang | 985c38a | 2018-11-21 19:24:13 | [diff] [blame] | 394 | and check out the default settings there. Feel free to commit added or removed |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 395 | settings to enable better team development, or change settings locally in |
| 396 | `.vscode/settings.json` to suit personal preference. |
Raphael Kubo da Costa | e6e63d3 | 2022-09-14 18:17:18 | [diff] [blame] | 397 | |
Raphael Kubo da Costa | e6e63d3 | 2022-09-14 18:17:18 | [diff] [blame] | 398 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 399 | *** aside |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 400 | Note: these settings assume that the workspace folder (the root folder displayed |
Bartek Nowierski | fa835f8c | 2021-02-24 00:36:02 | [diff] [blame] | 401 | in the Explorer tab) is Chromium's `src/` directory. If this is not the case, |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 402 | replace any references to `${workspaceFolder}` with the path to your `src/`. |
| 403 | *** |
Jesse McKenna | fffd811 | 2020-05-08 19:18:48 | [diff] [blame] | 404 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 405 | ### Tasks |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 406 | |
Dan Harrington | b426cf9b | 2020-09-10 19:47:08 | [diff] [blame] | 407 | Next, we'll tell VS Code how to compile our code, run tests, and to read |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 408 | warnings and errors from the build output. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 409 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 410 | Open the file `.vscode/tasks.json`. This will provide tasks to do basic things. |
| 411 | You might have to adjust the commands to your situation and needs. For example, |
| 412 | before running most of the tasks, you'll need to set the `chromeOutputDir` value |
| 413 | in that file. |
Daniel Cheng | 2d4c2d19 | 2022-07-01 01:38:31 | [diff] [blame] | 414 | |
Tiago Vignatti | 3e5b18bc | 2023-03-30 13:13:46 | [diff] [blame] | 415 | Now you can run tasks by using `Ctrl+P` (`Cmd+Shift+P` in macOS) and typing |
| 416 | "task " and then a number of your choice. If you select one of the build tasks, |
| 417 | the build output will display in the terminal pane. Jump through build problems |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 418 | quickly using `F8` / `Shift-F8`. See [task names](#task-names) for more info on |
Tiago Vignatti | 3e5b18bc | 2023-03-30 13:13:46 | [diff] [blame] | 419 | running tasks. |
Daniel Cheng | 2d4c2d19 | 2022-07-01 01:38:31 | [diff] [blame] | 420 | |
| 421 | If you have intellisense enabled but do not have include paths set up correctly, |
| 422 | jumping through problems will also try to navigate through all the include files |
| 423 | it cannot locate and add a lot of noise. You can fix your include path or simply |
| 424 | set intellisense to "tag parser" mode by doing the following: |
| 425 | |
| 426 | 1. Open Preferences (`Ctrl+Shift+P` > "Preferences: Open User Settings"). |
| 427 | 2. Type "intellisense engine" in the settings search box. |
| 428 | 3. Select "Tag Parser" as the provider. |
| 429 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 430 | Note: on a Chromebook, use **🔍+<8th button in the top row that's not ESC>**. In |
Daniel Cheng | 2d4c2d19 | 2022-07-01 01:38:31 | [diff] [blame] | 431 | most cases, this is the top row button that is the closest to be directly above |
| 432 | the 8 key. |
| 433 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 434 | ### Launch Commands |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 435 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 436 | Launch commands are the equivalent of `F5` in Visual Studio: They launch some |
| 437 | program or a debugger. Optionally, they can run some task defined in |
| 438 | `tasks.json`. Launch commands can be run from the debug view (`Ctrl+Shift+D`). |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 439 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 440 | Open the file at `.vscode/launch.json` and adjust the example launch commands to |
| 441 | your situation and needs (e.g., the value of "type" needs adjustment for |
| 442 | Windows). |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 443 | |
| 444 | ### Key Bindings |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 445 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 446 | To edit key bindings, press `Ctrl+K, Ctrl+S`. You'll see the defaults on the |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 447 | left and your overrides on the right stored in the file |
| 448 | `.vscode/keybindings.json`. Please take a look and adjust them to your situation |
| 449 | and needs. To change a key binding, copy the corresponding key binding to the |
| 450 | right. It's fairly self-explanatory. |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 451 | |
| 452 | You can bind any command to a key, even commands specified by extensions like |
| 453 | `CodeSearchOpen`. For instance, to bind `CodeSearchOpen` to `F2` to , simply add |
| 454 | `{ "key": "F2", "command": "cs.open" },`. |
| 455 | Note that the command title `CodeSearchOpen` won't work. You have to get the |
| 456 | actual command name from the [package.json |
| 457 | file](https://github.com/chaopeng/vscode-chromium-codesearch/blob/master/package.json) |
| 458 | of the extension. |
| 459 | |
| 460 | If you are used to other editors, you can also install your favorite keymap. |
| 461 | For instance, to install eclipse keymaps, install the |
| 462 | `vscode-eclipse-keybindings` extension. More keymaps can be found |
| 463 | [in the marketplace](https://marketplace.visualstudio.com/search?target=vscode&category=Keymaps). |
| 464 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 465 | ### Fixes for Known Issues |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 466 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 467 | #### Git on Windows |
| 468 | |
| 469 | If you only have the `depot_tools` Git installed on your machine, even though it |
| 470 | is in your PATH, VS Code will ignore it as it seems to be looking for `git.exe`. |
| 471 | You will have to add the following to your settings in order for the Git |
| 472 | integration to work: |
| 473 | |
| 474 | ```json |
| 475 | { |
| 476 | "git.path": "C:\\src\\depot_tools\\git.bat" |
| 477 | |
| 478 | // more settings here... |
| 479 | } |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 480 | ``` |
| 481 | |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 482 | Tip: you can jump to the settings JSON file by using `Ctrl+Shift+P` and using |
| 483 | the "Preferences: Open User Settings (JSON)" verb (for whatever reason, setting |
| 484 | `git.path` as a folder setting does not appear to work). |
| 485 | |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 486 | ### Remote |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 487 | |
| 488 | *** promo |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 489 | Googlers: See [go/vscode-remote](http://go/vscode-remote) instead. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 490 | *** |
| 491 | |
| 492 | VS Code now has a |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 493 | [Remote](https://code.visualstudio.com/docs/remote/remote-overview) framework |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 494 | that allows you to use VS Code on your laptop while your code is hosted |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 495 | elsewhere. This really shines when used in conjunction with the vscode-clangd plugin, |
| 496 | which allows clangd to run remotely as well. |
| 497 | |
| 498 | To get this to run, install the Remote pack extension, and then make sure your |
| 499 | ssh config file has your remote connection: |
| 500 | |
| 501 | `~/.ssh/config`: |
| 502 | ``` |
| 503 | Host my-connection |
| 504 | HostName my-remote-host.corp.company.com |
| 505 | ``` |
| 506 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 507 | VS Code will then list this connection in the 'Remote Explorer' section on the |
| 508 | left. To launch VS Code with this connection, click on the '+window' icon next |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 509 | to the listed hostname. It has you choose a folder - use the 'src' folder root. |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 510 | This will open a new VS Code window in 'Remote' mode. ***Now you can install |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 511 | extensions specifically for your remote connection, like vscode-clangd, etc.*** |
| 512 | |
Peter Wen | 3ba9120 | 2020-06-17 15:56:54 | [diff] [blame] | 513 | #### Chromebooks |
| 514 | |
| 515 | For Googlers, [here](http://go/vscode/remote_development_via_web) are |
| 516 | Google-specific instructions for setting up remote development on chromebooks |
| 517 | without using Crostini. |
| 518 | |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 519 | #### Windows & SSH |
Yuwei Huang | 1c4f50c | 2021-08-06 22:41:56 | [diff] [blame] | 520 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 521 | VS Code remote tools requires 'sshd' which isn't installed on Windows by |
| 522 | default. |
Yuwei Huang | 1c4f50c | 2021-08-06 22:41:56 | [diff] [blame] | 523 | |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 524 | For Googlers, sshd should already be installed on your workstation, and VS Code |
Yuwei Huang | 1c4f50c | 2021-08-06 22:41:56 | [diff] [blame] | 525 | should work remotely if you followed the setup instructions at |
| 526 | [go/building-chrome-win](http://go/building-chrome-win). If you are still having |
| 527 | problems, please refer to |
| 528 | [go/vscode-remote#windows](http://go/vscode-remote#windows). |
| 529 | |
Ho Cheung | c083ca1 | 2023-04-06 14:22:07 | [diff] [blame] | 530 | Non-Googlers may follow Microsoft's instructions for |
Yuwei Huang | 1c4f50c | 2021-08-06 22:41:56 | [diff] [blame] | 531 | [installing the OpenSSH server](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse). |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 532 | VS Code should work remotely after following this step. |
Daniel Murphy | d9e88fb | 2020-03-17 19:26:23 | [diff] [blame] | 533 | |
Dan Harrington | b06ce2f | 2019-04-09 15:35:29 | [diff] [blame] | 534 | ### Snippets |
Yuki Osaki | 0a255c5 | 2021-12-20 05:35:26 | [diff] [blame] | 535 | |
Dan Harrington | b06ce2f | 2019-04-09 15:35:29 | [diff] [blame] | 536 | There are some useful snippets provided in |
Ming-Ying Chung | 8dadf3f3 | 2024-03-12 18:47:27 | [diff] [blame] | 537 | [//tools/vscode/cpp.json](/tools/vscode/cpp.json), which are already installed |
| 538 | to your workspace at `.vscode/cpp.code-snippets` |
Mounir Lamouri | 3b9e31d | 2019-07-30 20:14:41 | [diff] [blame] | 539 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 540 | ### Tips |
| 541 | |
| 542 | #### The `out` folder |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 543 | |
Tiago Vignatti | 3e5b18bc | 2023-03-30 13:13:46 | [diff] [blame] | 544 | Automatically generated code is put into a subfolder of `out/`, which means that |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 545 | these files are ignored by VS Code (see files.exclude above) and cannot be |
Tiago Vignatti | 3e5b18bc | 2023-03-30 13:13:46 | [diff] [blame] | 546 | opened e.g. from quick-open (`Ctrl+P`). As of version 1.21, VS Code does not |
| 547 | support negated glob commands, but you can define a set of exclude pattern to |
| 548 | include only `out/Debug/gen`: |
Christian Dullweber | babb96e1 | 2018-05-28 14:00:14 | [diff] [blame] | 549 | ``` |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 550 | "files.exclude": { |
| 551 | // Ignore build output folders. Except out/Debug/gen/ |
| 552 | "out/[^D]*/": true, |
| 553 | "out/Debug/[^g]*": true, |
| 554 | "out/Debug/g[^e]*": true, |
| 555 | "out_*/**": true, |
| 556 | }, |
Christian Dullweber | babb96e1 | 2018-05-28 14:00:14 | [diff] [blame] | 557 | ``` |
Christian Dullweber | d67c9b3 | 2018-04-03 08:30:42 | [diff] [blame] | 558 | |
| 559 | Once it does, you can use |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 560 | ``` |
| 561 | "!out/Debug/gen/**": true |
| 562 | ``` |
| 563 | in files.exclude instead of the symlink. |
| 564 | |
| 565 | #### Using VS Code as git editor |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 566 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 567 | Add `[core] editor = "code --wait"` to your `~/.gitconfig` file in order to use |
| 568 | VS Code as editor for git commit messages etc. Note that the editor starts up |
| 569 | significantly slower than nano or vim. To use VS Code as merge tool, add |
| 570 | `[merge] tool = code`. |
| 571 | |
| 572 | #### Task Names |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 573 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 574 | Note that we named the tasks `1-build_chrome_debug`, `2-build_chrome_release` |
| 575 | etc. This allows you to quickly execute tasks by pressing their number: |
| 576 | Press `Ctrl+P` and enter `task <n>`, where `<n>` is the number of the task. You |
| 577 | can also create a keyboard shortcut for running a task. `File > Preferences > |
| 578 | Keyboard Shortcuts` and add `{ "key": "ctrl+r", "command": |
| 579 | "workbench.action.tasks.runTask", "when": "!inDebugMode" }`. Then it's |
| 580 | sufficient to press `Ctrl+R` and enter `<n>`. |
| 581 | |
| 582 | #### Working on Laptop |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 583 | |
Bartek Nowierski | fa835f8c | 2021-02-24 00:36:02 | [diff] [blame] | 584 | You might want to disable git status autorefresh to save battery. |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 585 | |
| 586 | ``` |
chaopeng | 5c66dfe | 2017-03-22 13:51:45 | [diff] [blame] | 587 | "git.autorefresh": false, |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 588 | ``` |
| 589 | |
Tommy Nyquist | dc2ceaa4 | 2021-03-15 20:29:04 | [diff] [blame] | 590 | #### Editing in multiple Git repositories |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 591 | |
Tommy Nyquist | dc2ceaa4 | 2021-03-15 20:29:04 | [diff] [blame] | 592 | If you frequently work in multiple Git repositories that are part of the Chromium repository, you might find that the built-in tooling does not work as expected for files that exist below folders that are part of a `.gitignore` file checked in to Chromium. |
| 593 | |
| 594 | To work around this, you can add the directories you edit as separate `folders` entries in your workspace configuration, and ensure that the directories that are ignored in Chromium are listed **before** the Chromium `src` path. |
| 595 | |
| 596 | To edit this, go to `Settings` -> Select the `Workspace` tab, and choose to open as JSON (button in the top right), and configure `folders` like this (change paths to match your local setup and usage): |
| 597 | |
| 598 | ``` |
| 599 | { |
| 600 | "folders": [ |
| 601 | { |
| 602 | "path": "chromium/src/third_party/perfetto" |
| 603 | }, |
| 604 | { |
| 605 | "path": "chromium/src" |
| 606 | } |
| 607 | ] |
| 608 | } |
| 609 | ``` |
| 610 | |
Jianpeng Chao | b4048b8 | 2018-08-28 23:40:01 | [diff] [blame] | 611 | ### Unable to open $File resource is not available when debugging Chromium on Linux |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 612 | |
Jianpeng Chao | b4048b8 | 2018-08-28 23:40:01 | [diff] [blame] | 613 | Chromium [recently changed](https://docs.google.com/document/d/1OX4jY_bOCeNK7PNjVRuBQE9s6BQKS8XRNWGK8FEyh-E/edit?usp=sharing) |
| 614 | the file path to be relative to the output dir. Check |
| 615 | `gn args out/$dir --list` if `strip_absolute_paths_from_debug_symbols` is true (which is the default), |
Raphael Kubo da Costa | c85b513 | 2022-09-14 18:49:20 | [diff] [blame] | 616 | set `cwd` to the output dir. otherwise, set `cwd` to `${workspaceFolder}`. |
Jianpeng Chao | b4048b8 | 2018-08-28 23:40:01 | [diff] [blame] | 617 | |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 618 | ### More |
Ming-Ying Chung | a7db9dde8 | 2022-07-12 06:31:54 | [diff] [blame] | 619 | |
ljusten | e262c84 | 2017-04-12 08:29:04 | [diff] [blame] | 620 | More tips and tricks can be found |
Ryan Tarpine | 78d07f8 | 2022-11-14 16:19:27 | [diff] [blame] | 621 | [here](https://code.visualstudio.com/docs/getstarted/tips-and-tricks). |