/linuxkerneldev

Visual Studio Code extension to help find documentation, device tree matching on device driver source code, by compatible strings

Primary LanguageTypeScriptMIT LicenseMIT

Embedded Linux Dev

Symbol autocompletion, function and symbol navigation. Supports C, Kconfig, defconfig, .config and device tree files. Plus some automation to match device tree compatibles and open their respective driver or documentation files.

Requirements

The extension works on Linux systems, also tested on WSL, and uses some packages for its correct operation. Before use you must install the following dependencies on your system:

  • bash
  • universal-ctags

An important detail is to install universal-ctags and not exuberant-ctags to have support to index Kconfig and device tree files.

🧪 Experimental Device Tree Source Engine

A new DTS Engine parser is in testing phase. This does not use ctags and it has a totally different behavior showing hints and lookups just for the included files.

Requirements

The new DTS engine validate and compile the device tree source using the device tree compiler dtc. Before use you must install the following dependencies on your system:

  • device-tree-compiler

Enabling Experimental DTS Engine

To use new DTS Engine add the following to your settings.json:

    "kerneldev.experimental.newDtsEngine": true

Changing this configuration and saving will automatically reload the extension to make effect.

Also make sure to remove the DTS from the ctags.languages. The default configuration is:

    "ctags.languages": [
        "C",
        "C++",
        "DTS",
        "Kconfig",
        "Make"
    ],

The new DTS Engine uses the yaml binding documentation to have completion tips and validation. The extension needs to know a valid path to documentation. If you are opening the root folder from Linux Kernel source code add the following to your settings.json:

    "devicetree.bindings": [
        "${workspaceFolder}/Documentation/devicetree/bindings"
    ],

Features

All features of the extension can be accessed by clicking commands through the activity bar:

In the next topics, I will describe each of the extension features.

Device Tree Doc From Compatible

In a device-tree file, ".dts" or ".dtsi", or in a device driver file ".c", mouse click on a "compatible" string and select the command. VS Code will open the corresponding documentation file for the compatible:

This functionality can also be selected from the right click context menu:

Device Driver From Compatible

In a device-tree file, ".dts" or ".dtsi", mouse click on a "compatible" string and select the command. VS Code will match and open the code file, “.c”, from the driver that implements compatible:

This functionality can also be selected from the right click context menu:

ARM/ARM64 dts/dtsi From Include

In a device-tree file, “.dts” or “.dtsi”, mouse click on the string of a device-tree include and select the command. VS Code will open the corresponding file:

This functionality can also be selected from the right click context menu:

There are two options for this command, one for ARM and other for ARM64, because the devices-tree files for each of these archs are on different paths.

Linux Include From Selected

In ".c", ".dts" or ".dtsi" file, mouse click on an include string and select the command. VS Code will open the corresponding include:

This functionality can also be selected from the right click context menu:

Generate CTags

Last but not least. This functionality generates a “.vscode-ctags” file in the root folder that has been opened. This file is the tag index generated by universal-ctags. This file is required to generate the project code navigation:

  • Jump to definition:

  • Code completion:

  • Mouse hover tags:

Known Issues

You can check and open issues on Github repo

Release Notes

Check the CHANGELOG.md

Acknowledgment

The work here was only possible because of the Exuberant CTags extension, which I used as a base. Thanks Chris Wheeldon.

Thanks also to Trond Einar Snekvik who did a great job in creating a syntax highlighting for Kconfig that I am using here.