Skip to content

alex-schulster/stm_lsp_nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🤖 STM LSP

Patch clangd LSP for STM32CubeIDE projects. Say goodbye to unresolved includes and unknown types in your embedded projects.

Screen.Recording.2023-04-11.at.22.08.19.mov

✨ Features

  • Patch STM projects in a single command
  • Get fully working LSP for projects generated on STM32CubeIDE
  • Works with clangd

⚡️ Requirements

  • make
  • compiledb (install via pip)
  • Only works on Linux and macOS for now

📦 Installation

Can be installed with any package manager.

-- Surround feature
{
    "my_account/my_repo",
    config = function()
        require("stm_lsp_nvim").setup({
        -- Custom configuration, or leave empty for default config
        })
    end
},
-- Lua
use {
  "my_account/my_repo",
  config = function()
    require("stm_lsp_nvim").setup {
        -- Custom configuration, or leave empty for default config
    }
  end
}

⚙️ Configuration

The plugin comes with the following default config:

local defaults = {
    input_path = "Debug/compile_commands.json", -- Path to input file
    output_path = "build/compile_commands.json", -- Path to ouput file
    excludes = { -- List of patterns to exclude from file
        "fcyclomatic",
    },
}

🚀 Usage

Just launch neovim in a STM project root directory and run the :StmLspPatch command, and voilà, your clangd LSP should now be able to find all the header files, types and functions definitions, etc.

🤔 Under the hood

The way this plugin works is quite simple. STM projects use Makefile to indicate the compiler, the arguments, and most importantly, all the include paths to header files.

clangd cannot use the Makefile directly to resolve includes, and need a special JSON file named compile_commands.json which holds all the information held by the Makefile.

A Makefile does not generate such a file on its own (contrary to CMake). So to generate one, we use the wonderful compiledb python package.

Once the file is generated, we need to get rid of a few lines to avoid LSP complaints. STM uses a modified version of arm-none-eabi-gcc with custom arguments, such as -fcyclomatic-complexity. This option is of course not recognised by clangd which throws an error. We therefore filter all the lines containing it.

Finally, clangd only looks for the compile_commands.json files in precise locations. This is why we place the modified version in the build/ subdirectory (not used by STM32CubeIDE).

🛠️ Issues and contribution

This is my first public (and, hopefully, useful) repo on GitHub, and also my first time writing a plugin for Neovim. So you may have some issues trying to use it, or find gross mistakes in the code.

  • If you have a problem installing / using the plugin, don't hesitate to open a GitHub issue. I will do my best to help you.
  • If you have an idea on how to improve the plugin or can think of a way to optimise / correct it, please feel free to open a pull request.

About

Get clangd to work with STM32CubeIDE generated projects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published