chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 1 | # Use Visual Studio Code on Chromium code base |
| 2 | |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 3 | [TOC] |
| 4 | |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 5 | [Visual Studio Code](http://code.visualstudio.com/) |
| 6 | ([Wikipedia](https://en.wikipedia.org/wiki/Visual_Studio_Code)) is a |
| 7 | multi-platform code editor that is itself based on Electron which is based on |
| 8 | Chromium. Visual Studio Code has a growing community and base of installable |
| 9 | extensions and themes. It works without too much setup. |
| 10 | |
| 11 | ## Install extensions |
| 12 | |
chaopeng | 5c66dfe | 2017-03-22 13:51:45 | [diff] [blame^] | 13 | `F1` paste |
| 14 | `ext install cpptools you-complete-me clang-format chromium-codesearch` |
| 15 | then enter. For more extensions: |
| 16 | https://marketplace.visualstudio.com/search?target=vscode |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 17 | |
| 18 | Highly recommend you also install your favorite keymap. |
| 19 | |
| 20 | An Example to install eclipse keymaps `ext install vscode-eclipse-keybindings`. |
| 21 | You can search keymaps here. |
| 22 | https://marketplace.visualstudio.com/search?target=vscode&category=Keymaps |
| 23 | |
| 24 | |
| 25 | ## Settings |
| 26 | |
| 27 | Open Settings `File/Code - Preferences - Settings` and add the following |
| 28 | settings. |
| 29 | |
| 30 | ``` |
| 31 | { |
| 32 | "editor.tabSize": 2, |
| 33 | "editor.rulers": [80], |
chaopeng | 5c66dfe | 2017-03-22 13:51:45 | [diff] [blame^] | 34 | "[cpp]": { |
| 35 | "editor.quickSuggestions": true |
| 36 | }, |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 37 | // Exclude |
| 38 | "files.exclude": { |
| 39 | "**/.git": true, |
| 40 | "**/.svn": true, |
| 41 | "**/.hg": true, |
| 42 | "**/.DS_Store": true, |
| 43 | "**/out": true |
| 44 | }, |
| 45 | // YCM |
| 46 | "ycmd.path": "<your_ycmd_path>", |
| 47 | "ycmd.global_extra_config": |
| 48 | "<your_chromium_path>/src/tools/vim/chromium.ycm_extra_conf.py", |
| 49 | "ycmd.confirm_extra_conf": false, |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 50 | "ycmd.use_imprecise_get_type": true, |
| 51 | // clang-format |
chaopeng | 6fca2b0 | 2017-03-03 19:10:51 | [diff] [blame] | 52 | "clang-format.executable": "<your_depot_tools>/clang-format", |
| 53 | "clang-format.style": "file" |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 54 | } |
| 55 | ``` |
| 56 | |
| 57 | ### Install auto-completion engine(ycmd) |
| 58 | |
| 59 | ``` |
| 60 | $ git clone https://github.com/Valloric/ycmd.git ~/.ycmd |
| 61 | $ cd ~/.ycmd |
| 62 | $ ./build.py --clang-completer |
| 63 | ``` |
| 64 | |
| 65 | ## Work flow |
| 66 | |
| 67 | 1. `ctrl+p` open file. |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 68 | 2. `ctrl+o` goto symbol. `ctrl+l` goto line. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 69 | 3. <code>ctrl+`</code> toggle terminal. |
chaopeng | 5c66dfe | 2017-03-22 13:51:45 | [diff] [blame^] | 70 | 4. `F1` - `CodeSearchOpen` open current line in code search on chrome. |
| 71 | 5. `F1` - `CodeSearchReferences` open XRef Infomation of current symbol. |
| 72 | 6. Use right click menu call `go to definition` or `peek definition`. |
| 73 | 7. Use right click menu call `find all references`. |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 74 | |
| 75 | ## Tips |
| 76 | |
| 77 | ### On laptop |
| 78 | |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 79 | Because we use ycmd to enable auto completion. We can disable CPP autocomplete |
chaopeng | 5c66dfe | 2017-03-22 13:51:45 | [diff] [blame^] | 80 | and index to save battery. We can also disable git status autorefresh to save |
| 81 | battery. |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 82 | |
| 83 | ``` |
chaopeng | 5c66dfe | 2017-03-22 13:51:45 | [diff] [blame^] | 84 | "git.autorefresh": false, |
chaopeng | ca28511 | 2017-03-02 15:39:04 | [diff] [blame] | 85 | "C_Cpp.autocomplete": "Disabled", |
| 86 | "C_Cpp.addWorkspaceRootToIncludePath": false |
| 87 | ``` |
| 88 | |
| 89 | ### Enable Sublime-like minimap |
| 90 | |
| 91 | ``` |
| 92 | "editor.minimap.enabled": true, |
| 93 | "editor.minimap.renderCharacters": false |
| 94 | ``` |
chaopeng | ba312ce | 2017-02-12 03:38:25 | [diff] [blame] | 95 | |
| 96 | ### More |
| 97 | |
| 98 | https://github.com/Microsoft/vscode-tips-and-tricks/blob/master/README.md |