diff options
| author | Woongbin Kang <wbk@outlook.com> | 2023-04-02 20:05:48 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-03 10:05:48 +1000 |
| commit | ec83c0b1857b596c4b53186804bf4452831b3241 (patch) | |
| tree | d0642dfb45355806876455589d4cc052acd278b0 /docs/other_vscode.md | |
| parent | d3008110096db2ac098db9b5cb47ad77582c01d9 (diff) | |
Add recommendations for VSCode intellisense (#19402)
Diffstat (limited to 'docs/other_vscode.md')
| -rw-r--r-- | docs/other_vscode.md | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/docs/other_vscode.md b/docs/other_vscode.md index b3fb9948aa..a10002570b 100644 --- a/docs/other_vscode.md +++ b/docs/other_vscode.md | |||
| @@ -46,16 +46,7 @@ Before starting, you will want to make sure that you have all of the build tools | |||
| 46 | 46 | ||
| 47 | This part is super simple. However, there is some configuration that we need to do to ensure things are configured correctly. | 47 | This part is super simple. However, there is some configuration that we need to do to ensure things are configured correctly. |
| 48 | 48 | ||
| 49 | ### Configuring VS Code | 49 | #### MSYS2 Setup |
| 50 | |||
| 51 | First, we need to set up IntelliSense. This isn't strictly required, but it will make your life a LOT easier. To do this, we need to create the `.vscode/c_cpp_properties.json` file in the QMK Firmware folder, You can do this all manually, but I've done most of the work already. | ||
| 52 | |||
| 53 | Grab [this file](https://gist.github.com/drashna/48e2c49ce877be592a1650f91f8473e8) and save it. You may need to edit this file, if you didn't install MSYS2 to the default location, or are using WSL/LxSS. | ||
| 54 | |||
| 55 | Once you have saved this file, you will need to reload VS Code, if it was already running. | ||
| 56 | |||
| 57 | ?> You should see an `extensions.json` and `settings.json` file in the `.vscode` folder, as well. | ||
| 58 | |||
| 59 | 50 | ||
| 60 | Now, we will set up the MSYS2 window to show up in VSCode as the integrated terminal. This has a number of advantages. Mostly, you can control+click on errors and jump to those files. This makes debugging much easier. It's also nice, in that you don't have to jump to another window. | 51 | Now, we will set up the MSYS2 window to show up in VSCode as the integrated terminal. This has a number of advantages. Mostly, you can control+click on errors and jump to those files. This makes debugging much easier. It's also nice, in that you don't have to jump to another window. |
| 61 | 52 | ||
| @@ -110,8 +101,50 @@ This installs a bunch of Git related tools that may make using Git with QMK Firm | |||
| 110 | Restart once you've installed any extensions | 101 | Restart once you've installed any extensions |
| 111 | 102 | ||
| 112 | # Configure VS Code for QMK | 103 | # Configure VS Code for QMK |
| 104 | |||
| 113 | 1. Click <kbd><kbd>File</kbd> > <kbd>Open Folder</kbd></kbd> | 105 | 1. Click <kbd><kbd>File</kbd> > <kbd>Open Folder</kbd></kbd> |
| 114 | 2. Open the QMK Firmware folder that you cloned from GitHub. | 106 | 2. Open the QMK Firmware folder that you cloned from GitHub. |
| 115 | 3. Click <kbd><kbd>File</kbd> > <kbd>Save Workspace As...</kbd></kbd> | 107 | 3. Click <kbd><kbd>File</kbd> > <kbd>Save Workspace As...</kbd></kbd> |
| 116 | 108 | ||
| 109 | ## Configuring VS Code | ||
| 110 | |||
| 111 | Using the [standard `compile_commands.json` database](https://clang.llvm.org/docs/JSONCompilationDatabase.html), we can get VS code C/C++ extension to use the exact same includes and defines used for your keyboard and keymap. | ||
| 112 | |||
| 113 | 1. Run `qmk generate-compilation-database -kb <keyboard> -km <keymap>` to generate the `compile_commands.json`. | ||
| 114 | 1. Create `.vscode/c_cpp_properties.json` with the following content: | ||
| 115 | ``` | ||
| 116 | { | ||
| 117 | "configurations": [ | ||
| 118 | { | ||
| 119 | "name": "qmk", | ||
| 120 | "compilerArgs": ["-mmcu=atmega32u4"], | ||
| 121 | "compilerPath": "/usr/bin/avr-gcc", | ||
| 122 | "cStandard": "gnu11", | ||
| 123 | "cppStandard": "gnu++14", | ||
| 124 | "compileCommands": "${workspaceFolder}/compile_commands.json", | ||
| 125 | "intelliSenseMode": "linux-gcc-arm", | ||
| 126 | "browse": { | ||
| 127 | "path": [ | ||
| 128 | "${workspaceFolder}" | ||
| 129 | ], | ||
| 130 | "limitSymbolsToIncludedHeaders": true, | ||
| 131 | "databaseFilename": "" | ||
| 132 | } | ||
| 133 | } | ||
| 134 | ], | ||
| 135 | "version": 4 | ||
| 136 | } | ||
| 137 | ``` | ||
| 138 | |||
| 139 | Change values in `.vscode/c_cpp_properties.json` for your environment: | ||
| 140 | |||
| 141 | 1. Copy the `-mmcu` argument from `compile_commands.json` into your `compilerArgs`. This is to work around a [bug in vscode c/c++ extension](https://github.com/microsoft/vscode-cpptools/issues/6478). | ||
| 142 | 1. Use the `compilerPath` from `compile_commands.json`. | ||
| 143 | 1. Modify `cStandard`, `cppStandard` and `intelliSenseMode` values to the correct values for your platform. See [this section](https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference#_configuration-properties) for reference. For WSL, it should still be gcc-x64. | ||
| 144 | |||
| 117 | And now you're ready to code QMK Firmware in VS Code | 145 | And now you're ready to code QMK Firmware in VS Code |
| 146 | |||
| 147 | |||
| 148 | ## Troubleshooting VSCode C/C++ extension | ||
| 149 | |||
| 150 | If the defines are not matching what you expect, open the source code and run action `C/C++: Log Diagnostics`. This will list the exact list of defines and include paths defined in `compile_commands.json`, and if it's not part of your compilation database, it will tell you so. \ No newline at end of file | ||
