Files
dotfiles/nvim/lua/plugins/project-run.lua
Timo 2ea7d6457f nvim: fix startup errors, add language + project-run support
Startup errors:
- catppuccin: the bufferline integration moved to catppuccin.special.bufferline
- lspconfig-extended: drop the removed LazyVim keymaps API for
  opts.servers["*"].keys, and move remove-workspace-folder to <leader>clR
  so it stops colliding with LspRestart on <leader>clr
- options: lazyvim_cmp = "blink" is not a valid value, it is "blink.cmp"

Language support (python, c/cpp, rust, zephyr, and the common ones) via
lazyvim.json extras: dap.core, clangd, cmake, docker, git, json, rust,
toml, yaml.

- lang/zephyr.lua: gated entirely on ZEPHYR_BASE / ZEPHYR_SDK_INSTALL_DIR /
  GNUARMEMB_TOOLCHAIN_PATH, returning {} when none are set, so it is inert
  on machines without Zephyr. Nothing is hardcoded: the clangd
  --query-driver globs are built from those vars, falling back to resolving
  the cross-gcc through exepath()+fs_realpath(). Adds devicetree/kconfig
  treesitter and filetypes (*.overlay, Kconfig.*, prj.conf, *_defconfig).
- clangd/config.yaml: strip the GCC-only flags Zephyr emits into
  compile_commands.json (-fno-printf-return-value, -mfp16-format=*, ...),
  which clang rejects as "Unknown argument". Remove only drops flags that
  are present, so it is a no-op for native builds. Takes a built Zephyr app
  from 15 diagnostics to 0, with CONFIG_* resolving into the generated
  autoconf.h.
- npm-servers.lua: npm is not installed here, so yaml/docker servers failed
  to install on every startup and to spawn on every matching file. Sets
  both enabled = false and mason = false for servers whose binary is
  missing from PATH and from mason/bin.

Project runner under <leader>R (<leader>r is refactoring), dispatching on
the detected project type -- zephyr, rust, python, cmake, make:

  Rr run project   Rb build   Rt test   RF build+flash   Rf run file
  Rk configure     Rc clean   Rs select target/board     Ri info

Zephyr boards are picked with vim.ui.select over `west boards`, cached per
scan and persisted per project root under stdpath("state"), never written
into the project. A build with no board set prompts first, then proceeds.
Detection walks up from the last real file buffer, tracked by an autocmd,
because a terminal opened by one of these verbs would otherwise become the
buffer detection ran from.

Also <leader>b1..b9/b0 jump to buffer N (ordinal, no longer skipping the
current one) and <leader>b<Left>/<Right> cycle.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01StGBghPW9Dm7z7uj2VNWHr
2026-09-04 15:22:14 +02:00

56 lines
1.9 KiB
Lua

-- Keymaps for the language-aware project runner in lua/util/project.lua.
--
-- <leader>r is already the refactoring group, so the run/project verbs live
-- under <leader>R. Each verb dispatches on the detected project type, so the
-- same key does the right thing in a Rust crate, a Python package or a Zephyr
-- application.
local function p(fn)
return function()
require("util.project")[fn]()
end
end
return {
{
"folke/snacks.nvim",
-- Remember the last real file buffer, so the run verbs still know which
-- project you are in after one of them has opened a terminal (at which
-- point the focused buffer is the terminal, not your code).
init = function()
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
group = vim.api.nvim_create_augroup("project_run_last_file", { clear = true }),
callback = function(ev)
if vim.bo[ev.buf].buftype == "" then
local name = vim.api.nvim_buf_get_name(ev.buf)
if name ~= "" then
vim.g.project_last_file = name
end
end
end,
})
end,
-- stylua: ignore
keys = {
{ "<leader>R", "", desc = "+run/project" },
{ "<leader>Rr", p("run"), desc = "Run project" },
{ "<leader>Rf", p("run_file"), desc = "Run current file" },
{ "<leader>Rb", p("build"), desc = "Build" },
{ "<leader>Rt", p("test"), desc = "Test" },
{ "<leader>RF", p("flash"), desc = "Build + Flash (Zephyr)" },
{ "<leader>Rs", p("select_target"), desc = "Select target/board" },
{ "<leader>Rk", p("configure"), desc = "Configure (menuconfig/clippy)" },
{ "<leader>Rc", p("clean"), desc = "Clean" },
{ "<leader>Ri", p("info"), desc = "Project info" },
},
},
{
"folke/which-key.nvim",
opts = {
spec = {
{ "<leader>R", group = "run/project", icon = " " },
},
},
},
}