develop/tools/vscode.html · develop/tools/vscode.rst 공식 원문 ↗

Zephyr 3.7.0 · Develop · Tools · Visual Studio Code

Visual Studio Code

Zephyr build가 만든 compile_commands.json으로 linting과 code navigation을 활성화합니다.

Official pathdevelop/tools/vscode.html
Source filedevelop/tools/vscode.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

VS Code와 C/C++ Extension Pack 설치, workspace trust, Blinky build, compile_commands.json 설정과 Zephyr 관련 extension 자료를 설명합니다.

Extension

C/C++ Pack

Database

compile_commands.json

Features

lint · navigation

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 3B57E00C250CAE2DA0BD118054BD499C39F7D6EF6EF39077E7B6B8FE71550549
.. _vscode_ide:

Visual Studio Code
##################

`Visual Studio Code`_ (VS Code for short) is a popular cross-platform IDE that supports C projects
and has a rich set of extensions.

This guide describes the process of setting up VS Code for Zephyr's
:zephyr:code-sample:`blinky` sample in VS Code.

The instructions have been tested on Linux, but the steps should be the same for macOS and
Windows, just make sure to adjust the paths if needed.

Get VS Code
***********

`Download VS Code`_ and install it.

Install the required extensions through the `Extensions` marketplace in the left panel.
Search for the `C/C++ Extension Pack`_ and install it.

Initialize a new workspace
**************************

This guide gives details on how to configure the :zephyr:code-sample:`blinky`
sample application, but the instructions would be similar for any Zephyr project and :ref:`workspace
layout <west-workspaces>`.

Before you start, make sure you have a working Zephyr development environment, as per the
instructions in the :ref:`getting_started`.

Open the project in VS Code
***************************

#. In VS Code, select :menuselection:`File --> Open Folder` from the main menu.

#. Navigate to your Zephyr workspace and select it (i.e. the :file:`zephyrproject` folder in your
   HOME directory if you have followed the Getting Started instructions).

#. If prompted, enable workspace trust.

Generate compile commands
*************************

In order to support code navigation and linting capabilities, you must compile your project once to
generate the :file:`compile_commands.json` file that will provide the C/C++ extension with the
required information (ex. include paths):

   .. zephyr-app-commands::
      :zephyr-app: samples/basic/blinky
      :board: native_sim/native/64
      :goals: build
      :compact:

Configure the C/C++ extension
*****************************

You'll now need to point to the generated :file:`compile_commands.json` file to enable linting and
code navigation in VS Code.

#. Go to the :menuselection:`File --> Preferences --> Settings` in the VS Code top menu.

#. Search for the parameter :guilabel:`C_Cpp > Default: Compile Commands` and set its value to:
   ``zephyr/build/compile_commands.json``.

   Linting errors in the code should now be resolved, and you should be able to navigate through the
   code.

Additional resources
********************

There are many other extensions that can be useful when working with Zephyr and VS Code. While this
guide does not cover them yet, you may refer to their documentation to set them up:

Contribution tooling
====================

- `Checkpatch Extension`_
- `EditorConfig Extension`_

Documentation languages extensions
==================================

- `reStructuredText Extension Pack`_

IDE extensions
==============

- `CMake Extension documentation`_
- `nRF Kconfig Extension`_
- `nRF DeviceTree Extension`_
- `GNU Linker Map files Extension`_

Additional guides
=================

- `How to Develop Zephyr Apps with a Modern, Visual IDE`_

.. note::

   Please be aware that these extensions might not all have the same level of quality and maintenance.

.. _Visual Studio Code: https://code.visualstudio.com/
.. _Download VS Code: https://code.visualstudio.com/Download
.. _VS Code documentation: https://code.visualstudio.com/docs
.. _C/C++ Extension Pack: https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack
.. _C/C++ Extension documentation: https://code.visualstudio.com/docs/languages/cpp
.. _CMake Extension documentation: https://code.visualstudio.com/docs/cpp/cmake-linux

.. _Checkpatch Extension: https://marketplace.visualstudio.com/items?itemName=idanp.checkpatch
.. _EditorConfig Extension: https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig

.. _reStructuredText Extension Pack: https://marketplace.visualstudio.com/items?itemName=lextudio.restructuredtext-pack

.. _nRF Kconfig Extension: https://marketplace.visualstudio.com/items?itemName=nordic-semiconductor.nrf-kconfig
.. _nRF DeviceTree Extension: https://marketplace.visualstudio.com/items?itemName=nordic-semiconductor.nrf-devicetree
.. _GNU Linker Map files Extension: https://marketplace.visualstudio.com/items?itemName=trond-snekvik.gnu-mapfiles

.. _How to Develop Zephyr Apps with a Modern, Visual IDE: https://github.com/beriberikix/zephyr-vscode-example

Part 3

한국어 전문 번역

Visual Studio Code

Visual Studio Code(VS Code)는 C project를 지원하고 extension 생태계가 풍부한 cross-platform IDE입니다.

이 안내는 Zephyr Blinky sample을 VS Code에서 설정하는 과정을 설명합니다. Linux에서 검증됐지만 필요한 path를 조정하면 macOS와 Windows도 같은 절차를 사용할 수 있습니다.

VS Code 받기

VS Code download에서 설치한 뒤 왼쪽 Extensions marketplace를 엽니다. C/C++ Extension Pack을 검색해 설치합니다.

새 workspace 초기화

예시는 Blinky지만 다른 Zephyr project와 West workspace layout에도 비슷하게 적용됩니다. 먼저 Getting Started에 따라 Zephyr 개발 환경이 동작하는지 확인합니다.

VS Code에서 project 열기

  1. Main menu에서 File → Open Folder를 선택합니다.
  2. zephyrproject 같은 Zephyr workspace로 이동해 folder를 선택합니다.
  3. 확인창이 나오면 workspace trust를 활성화합니다.

Compile command 생성

compile_commands.json은 C/C++ extension에 include path와 compile option을 제공해 code navigation과 linting을 가능하게 합니다. 이 file을 만들려면 project를 한 번 build합니다.

west build -b native_sim/native/64 samples/basic/blinky

C/C++ extension 구성

  1. VS Code top menu에서 File → Preferences → Settings로 이동합니다.
  2. C_Cpp > Default: Compile Commands를 검색해 zephyr/build/compile_commands.json으로 설정합니다.

설정 후 code의 lint error가 해소되고 symbol definition과 declaration 사이를 탐색할 수 있어야 합니다.

추가 자료

Zephyr와 VS Code 작업에 도움이 될 수 있는 extension과 guide입니다.

Contribution 도구

Documentation language extension

IDE extension

추가 guide

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.