1.. _vscode_ide:
2
3Visual Studio Code
4##################
5
6`Visual Studio Code`_ (VS Code for short) is a popular cross-platform IDE that supports C projects
7and has a rich set of extensions.
8
9This guide describes the process of setting up VS Code for Zephyr's
10:zephyr:code-sample:`blinky` sample in VS Code.
11
12The instructions have been tested on Linux, but the steps should be the same for macOS and
13Windows, just make sure to adjust the paths if needed.
14
15Get VS Code
16***********
17
18`Download VS Code`_ and install it.
19
20Install the required extensions through the :guilabel:`Extensions` marketplace in the left panel.
21Search for the `C/C++ Extension Pack`_ and install it.
22
23Initialize a new workspace
24**************************
25
26This guide gives details on how to configure the :zephyr:code-sample:`blinky`
27sample application, but the instructions would be similar for any Zephyr project and :ref:`workspace
28layout <west-workspaces>`.
29
30Before you start, make sure you have a working Zephyr development environment, as per the
31instructions in the :ref:`getting_started`.
32
33Open the project in VS Code
34***************************
35
36#. In VS Code, select :menuselection:`File --> Open Folder` from the main menu.
37
38#. Navigate to your Zephyr workspace and select it (i.e. the :file:`zephyrproject` folder in your
39   HOME directory if you have followed the Getting Started instructions).
40
41#. If prompted, enable workspace trust.
42
43Generate compile commands
44*************************
45
46In order to support code navigation and linting capabilities, you must compile your project once to
47generate the :file:`compile_commands.json` file that will provide the C/C++ extension with the
48required information (ex. include paths):
49
50   .. zephyr-app-commands::
51      :zephyr-app: samples/basic/blinky
52      :board: native_sim/native/64
53      :goals: build
54      :compact:
55
56Configure the C/C++ extension
57*****************************
58
59You'll now need to point to the generated :file:`compile_commands.json` file to enable linting and
60code navigation in VS Code.
61
62#. Go to the :menuselection:`File --> Preferences --> Settings` in the VS Code top menu.
63
64#. Search for the parameter :guilabel:`C_Cpp > Default: Compile Commands` and set its value to:
65   ``zephyr/build/compile_commands.json``.
66
67   Linting errors in the code should now be resolved, and you should be able to navigate through the
68   code.
69
70Additional resources
71********************
72
73There are many other extensions that can be useful when working with Zephyr and VS Code. While this
74guide does not cover them yet, you may refer to their documentation to set them up:
75
76Contribution tooling
77====================
78
79- `Checkpatch Extension`_
80- `EditorConfig Extension`_
81
82Documentation languages extensions
83==================================
84
85- `reStructuredText Extension Pack`_
86
87IDE extensions
88==============
89
90- `CMake Extension documentation`_
91- `nRF Kconfig Extension`_
92- `nRF DeviceTree Extension`_
93- `GNU Linker Map files Extension`_
94
95Additional guides
96=================
97
98- `How to Develop Zephyr Apps with a Modern, Visual IDE`_
99
100.. note::
101
102   Please be aware that these extensions might not all have the same level of quality and maintenance.
103
104.. _Visual Studio Code: https://code.visualstudio.com/
105.. _Download VS Code: https://code.visualstudio.com/Download
106.. _VS Code documentation: https://code.visualstudio.com/docs
107.. _C/C++ Extension Pack: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack
108.. _C/C++ Extension documentation: https://code.visualstudio.com/docs/languages/cpp
109.. _CMake Extension documentation: https://code.visualstudio.com/docs/cpp/cmake-linux
110
111.. _Checkpatch Extension: https://marketplace.visualstudio.com/items?itemName=idanp.checkpatch
112.. _EditorConfig Extension: https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
113
114.. _reStructuredText Extension Pack: https://marketplace.visualstudio.com/items?itemName=lextudio.restructuredtext-pack
115
116.. _nRF Kconfig Extension: https://marketplace.visualstudio.com/items?itemName=nordic-semiconductor.nrf-kconfig
117.. _nRF DeviceTree Extension: https://marketplace.visualstudio.com/items?itemName=nordic-semiconductor.nrf-devicetree
118.. _GNU Linker Map files Extension: https://marketplace.visualstudio.com/items?itemName=trond-snekvik.gnu-mapfiles
119
120.. _How to Develop Zephyr Apps with a Modern, Visual IDE: https://github.com/beriberikix/zephyr-vscode-example
121