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). You may do it from VS Code embedded terminal; select
49:menuselection:`Terminal --> New Terminal` from the top menu or the command palette
50(:kbd:`Ctrl+Shift+P`), then type:
51
52.. code-block:: console
53
54   $ cd zephyr
55   $ west build -p always -b native_sim/native/64
56
57
58Configure the C/C++ extension
59*****************************
60
61You'll now need to point to the generated :file:`compile_commands.json` file to enable linting and
62code navigation in VS Code.
63
64#. Go to the :menuselection:`File --> Preferences --> Settings` in the VS Code top menu.
65
66#. Search for the parameter :guilabel:`C_Cpp > Default: Compile Commands` and set its value to:
67   ``zephyr/build/compile_commands.json``.
68
69   Linting errors in the code should now be resolved, and you should be able to navigate through the
70   code.
71
72Additional resources
73********************
74
75There are many other extensions that can be useful when working with Zephyr and VS Code. While this
76guide does not cover them yet, you may refer to their documentation to set them up:
77
78Contribution tooling
79====================
80
81- `Checkpatch Extension`_
82- `EditorConfig Extension`_
83
84Documentation languages extensions
85==================================
86
87- `reStructuredText Extension Pack`_
88
89IDE extensions
90==============
91
92- `CMake Extension documentation`_
93- `nRF Kconfig Extension`_
94- `nRF DeviceTree Extension`_
95- `GNU Linker Map files Extension`_
96
97Additional guides
98=================
99
100- `How to Develop Zephyr Apps with a Modern, Visual IDE`_
101
102.. note::
103
104   Please be aware that these extensions might not all have the same level of quality and maintenance.
105
106.. _Visual Studio Code: https://code.visualstudio.com/
107.. _Download VS Code: https://code.visualstudio.com/Download
108.. _VS Code documentation: https://code.visualstudio.com/docs
109.. _C/C++ Extension Pack: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack
110.. _C/C++ Extension documentation: https://code.visualstudio.com/docs/languages/cpp
111.. _CMake Extension documentation: https://code.visualstudio.com/docs/cpp/cmake-linux
112
113.. _Checkpatch Extension: https://marketplace.visualstudio.com/items?itemName=idanp.checkpatch
114.. _EditorConfig Extension: https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
115
116.. _reStructuredText Extension Pack: https://marketplace.visualstudio.com/items?itemName=lextudio.restructuredtext-pack
117
118.. _nRF Kconfig Extension: https://marketplace.visualstudio.com/items?itemName=nordic-semiconductor.nrf-kconfig
119.. _nRF DeviceTree Extension: https://marketplace.visualstudio.com/items?itemName=nordic-semiconductor.nrf-devicetree
120.. _GNU Linker Map files Extension: https://marketplace.visualstudio.com/items?itemName=trond-snekvik.gnu-mapfiles
121
122.. _How to Develop Zephyr Apps with a Modern, Visual IDE: https://github.com/beriberikix/zephyr-vscode-example
123