From 86c38f6ecf30cc2187ce5cab48917284a5136ce2 Mon Sep 17 00:00:00 2001 From: Andreas Tsouchlos Date: Mon, 14 Apr 2025 15:48:26 +0200 Subject: [PATCH] Add nvim-local-config-docker.md --- config/nvim-local-config-docker.md | 213 +++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 config/nvim-local-config-docker.md diff --git a/config/nvim-local-config-docker.md b/config/nvim-local-config-docker.md new file mode 100644 index 0000000..1c47c2c --- /dev/null +++ b/config/nvim-local-config-docker.md @@ -0,0 +1,213 @@ +Neovim has the [exrc option](https://neovim.io/doc/user/options.html#'exrc'), +which enables project-local configuration. + +First, the option hast to be enabled in the neovim config. + +```lua +vim.opt.exrc = true +``` + +Upon starting neovim in a directory, any code in `./nvim.lua`, will be aplied +as a local configuration after the global one. + +As an example, consider the following configuration, which + +- modifies the LSP settings for `clangd` to run in a docker container +- adds overseer templates to generate, build and flash a project using docker + +```lua +-- The user and group ids for the docker container can be found using `id -u` and `stat -c %g /dev/ttyACM0` +-- +-- +-- Set up LSP to run in docker container +-- +-- +local lspconfig = require('lspconfig') + +for _, client in pairs(vim.lsp.get_clients({ + name = "clangd" +})) do vim.lsp.stop_client(client.id) end + +lspconfig.clangd.setup({ + cmd = { + "docker", + "run", + "--rm", + "-v", + "/home/andreas/workspace/work/kinemic/toolassist-fw-new:/home/andreas/workspace/work/kinemic/toolassist-fw-new", + "-i", + "-u", + "1000:1001", + "toolassist", + "clangd-18", + "--background-index", + "--clang-tidy", + "--completion-style=bundled", + "--cross-file-rename", + "--header-insertion=iwyu", + "--query-driver=/**/*g++", + "--offset-encoding=utf-16" + } +}) + +-- +-- +-- Set up Overseer actions to run in docker containers +-- +-- + +local overseer = require("overseer") + +overseer.register_template({ + name = "Flash (Docker)", + builder = function() + local file = vim.fn.expand("%:p") + return { + cmd = { + "docker" + }, + args = { + "run", + "--rm", + "-v", + "/home/andreas/workspace/work/kinemic/toolassist-fw-new:/home/andreas/workspace/work/kinemic/toolassist-fw-new", + "-w", + "/home/andreas/workspace/work/kinemic/toolassist-fw-new", + "-i", + "-u", + "1000:1001", + "--device=/dev/ttyACM0", + -- "--device=/dev/ttyUSB0", + "toolassist", + "idf.py", + "flash" + }, + components = { + { + "on_output_quickfix" + }, + "default" + } + } + end, + condition = { + filetype = { + "cmake", + "cpp" + } + }, + priority = 1 +}) + +overseer.register_template({ + name = "CMake Generate (Docker)", + params = { + build_type = { + type = "enum", + choices = { + "Debug", + "Release", + "RelWithDebInfo", + "MinSizeRel" + }, + default = "Release" + }, + generator = { + type = "enum", + choices = { + "Ninja", + "Unix Makefiles" + }, + default = "Ninja" + }, + compiler = { + type = "enum", + choices = { + "g++", + "clang++" + }, + default = "g++" + } + }, + builder = function(params) + return { + cmd = { + "docker" + }, + args = { + "run", + "--rm", + "-v", + "/home/andreas/workspace/work/kinemic/toolassist-fw-new:/home/andreas/workspace/work/kinemic/toolassist-fw-new", + "-w", + "/home/andreas/workspace/work/kinemic/toolassist-fw-new", + "-i", + "-u", + "1000:1001", + "toolassist", + "cmake", + "-B", + "build", + "-S", + ".", + "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", + "-DCMAKE_BUILD_TYPE=" .. params.build_type, + "-DCMAKE_CXX_COMPILER=" .. params.compiler, + "-G", + params.generator + }, + components = { + "default" + } + } + end, + condition = { + filetype = { + "cmake", + "cpp" + } + }, + priority = 1 +}) + +overseer.register_template({ + name = "CMake Build (Docker)", + builder = function() + local file = vim.fn.expand("%:p") + return { + cmd = { + "docker" + }, + args = { + "run", + "--rm", + "-v", + "/home/andreas/workspace/work/kinemic/toolassist-fw-new:/home/andreas/workspace/work/kinemic/toolassist-fw-new", + "-w", + "/home/andreas/workspace/work/kinemic/toolassist-fw-new", + "-i", + "-u", + "1000:1001", + "toolassist", + "cmake", + "--build", + "build", + "-j16" + }, + components = { + { + "on_output_quickfix" + }, + "default" + } + } + end, + condition = { + filetype = { + "cmake", + "cpp" + } + }, + priority = 1 +}) +```