OLD | NEW |
---|---|
(Empty) | |
1 # Visual Studio Code Dev | |
chaopeng
2017/03/30 14:16:14
Please merge this to docs/vscode.md
| |
2 | |
3 Visual Studio Code is a free, lightweight and powerful code editor for Windows, | |
4 Mac and Linux. It has built-in support for JavaScript, TypeScript and Node.js | |
5 and a rich extension ecosystem that adds intellisense, debugging, syntax | |
6 highlighting etc. for many languages (C++, Python, Go). Get started | |
7 [here](https://code.visualstudio.com/docs). | |
8 | |
9 It is NOT a full-fledged IDE like Visual Studio. The two are completely | |
10 separate products. The only commonality with Visual Studio is that both are | |
11 from Microsoft. | |
12 | |
13 Here's what works well: | |
14 | |
15 * Editing code works well especially when you get used to the [keyboard | |
16 shortcuts](https://code.visualstudio.com/docs/customization/keybindings). | |
17 VS Code is very responsive and can handle even big code bases like Chromium. | |
18 * Git integration is a blast. Built-in side-by-side view, local commit and | |
19 even extensions for | |
20 [history](https://marketplace.visualstudio.com/items?itemName=donjayamanne.g ithistory) | |
21 and | |
22 [blame view](https://marketplace.visualstudio.com/items?itemName=ryu1kn.anno tator). | |
23 * [Debugging](https://code.visualstudio.com/Docs/editor/debugging) works | |
24 well, even though startup times can be fairly high (~40 seconds with | |
25 gdb on Linux, much lower on Windows). You can step through code, inspect | |
26 variables, view call stacks for multiple threads etc. | |
27 * Opening files and searching solution-wide works well now after having | |
28 problems in earlier versions. | |
29 * Building works well. Build tools are easy to integrate. Warnings and errors | |
30 are displayed on a separate page and you can click to jump to the | |
31 corresponding line of code. | |
32 | |
33 [TOC] | |
34 | |
35 ## Updating This Page | |
chaopeng
2017/03/30 14:16:14
nit: Maybe we should not add this section.
ljusten (tachyonic)
2017/03/31 14:02:31
I've added this because I imagine this doc will be
| |
36 | |
37 Please keep this doc up-to-date. VS Code is still in active development and | |
38 subject to changes. This doc is checked into the Chromium git repo, so if you | |
39 make changes, you have to | |
40 [submit a change list](https://www.chromium.org/developers/contributing-code). | |
41 You may skip code review by adding | |
42 ``` | |
43 TBR=<foo>@chromium.org | |
44 ``` | |
45 where <foo> should be a valid comitter (e.g. your supervisor). | |
46 | |
47 All file paths and commands have been tested on Linux. Windows and Mac might | |
48 require a slightly different setup (e.g. `Ctrl` -> `Cmd`). Please update this | |
49 page accordingly. | |
50 | |
51 ## Setup | |
52 | |
53 ### Installation | |
54 | |
55 Follow the steps on https://code.visualstudio.com/docs/setup/setup-overview. | |
56 To run it on Linux, just navigate to the chromium/src folder and type 'code .' | |
57 in a terminal. VS Code does not require project or solution files. However, it | |
58 does store workspace settings in a .vscode folder in your base directory. | |
59 | |
60 ### Useful Extensions | |
61 | |
62 Up to now, you have a basic version of VS Code without much language support. | |
63 Next, we will install some useful extensions. Jump to the extensions window | |
64 (`Ctrl+Shift+X`) and install these extensions, you will most likely use them | |
65 every day: | |
66 | |
chaopeng
2017/03/30 14:16:14
Add a line for developer easier install everything
ljusten (tachyonic)
2017/03/31 14:02:31
Apparently they changed the behavior and ext insta
| |
67 * ***C/C++*** - | |
68 Complete C/C++ language support. | |
69 * ***Python*** - | |
70 Python linting, debugging, intellisense, code formatting etc. | |
71 * ***Toggle Header/Source*** - | |
72 Toggles between .cc and .h with `F4`. The C/C++ extension supports this as | |
73 well `Alt+O`. Last time I checked this was very laggy, but they might have | |
74 improved it since, so this extension might not be necessary. | |
75 * ***Protobuf support*** - | |
76 Syntax highlighting for .proto files. | |
77 * ***Rewrap*** - | |
78 Wrap lines at 80 characters with `Alt+Q`. | |
chaopeng
2017/03/30 14:16:14
1. Add chromium-codesearch
https://marketplace.vis
ljusten (tachyonic)
2017/03/31 14:02:31
Done.
Just noticed you wrote this extension. Nice
| |
79 | |
80 The following extensions might be useful for you as well: | |
81 | |
82 * ***Annotator*** - | |
83 Git blame view. | |
84 * ***Git History (git log)*** - | |
85 Git history view. | |
86 * ***you-complete-me*** - | |
87 YouCompleteMe code completion for VS Code. I've had some luck with it in | |
88 Chromium. Be sure to turn off code completion and suggestions from the C/C++ | |
89 extension. | |
90 * ***change-case*** - | |
91 Quickly change the case of the current selection or current word. | |
92 * ***Instant Markdown*** - | |
93 Markdown (.md) preview in your browser as you type. This document was | |
94 written with this extension! | |
95 | |
96 Also be sure to take a look at the | |
97 [VS Code marketplace](https://marketplace.visualstudio.com/VSCode) to check out other | |
98 useful extensions. | |
99 | |
100 ### Color Scheme | |
101 Press `Ctrl+Shift+P, color, Enter` to pick a color scheme for the editor. There | |
102 are also tons of [color schemes available for download on the | |
103 marketplace](https://marketplace.visualstudio.com/search?target=VSCode&category= Themes&sortBy=Downloads). | |
104 | |
105 ### Usage Tips | |
106 * `Ctrl+P` opens a search box to find and open a file. | |
107 * `Ctrl+Shift+P` opens a search box to find a command (e.g. Tasks: Run Task). | |
108 * `Ctrl+K, Z` enters Zen Mode, a fullscreen editing mode with nothing but the | |
109 current editor visible. | |
110 * `Ctrl+Shift+M` and `Ctrl+~` toggles between problem view (compile | |
111 warnings and errors) and terminal view. This is useful during compilation. | |
112 * `Alt+O` switches between the source/header file. | |
113 * `F12` jumps to a symbol definition. | |
114 * `Ctrl+D` selects the word at the cursor. Pressing it multiple times | |
115 multi-selects the next occurrences, so typing in one types in all of them, | |
116 and `Ctrl+U` deselects the last occurrence. | |
117 * `Ctrl+X` without anything selected cuts the current line. `Ctrl+V` pastes | |
118 the line. | |
119 | |
chaopeng
2017/03/30 14:16:14
ctrl+` toggle terminal.
F1 - CodeSearchOpen open c
ljusten (tachyonic)
2017/03/31 14:02:31
Done.
| |
120 ## Setup For Chromium | |
121 | |
122 VS Code is configured via JSON files. This paragraph contains JSON configuration | |
123 files that are useful for Chromium development, in particular. See [VS Code | |
124 documentation](https://code.visualstudio.com/docs/customization/overview) for an | |
125 introduction to VS Code customization. | |
126 | |
127 ### Workspace Settings | |
128 Open the file chromium/src/.vscode/settings.json and add the following settings: | |
129 | |
130 ``` | |
131 { | |
132 // Default tab size of 2. | |
133 "editor.tabSize": 2, | |
134 // Do not figure out tab size from opening a file. | |
135 "editor.detectIndentation": false, | |
136 // Add a line at 80 characters. | |
137 "editor.rulers": [80], | |
138 // Optional: Highlight current line at the left of the editor. | |
139 "editor.renderLineHighlight": "gutter", | |
140 // Optional: Don't automatically add closing brackets. It gets in the way. | |
141 "editor.autoClosingBrackets": false, | |
142 // Optional: Enable a tiny 30k feet view of your doc. | |
143 "editor.minimap.enabled": true, | |
144 "editor.minimap.maxColumn": 80, | |
chaopeng
2017/03/30 14:16:14
"editor.minimap.renderCharacters": false
This one
ljusten (tachyonic)
2017/03/31 14:02:31
I agree.
| |
145 // Trim tailing whitespace on save. | |
146 "files.trimTrailingWhitespace": true, | |
147 // Optional: Do not open files in 'preview' mode. Opening a new file in can | |
148 // replace an existing one in preview mode, which can be confusing. | |
149 "workbench.editor.enablePreview": false, | |
150 // Optional: Same for files opened from quick open (Ctrl+P). | |
151 "workbench.editor.enablePreviewFromQuickOpen": false, | |
152 | |
153 "files.associations": { | |
154 // Adds xml syntax highlighting for grd files. | |
155 "*.grd" : "xml", | |
156 // Optional: .gn and .gni are not JavaScript, but at least it gives some | |
157 // approximate syntax highlighting. Ignore the linter warnings! | |
158 "*.gni" : "javascript", | |
159 "*.gn" : "javascript" | |
160 }, | |
161 | |
162 "files.exclude": { | |
163 // Ignore build output folders. | |
164 "out*/**": true | |
165 }, | |
166 | |
167 // Wider author column for annotator extension. | |
168 "annotator.annotationColumnWidth": "24em", | |
169 | |
chaopeng
2017/03/30 14:16:14
Do you forget YCM settings here? Also please add h
ljusten (tachyonic)
2017/03/31 14:02:31
Added. How does use_imprecise_get_type work:true o
ljusten (tachyonic)
2017/03/31 14:02:31
Done.
chaopeng
2017/03/31 14:42:19
No, I dont install ycm in vim.
| |
170 // C++ clang format settings. | |
chaopeng
2017/03/30 14:16:14
Please look at Nico's comment for clang-format
htt
ljusten (tachyonic)
2017/03/31 14:02:31
Done.
| |
171 "C_Cpp.clang_format_path": "clang-format", | |
172 "C_Cpp.clang_format_style": "Chromium", | |
173 "C_Cpp.clang_format_fallbackStyle": "Visual Studio", | |
174 "C_Cpp.clang_format_sortIncludes": true, | |
175 "C_Cpp.clang_format_formatOnSave": true, | |
176 } | |
177 ``` | |
178 | |
179 ### Tasks | |
180 Next, we'll tell VS Code how to compile our code and how to read warnings and | |
181 errors from the build output. Copy the code below to | |
182 chromium/src/.vscode/tasks.json. This will provide 5 tasks to do basic things. | |
183 You might have to adjust the commands to your situation and needs. | |
184 | |
185 ``` | |
186 { | |
187 "version": "0.1.0", | |
188 "_runner": "terminal", | |
189 "showOutput": "always", | |
190 "echoCommand": true, | |
191 "tasks": [ | |
192 { | |
193 "taskName": "1-build_chrome_debug", | |
194 "command": "ninja -C out/Debug -j 2000 chrome", | |
195 "isShellCommand": true, | |
196 "isTestCommand": true, | |
197 "problemMatcher": { | |
198 "owner": "cpp", | |
199 "fileLocation": ["relative", "${workspaceRoot}"], | |
200 "pattern": { | |
201 "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.* )$", | |
202 "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 | |
203 } | |
204 } | |
205 }, | |
206 { | |
207 "taskName": "2-build_chrome_release", | |
208 "command": "ninja -C out/Release -j 2000 chrome", | |
209 "isShellCommand": true, | |
210 "isBuildCommand": true, | |
211 "problemMatcher": { | |
212 "owner": "cpp", | |
213 "fileLocation": ["relative", "${workspaceRoot}"], | |
214 "pattern": { | |
215 "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.* )$", | |
216 "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 | |
217 } | |
218 } | |
219 }, | |
220 { | |
221 "taskName": "3-build_all_debug", | |
222 "command": "ninja -C out/Debug -j 2000", | |
223 "isShellCommand": true, | |
224 "problemMatcher": { | |
225 "owner": "cpp", | |
226 "fileLocation": ["relative", "${workspaceRoot}"], | |
227 "pattern": { | |
228 "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.* )$", | |
229 "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 | |
230 } | |
231 } | |
232 }, | |
233 { | |
234 "taskName": "4-build_all_release", | |
235 "command": "ninja -C out/Release -j 2000", | |
236 "isShellCommand": true, | |
237 "problemMatcher": { | |
238 "owner": "cpp", | |
239 "fileLocation": ["relative", "${workspaceRoot}"], | |
240 "pattern": { | |
241 "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.* )$", | |
242 "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 | |
243 } | |
244 } | |
245 }, | |
246 { | |
247 "taskName": "5-build_test_debug", | |
248 "command": "ninja -C out/Debug -j 2000 unit_tests components_unittests brows er_tests", | |
249 "isShellCommand": true, | |
250 "problemMatcher": { | |
251 "owner": "cpp", | |
252 "fileLocation": ["relative", "${workspaceRoot}"], | |
253 "pattern": { | |
254 "regexp": "^../../(.*):(\\d+):(\\d+):\\s+(warning|\\w*\\s?error):\\s+(.* )$", | |
255 "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 | |
256 } | |
257 } | |
258 }] | |
259 } | |
260 ``` | |
261 | |
262 ### Launch Commands | |
263 Launch commands are the equivalent of `F5` in Visual Studio: They launch some | |
264 program or a debugger. Optionally, they can run some task defined in | |
265 `tasks.json`. Launch commands can be run from the debug view (`Ctrl+Shift+D`). | |
266 Copy the code below to chromium/src/.vscode/launch.json and adjust them to | |
267 your situation and needs. | |
268 ``` | |
269 { | |
270 "version": "0.2.0", | |
271 "configurations": [ | |
272 { | |
273 "name": "Chrome Debug", | |
274 "type": "cppdbg", | |
275 "request": "launch", | |
276 "targetArchitecture": "x64", | |
277 "program": "${workspaceRoot}/out/Debug/chrome", | |
278 "args": [], // Optional command line args | |
279 "preLaunchTask": "1-build_chrome_debug", | |
280 "stopAtEntry": false, | |
281 "cwd": "${workspaceRoot}", | |
282 "environment": [], | |
283 "externalConsole": true | |
284 }, | |
285 { | |
286 "name": "Chrome Release", | |
287 "type": "cppdbg", | |
288 "request": "launch", | |
289 "targetArchitecture": "x64", | |
290 "program": "${workspaceRoot}/out/Release/chrome", | |
291 "args": [], // Optional command line args | |
292 "preLaunchTask": "2-build_chrome_release", | |
293 "stopAtEntry": false, | |
294 "cwd": "${workspaceRoot}", | |
295 "environment": [], | |
296 "externalConsole": true | |
297 }, | |
298 { | |
299 "name": "Custom Test Debug", | |
300 "type": "cppdbg", | |
301 "request": "launch", | |
302 "targetArchitecture": "x64", | |
303 "program": "${workspaceRoot}/out/Debug/unit_tests", | |
304 "args": ["--gtest_filter=*", | |
305 "--single_process", | |
306 "--ui-test-action-max-timeout=1000000", | |
307 "--test-launcher-timeout=1000000"], | |
308 "preLaunchTask": "5-build_test_debug", | |
309 "stopAtEntry": false, | |
310 "cwd": "${workspaceRoot}", | |
311 "environment": [], | |
312 "externalConsole": true | |
313 }, | |
314 { | |
315 "name": "Attach Debug", | |
316 "type": "cppdbg", | |
317 "request": "launch", | |
318 "targetArchitecture": "x64", | |
319 "program": "${workspaceRoot}/out/Debug/chrome", | |
320 "args": ["--remote-debugging-port=2224"], | |
321 "stopAtEntry": false, | |
322 "cwd": "${workspaceRoot}", | |
323 "environment": [], | |
324 "externalConsole": false | |
325 }] | |
326 } | |
327 ``` | |
328 | |
329 ### Key Bindings | |
330 To edit key bindings, press `Ctrl+K, Ctrl+S`. You'll see the defaults on the | |
331 left and your overrides on the right. To change a key binding, copy the | |
332 corresponding command to the right. It's fairly self-explanatory. As everything, | |
333 key bindings are stored in a `keybindings.json` file. Here are some key bindings | |
334 that are likely to be useful for you: | |
335 | |
336 ``` | |
337 // Place your key bindings in this file to overwrite the defaults | |
338 [ | |
339 // Run the task marked as "isTestCommand": true, see tasks.json. | |
340 { "key": "ctrl+shift+t", "command": "workbench.action.tasks.test" }, | |
341 // Jump to the previous change in the built-in diff tool. | |
342 { "key": "ctrl+up", "command": "workbench.action.compareEditor.previo usChange" }, | |
343 // Jump to the next change in the built-in diff tool. | |
344 { "key": "ctrl+down", "command": "workbench.action.compareEditor.nextCh ange" }, | |
345 // Jump to previous location in the editor (useful to get back from viewing a sy mbol definition). | |
346 { "key": "alt+left", "command": "workbench.action.navigateBack" }, | |
347 // Jump to next location in the editor. | |
348 { "key": "alt+right", "command": "workbench.action.navigateForward" }, | |
349 // Get a blame view of the current file. Requires the annotator extension. | |
350 { "key": "ctrl+alt+a", "command": "annotator.annotate" }, | |
351 // Toggle header/source with the Toggle Header/Source extension (overrides the | |
352 // key binding from the C/C++ extension as I found it to be slow). | |
353 { "key": "alt+o", "command": "togglehs.toggleHS" }, | |
354 // Quickly run a task, see tasks.json. Since we named them 1-, 2- etc., it is | |
355 // suffucient to press the corresponding number. | |
356 { "key": "ctrl+r", "command": "workbench.action.tasks.runTask", | |
357 "when": "!inDebugMode" }, | |
358 // The following keybindings are useful on laptops with small keyboards such as | |
359 // Chromebooks that don't provide all keys. | |
360 { "key": "shift+alt+down", "command": "cursorColumnSelectDown", | |
361 "when": "editorTextFocus" }, | |
362 { "key": "shift+alt+left", "command": "cursorColumnSelectLeft", | |
363 "when": "editorTextFocus" }, | |
364 { "key": "shift+alt+pagedown", "command": "cursorColumnSelectPageDown", | |
365 "when": "editorTextFocus" }, | |
366 { "key": "shift+alt+pageup", "command": "cursorColumnSelectPageUp", | |
367 "when": "editorTextFocus" }, | |
368 { "key": "shift+alt+right", "command": "cursorColumnSelectRight", | |
369 "when": "editorTextFocus" }, | |
370 { "key": "shift+alt+up", "command": "cursorColumnSelectUp", | |
371 "when": "editorTextFocus" }, | |
372 { "key": "alt+down", "command": "scrollPageDown", | |
373 "when": "editorTextFocus" }, | |
374 { "key": "alt+up", "command": "scrollPageUp", | |
375 "when": "editorTextFocus" }, | |
376 { "key": "alt+backspace", "command": "deleteRight", | |
377 "when": "editorTextFocus && !editorReadonly" } , | |
378 { "key": "ctrl+right", "command": "cursorEnd", | |
379 "when": "editorTextFocus" }, | |
380 { "key": "ctrl+shift+right", "command": "cursorEndSelect", | |
381 "when": "editorTextFocus" }, | |
382 { "key": "ctrl+left", "command": "cursorHome", | |
383 "when": "editorTextFocus" }, | |
384 { "key": "ctrl+shift+left", "command": "cursorHomeSelect", | |
385 "when": "editorTextFocus" }, | |
386 ] | |
387 ``` | |
388 | |
389 ### Tips | |
390 | |
chaopeng
2017/03/30 14:16:14
Please add my battery saving settings here:
https:
ljusten (tachyonic)
2017/03/31 14:02:31
Done.
| |
391 #### The `out` folder | |
392 Automatically generated code is put into a subfolder of out/, which means that | |
393 these files are ignored by VS Code (see files.exclude above) and cannot be | |
394 opened e.g. from quick-open (`Ctrl+P`). On Linux, you can create a symlink as a | |
395 work-around: | |
396 ``` | |
397 cd ~/chromium/src | |
398 mkdir _out | |
399 ln -s ../out/Debug/gen _out/gen | |
400 ``` | |
401 We picked _out since it is already in .gitignore, so it won't show up in git | |
402 status. | |
403 | |
404 Note: As of version 1.9, VS Code does not support negated glob commands, but | |
405 once it does, you can use | |
406 ``` | |
407 "!out/Debug/gen/**": true | |
408 ``` | |
409 in files.exclude instead of the symlink. | |
410 | |
411 #### Using VS Code as git editor | |
412 Add `[core] editor = "code --wait"` to your `~/.gitignore` file in order to use | |
413 VS Code as editor for git commit messages etc. Note that the editor starts up | |
414 significantly slower than nano or vim. | |
415 | |
chaopeng
2017/03/30 14:16:14
vscode can also be the difftool/mergetool. If you
ljusten (tachyonic)
2017/03/31 14:02:31
Done.
| |
416 #### Task Names | |
417 Note that we named the tasks `1-build_chrome_debug`, `2-build_chrome_release` | |
418 etc. This allows you to quickly execute tasks by pressing their number: | |
419 Press `Ctrl+P` and enter `task <n>`, where `<n>` is the number of the task. You | |
420 can also create a keyboard shortcut for running a task. `File > Preferences > | |
421 Keyboard Shortcuts` and add `{ "key": "ctrl+r", "command": | |
422 "workbench.action.tasks.runTask", "when": "!inDebugMode" }`. Then it's | |
423 sufficient to press `Ctrl+R` and enter `<n>`. | |
OLD | NEW |