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