Compare commits

..

2 Commits

Author SHA1 Message Date
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
108ea36cca hyprland: port scripts off hyprlang hyprctl syntax
With the Lua config, `hyprctl dispatch` evaluates Lua rather than the
hyprlang dispatcher strings, and `hyprctl keyword` is refused outright
("can't work with non-legacy parsers"). Three scripts still used the old
forms and silently failed.

- toggle_floating (SUPER+W): rewritten around hl.dsp.window.{float,resize,
  center}. The Lua resize dispatcher takes absolute pixels only, so the
  70% is resolved against the logical size of the window's monitor, and
  fullscreen is left first since resize is a no-op while fullscreen.
  Floats every window at 70%x70% now, not just 50%x55% for kitty.
- performance: runtime overrides via `hyprctl eval hl.config{}`; drop the
  removed decoration:drop_shadow for decoration:shadow:enabled; read the
  gamemode flag from `getoption -j` (.bool), which the awk on line 2 had
  been picking the "set:" line out of.
- move_by_rules: movetoworkspace -> hl.dsp.window.move{workspace=N}.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01StGBghPW9Dm7z7uj2VNWHr
2026-09-04 15:21:05 +02:00
14 changed files with 794 additions and 81 deletions

26
clangd/config.yaml Normal file
View File

@@ -0,0 +1,26 @@
# clangd user configuration.
#
# Cross-compiled embedded builds (Zephyr in particular) put GCC-only flags into
# compile_commands.json. clangd is clang, does not recognise them, and reports
# "Unknown argument: ..." on line 1 of every file in the project -- even though
# the code itself is fine and all symbols resolve.
#
# Stripping them here, once, fixes every such project without needing a .clangd
# file checked into each one. Remove only drops a flag if it is actually
# present, so this is inert for native builds.
#
# If a new one shows up for another target (RISC-V, Xtensa ...), the message
# names it exactly -- add it to the list below.
CompileFlags:
Remove:
# --- seen in Zephyr / arm-none-eabi builds ---
- -fno-printf-return-value
- -fno-reorder-functions
- -fno-defer-pop
- -fconserve-stack
- -fno-freestanding
- -mfp16-format=*
- -mno-fdpic
# GCC tuning params clang has no equivalent for
- --param=*

View File

@@ -16,7 +16,7 @@ grep 'workspace' ~/.config/hypr/themes/luna/rules.conf | while IFS= read -r line
# Compare the retrieved value with the active class of the window
if echo "$active_class" | grep -E "$regex"; then
#echo "The class matches the active class of the window. Workspace value to apply: $workspace_value"
hyprctl dispatch movetoworkspace "$workspace_value"
hyprctl dispatch "hl.dsp.window.move({ workspace = $workspace_value })"
fi
fi
done

View File

@@ -1,12 +1,18 @@
#!/usr/bin/env sh
HYPRGAMEMODE=$(hyprctl getoption animations:enabled | awk 'NR==2{print $2}')
# Toggles "game mode": strips animations/blur/shadows/gaps for max performance,
# and reloads the config to restore them.
#
# NOTE: with the Lua config `hyprctl keyword` is gone ("can't work with
# non-legacy parsers"); runtime overrides go through `hyprctl eval hl.config{}`.
HYPRGAMEMODE=$(hyprctl getoption animations:enabled -j | jq -r '.bool')
# Waybar performance
FILE="$HOME/.config/waybar/style.css"
sed -i 's/\/\* \(.*animation:.*\) \*\//\1/g' $FILE
if [ "$HYPRGAMEMODE" = 1 ]; then
if [ "$HYPRGAMEMODE" = true ]; then
sed -i 's/^\(.*animation:.*\)$/\/\* \1 \*\//g' $FILE
fi
@@ -14,15 +20,20 @@ killall waybar
waybar > /dev/null 2>&1 &
# Hyprland performance
if [ "$HYPRGAMEMODE" = 1 ]; then
hyprctl --batch "\
keyword animations:enabled 0;\
keyword decoration:drop_shadow 0;\
keyword decoration:blur:enabled 0;\
keyword general:gaps_in 0;\
keyword general:gaps_out 0;\
keyword general:border_size 1;\
keyword decoration:rounding 0"
if [ "$HYPRGAMEMODE" = true ]; then
hyprctl eval 'return hl.config({
animations = { enabled = false },
decoration = {
rounding = 0,
blur = { enabled = false },
shadow = { enabled = false },
},
general = {
gaps_in = 0,
gaps_out = 0,
border_size = 1,
},
})'
exit
fi

View File

@@ -1,31 +1,25 @@
#!/bin/bash
floating=$(hyprctl activewindow -j | jq '.floating')
window=$(hyprctl activewindow -j | jq '.initialClass' | tr -d "\"")
# NOTE: with the Lua config, `hyprctl dispatch` evaluates Lua (hl.dispatch(...)),
# not the old hyprlang "togglefloating" / "resizeactive exact 70% 70%" strings.
# The Lua resize dispatcher only takes absolute x/y, so the percentage is
# resolved here against the logical size of the window's monitor.
function toggle() {
width=$1
height=$2
PERCENT=70
hyprctl --batch "dispatch togglefloating; dispatch resizeactive exact ${width} ${height}; dispatch centerwindow"
}
eval "$(hyprctl activewindow -j | jq -r '"floating=\(.floating) fullscreen=\(.fullscreen) mon=\(.monitor)"')"
function untoggle() {
hyprctl dispatch togglefloating
}
if [ "$floating" = "true" ]; then
hyprctl dispatch 'hl.dsp.window.float()'
exit
fi
function handle() {
width=$1
height=$2
read -r w h <<<"$(hyprctl monitors -j | jq -r --argjson m "$mon" --argjson p "$PERCENT" \
'.[] | select(.id == $m) | "\((.width / .scale * $p / 100) | round) \((.height / .scale * $p / 100) | round)"')"
if [ "$floating" == "false" ]; then
toggle "$width" "$height"
else
untoggle
fi
}
# resizeactive is a no-op on a fullscreen window, so leave fullscreen first.
if [ "$fullscreen" != "0" ]; then
hyprctl dispatch 'hl.dsp.window.fullscreen({ mode = "fullscreen" })'
fi
case $window in
kitty) handle "50%" "55%" ;;
*) handle "70%" "70%" ;;
esac
hyprctl --batch "dispatch hl.dsp.window.float(); dispatch hl.dsp.window.resize({ x = ${w}, y = ${h} }); dispatch hl.dsp.window.center()"

View File

@@ -1,32 +1,66 @@
{
"LazyVim": { "branch": "main", "commit": "d72127eb936f7f05d88d4fc316bc7e89080d69d8" },
"LazyVim": { "branch": "main", "commit": "c10948c50b18fae7f256433afdef09e432410480" },
"SchemaStore.nvim": { "branch": "main", "commit": "6a1a2daf151dd742d5ff2f64eb2cc049d7e5ab4a" },
"async.nvim": { "branch": "main", "commit": "ca8f5696c45bd4786b8840923d86b6932ce92ded" },
"blink.cmp": { "branch": "main", "commit": "78336bc89ee5365633bcf754d93df01678b5c08f" },
"bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" },
"catppuccin": { "branch": "main", "commit": "8c4125e3c746976ba025dc5d908fa22c6aa09486" },
"conform.nvim": { "branch": "master", "commit": "9fd3d5e0b689ec1bf400c53cbbec72c6fdf24081" },
"flash.nvim": { "branch": "main", "commit": "fcea7ff883235d9024dc41e638f164a450c14ca2" },
"gitsigns.nvim": { "branch": "main", "commit": "20ad4419564d6e22b189f6738116b38871082332" },
"grug-far.nvim": { "branch": "main", "commit": "3e72397465f774b01aa38e4fe8e6eecf23d766d9" },
"lazy.nvim": { "branch": "main", "commit": "db067881fff0fd4be8c00e5bde7492e0e1c77a2f" },
"lazydev.nvim": { "branch": "main", "commit": "371cd7434cbf95606f1969c2c744da31b77fcfa6" },
"lualine.nvim": { "branch": "master", "commit": "3946f0122255bc377d14a59b27b609fb3ab25768" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "3590d66effccc7376d8c3dbe45e8291f9fed2843" },
"mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" },
"mini.ai": { "branch": "main", "commit": "11c57180bc9084089206e211ac7aa598bedc9673" },
"mini.icons": { "branch": "main", "commit": "284798619aed9f4c1ac1b9417b9a5e3b4b85ef3a" },
"mini.pairs": { "branch": "main", "commit": "b9aada8c0e59f2b938e98fbf4eae0799eba96ad9" },
"noice.nvim": { "branch": "main", "commit": "5099348591f7d3ba9e547b1e631c694c65bbe0b9" },
"nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" },
"nvim-lint": { "branch": "master", "commit": "9da1fb942dd0668d5182f9c8dee801b9c190e2bb" },
"nvim-lspconfig": { "branch": "master", "commit": "e25994a1c2373784364852cd904cb39b6d75f227" },
"nvim-treesitter": { "branch": "main", "commit": "64f4755b9d6ea9008265b09eb79fd91727311682" },
"nvim-treesitter-textobjects": { "branch": "main", "commit": "5d63945ad7002ee3702c2f2150a662d5ed20626b" },
"nvim-ts-autotag": { "branch": "main", "commit": "c4ca798ab95b316a768d51eaaaee48f64a4a46bc" },
"catppuccin": { "branch": "main", "commit": "edefef779ab08ce1a4a404713e3012b0d202bd35" },
"clangd_extensions.nvim": { "branch": "main", "commit": "78c2ecd659d54972be17aa6ba2deac3c53223b80" },
"cmake-tools.nvim": { "branch": "master", "commit": "ee807ac4e62591720de2f6ad0abbfb966c4c7b97" },
"conform.nvim": { "branch": "master", "commit": "016802de402556da54c36bd7359b441266b01cdd" },
"crates.nvim": { "branch": "main", "commit": "b8281be336498035f9288d6542b2881a7140a9ec" },
"dial.nvim": { "branch": "master", "commit": "f2634758455cfa52a8acea6f142dcd6271a1bf57" },
"diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" },
"edgy.nvim": { "branch": "main", "commit": "8bfd2808994a988c975694122f68624b8a219f5f" },
"flash.nvim": { "branch": "main", "commit": "5f0f270fdc7c5b0c21d903ee85b9cb06f2ac636a" },
"friendly-snippets": { "branch": "main", "commit": "6cd7280adead7f586db6fccbd15d2cac7e2188b9" },
"gitsigns.nvim": { "branch": "main", "commit": "5be654f2232c10ddcad19c1607a67b6b4b78fc29" },
"grapple.nvim": { "branch": "main", "commit": "b41ddfc1c39f87f3d1799b99c2f0f1daa524c5f7" },
"grug-far.nvim": { "branch": "main", "commit": "11595bf747edc270bce2069d1020502ad4ae56cf" },
"lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" },
"lazydev.nvim": { "branch": "main", "commit": "ff2cbcba459b637ec3fd165a2be59b7bbaeedf0d" },
"lualine.nvim": { "branch": "master", "commit": "221ce6b2d999187044529f49da6554a92f740a96" },
"markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "40276c4df7e6bdce6801d6c035c6227f9115a855" },
"mason-nvim-dap.nvim": { "branch": "main", "commit": "9a10e096703966335bd5c46c8c875d5b0690dade" },
"mason.nvim": { "branch": "main", "commit": "2a6940af80375532e5e9e7c1f2fc6319a1b7a69d" },
"mini.ai": { "branch": "main", "commit": "25248c6aa002391936a6200f12d1466015987133" },
"mini.icons": { "branch": "main", "commit": "98faae31e9be1cc054ae63485e58ceb185efcad0" },
"mini.pairs": { "branch": "main", "commit": "b1c5a726921b7a8c9321e9a7a208aa0571de5810" },
"mini.surround": { "branch": "main", "commit": "8d5d0c5aa92449368ac251e85451d79d8f69d296" },
"noice.nvim": { "branch": "main", "commit": "7bfd942445fb63089b59f97ca487d605e715f155" },
"nui.nvim": { "branch": "main", "commit": "10fc361835c856ba4233ef5ea135b919bf3dce97" },
"nvim-dap": { "branch": "master", "commit": "c9a0738e45f1bd41d792a126941348dce661cf9b" },
"nvim-dap-python": { "branch": "master", "commit": "1808458eba2b18f178f990e01376941a42c7f93b" },
"nvim-dap-ui": { "branch": "master", "commit": "cc9dd33aade7f20bae414d0cba163bc60d4d4b43" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "fbdb48c2ed45f4a8293d0d483f7730d24467ccb6" },
"nvim-highlight-colors": { "branch": "main", "commit": "e4c7af0211866162d999ce0bdd6a029302e19139" },
"nvim-jqx": { "branch": "master", "commit": "07393e80fa8097e82f9038fec05e948fe8a60fd1" },
"nvim-lint": { "branch": "master", "commit": "3d55c8f67c6ae5c15e1042571e107c7a3d5c5f4e" },
"nvim-lspconfig": { "branch": "master", "commit": "85e732c62ac59ab7c12df71ddd020baa87948390" },
"nvim-nio": { "branch": "master", "commit": "edcc181a875301dd21840189aa2f2f9ad69fc172" },
"nvim-treesitter": { "branch": "main", "commit": "427e9222363d07c32d6db6169e4049c28d58d141" },
"nvim-treesitter-textobjects": { "branch": "main", "commit": "5c7b0263797dfd1bd6202f2b219f3b53a80b2187" },
"nvim-ts-autotag": { "branch": "main", "commit": "88c1453db4ba7dd24131086fe51fdf74e587d275" },
"nvim_context_vt": { "branch": "master", "commit": "74c5ec8786426c5458e1a9f6b8b2fd6977ba01ab" },
"persistence.nvim": { "branch": "main", "commit": "b20b2a7887bd39c1a356980b45e03250f3dce49c" },
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
"snacks.nvim": { "branch": "main", "commit": "76160be5d38cd67e46557cb5d0b3e36ececdfa3c" },
"todo-comments.nvim": { "branch": "main", "commit": "411503d3bedeff88484de572f2509c248e499b38" },
"tokyonight.nvim": { "branch": "main", "commit": "2642dbb83333e0575d1c3436e1d837926871c5fb" },
"trouble.nvim": { "branch": "main", "commit": "d7494d8bc563f8ae8b3f35d78c7478cf842b0ab9" },
"ts-comments.nvim": { "branch": "main", "commit": "123a9fb12e7229342f807ec9e6de478b1102b041" },
"which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" }
"plenary.nvim": { "branch": "master", "commit": "74b06c6c75e4eeb3108ec01852001636d85a932b" },
"py-requirements.nvim": { "branch": "main", "commit": "6d8b1657234e76ca1b850c42150187dcaa627e93" },
"refactoring.nvim": { "branch": "master", "commit": "64e10d782ae5b9653558482910213b8946651456" },
"render-markdown.nvim": { "branch": "main", "commit": "4663eb3ecd538bd5062628fb6d95bbe6bdca78f6" },
"rustaceanvim": { "branch": "main", "commit": "8fa1a98f514041132ab40088be53c130eb8d14c9" },
"smart-splits.nvim": { "branch": "master", "commit": "0ab2e4928dc867dfea3ff1da186e69f289d8a532" },
"snacks.nvim": { "branch": "main", "commit": "882c996cf28183f4d63640de0b4c02ec886d01f2" },
"suda.vim": { "branch": "master", "commit": "c492741b4679b3cdd4d9e34138209784e061d916" },
"todo-comments.nvim": { "branch": "main", "commit": "31e3c38ce9b29781e4422fc0322eb0a21f4e8668" },
"tokyonight.nvim": { "branch": "main", "commit": "cdc07ac78467a233fd62c493de29a17e0cf2b2b6" },
"trouble.nvim": { "branch": "main", "commit": "bd67efe408d4816e25e8491cc5ad4088e708a69a" },
"ts-comments.nvim": { "branch": "main", "commit": "a59d6092213447450191122c9346f309161504cb" },
"ts-error-translator.nvim": { "branch": "main", "commit": "558abff11b9e8f4cefc0de09df780c56841c7a4b" },
"ts-node-action": { "branch": "master", "commit": "dda34b5b440a4f1137f8e815756a19cf655b516f" },
"tsc.nvim": { "branch": "main", "commit": "e083bcf1e54bc3af7df92b33235efb334e8c782c" },
"venv-selector.nvim": { "branch": "main", "commit": "cc4bb3975de8835291f9bb45889e96c6b2795fc4" },
"which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" },
"yanky.nvim": { "branch": "main", "commit": "dd6689fdda85f66cab7d9b1a1664625f3be0920d" },
"yazi.nvim": { "branch": "main", "commit": "c176256edc3361d6fe388d8cd561bb716b5ee640" }
}

View File

@@ -1,8 +1,17 @@
{
"extras": [
"lazyvim.plugins.extras.coding.mini-surround",
"lazyvim.plugins.extras.dap.core",
"lazyvim.plugins.extras.editor.dial",
"lazyvim.plugins.extras.editor.refactoring",
"lazyvim.plugins.extras.lang.clangd",
"lazyvim.plugins.extras.lang.cmake",
"lazyvim.plugins.extras.lang.docker",
"lazyvim.plugins.extras.lang.git",
"lazyvim.plugins.extras.lang.json",
"lazyvim.plugins.extras.lang.rust",
"lazyvim.plugins.extras.lang.toml",
"lazyvim.plugins.extras.lang.yaml",
"lazyvim.plugins.extras.util.dot",
"plugins.extras.coding.blink-extended",
"plugins.extras.coding.treesitter.node-action",
@@ -18,6 +27,7 @@
"plugins.extras.lang.python-extended",
"plugins.extras.lang.web.html-css",
"plugins.extras.lang.web.typescript-extended",
"plugins.extras.lang.zephyr",
"plugins.extras.linting.eslint-extended",
"plugins.extras.lsp.lspconfig-extended",
"plugins.extras.lsp.mason-extended",

View File

@@ -8,7 +8,7 @@ vim.loader.enable()
go.lualine_info_extras = false
go.codeium_cmp_hide = false
go.lazygit_config = false
go.lazyvim_cmp = "blink"
go.lazyvim_cmp = "blink.cmp"
go.lazyvim_picker = "snacks"
-- Define leader key

View File

@@ -0,0 +1,115 @@
-- Zephyr RTOS support.
--
-- This extra is driven entirely by Zephyr's own environment variables and is
-- inert unless one of them is set, so it costs nothing on a machine that does
-- no Zephyr work and needs no per-host editing.
--
-- ZEPHYR_BASE the zephyr repo -- presence of this enables the extra
-- ZEPHYR_SDK_INSTALL_DIR Zephyr SDK root (toolchain variant "zephyr")
-- GNUARMEMB_TOOLCHAIN_PATH toolchain root (variant "gnuarmemb")
-- ZEPHYR_TOOLCHAIN_VARIANT which of the above is in use
--
-- Zephyr is otherwise "C + CMake + Kconfig + devicetree", so clangd and cmake
-- do the heavy lifting. What clangd cannot work out unaided is the built-in
-- include paths of a cross compiler, hence --query-driver.
-- (Zephyr's build/compile_commands.json is found by clangd on its own: it
-- searches ./ and ./build of each parent directory.)
local zephyr_base = os.getenv("ZEPHYR_BASE")
local sdk_dir = os.getenv("ZEPHYR_SDK_INSTALL_DIR")
local gnuarmemb = os.getenv("GNUARMEMB_TOOLCHAIN_PATH")
-- Not a Zephyr environment -> contribute nothing.
if not (zephyr_base or sdk_dir or gnuarmemb) then
return {}
end
--- Toolchain globs for clangd's --query-driver, taken from the Zephyr vars.
--- Falls back to whatever cross gcc the environment puts on $PATH when the
--- toolchain variables are not set (as with a distro-packaged toolchain).
---@return string[]
local function query_driver_globs()
local globs, seen = {}, {}
local function add(p)
if p and p ~= "" and not seen[p] then
seen[p] = true
globs[#globs + 1] = p
end
end
-- Zephyr SDK: <sdk>/<target>-zephyr-elf/bin/<target>-zephyr-elf-gcc
if sdk_dir then
add(sdk_dir .. "/*/bin/*-gcc")
end
-- gnuarmemb variant: <root>/bin/arm-none-eabi-gcc
if gnuarmemb then
add(gnuarmemb .. "/bin/*-gcc")
end
-- No toolchain var set: resolve the cross compiler through $PATH instead of
-- assuming a prefix, and glob its real directory.
if #globs == 0 then
for _, cc in ipairs({
"arm-zephyr-eabi-gcc",
"arm-none-eabi-gcc",
"riscv64-zephyr-elf-gcc",
"xtensa-espressif_esp32-elf-gcc",
}) do
local exe = vim.fn.exepath(cc)
if exe ~= "" then
add(vim.fs.dirname(vim.uv.fs_realpath(exe) or exe) .. "/*-gcc")
end
end
end
return globs
end
return {
-- Syntax for the two Zephyr-specific languages
{
"nvim-treesitter/nvim-treesitter",
opts = { ensure_installed = { "devicetree", "kconfig" } },
},
{
"neovim/nvim-lspconfig",
-- Filetype detection Neovim does not ship with
init = function()
vim.filetype.add({
extension = {
overlay = "dts", -- board/shield overlays are devicetree
},
filename = {
["prj.conf"] = "kconfig",
["west.yml"] = "yaml",
},
pattern = {
["Kconfig.*"] = "kconfig", -- Kconfig.foo, Kconfig.defconfig, ...
[".*/boards/.*%.conf"] = "kconfig",
[".*/prj_.*%.conf"] = "kconfig",
[".*_defconfig"] = "kconfig",
},
})
end,
opts = function(_, opts)
opts.servers = opts.servers or {}
local clangd = opts.servers.clangd or {}
local drivers = query_driver_globs()
if #drivers > 0 then
clangd.cmd = clangd.cmd or { "clangd" }
table.insert(clangd.cmd, "--query-driver=" .. table.concat(drivers, ","))
end
-- Treat a west workspace / Zephyr app as a project root.
clangd.root_markers = clangd.root_markers or {}
vim.list_extend(clangd.root_markers, { "west.yml", ".west", "prj.conf", "CMakeLists.txt" })
opts.servers.clangd = clangd
return opts
end,
},
}

View File

@@ -4,20 +4,6 @@ local prefix = "<leader>cl"
return {
{
"neovim/nvim-lspconfig",
init = function()
local keys = require("lazyvim.plugins.lsp.keymaps").get()
keys[#keys + 1] = { "<leader>cl", false }
keys[#keys + 1] = { "<leader>cil", "<cmd>LspInfo<cr>", desc = "Lsp" }
keys[#keys + 1] = { prefix .. "r", "<cmd>LspRestart<cr>", desc = "Restart Lsp" }
keys[#keys + 1] = { prefix .. "s", "<cmd>LspStart<cr>", desc = "Start Lsp" }
keys[#keys + 1] = { prefix .. "S", "<cmd>LspStop<cr>", desc = "Stop Lsp" }
-- stylua: ignore start
keys[#keys + 1] = { prefix .. "r", function() vim.lsp.buf.remove_workspace_folder() end, desc = "Remove workspace" }
keys[#keys + 1] = { prefix .. "a", function() vim.lsp.buf.add_workspace_folder() end, desc = "Add workspace" }
-- stylua: ignore end
end,
opts = {
diagnostics = {
virtual_text = {
@@ -42,6 +28,22 @@ return {
enabled = false,
},
servers = {
-- Keymaps for every server. Was an `init` function calling
-- require("lazyvim.plugins.lsp.keymaps").get(), which LazyVim
-- deprecated in favour of the `keys` field on the server config.
["*"] = {
keys = {
{ "<leader>cl", false },
{ "<leader>cil", "<cmd>LspInfo<cr>", desc = "Lsp" },
{ prefix .. "r", "<cmd>LspRestart<cr>", desc = "Restart Lsp" },
{ prefix .. "s", "<cmd>LspStart<cr>", desc = "Start Lsp" },
{ prefix .. "S", "<cmd>LspStop<cr>", desc = "Stop Lsp" },
-- stylua: ignore start
{ prefix .. "a", function() vim.lsp.buf.add_workspace_folder() end, desc = "Add workspace" },
{ prefix .. "R", function() vim.lsp.buf.remove_workspace_folder() end, desc = "Remove workspace" },
-- stylua: ignore end
},
},
lua_ls = {
settings = {
Lua = {

View File

@@ -8,6 +8,21 @@ table.insert(keys, { prefix .. "s", "<Cmd>BufferLineSortByExtension<CR>", desc =
table.insert(keys, { prefix .. "<", "<cmd>BufferLineMovePrev<cr>", desc = "Move buffer prev" })
table.insert(keys, { prefix .. ">", "<cmd>BufferLineMoveNext<cr>", desc = "Move buffer next" })
-- Jump straight to a buffer by its position in the bufferline.
-- BufferLineGoToBuffer takes the absolute 1-based slot, so <leader>b1 is always
-- the leftmost buffer and the count never skips the one you are already on.
-- The ordinal shown in the bufferline (see numbers = "ordinal" below) is the
-- number to press.
for i = 1, 9 do
table.insert(keys, { prefix .. i, "<cmd>BufferLineGoToBuffer " .. i .. "<cr>", desc = "Buffer " .. i })
end
-- ...and 0 for the last one, however many there are.
table.insert(keys, { prefix .. "0", "<cmd>BufferLineGoToBuffer -1<cr>", desc = "Last Buffer" })
-- Arrows step through the bufferline in visible order.
table.insert(keys, { prefix .. "<Left>", "<cmd>BufferLineCyclePrev<cr>", desc = "Prev Buffer" })
table.insert(keys, { prefix .. "<Right>", "<cmd>BufferLineCycleNext<cr>", desc = "Next Buffer" })
-- stylua: ignore end
return {
@@ -15,9 +30,11 @@ return {
keys = keys,
opts = {
options = {
modified_icon = "",
modified_icon = "",
color_icons = true,
separator_style = "slope",
-- Show 1, 2, 3 ... so the number you see is the number you press.
numbers = "ordinal",
},
},
}

View File

@@ -50,7 +50,7 @@ return {
{
"akinsho/bufferline.nvim",
opts = {
highlights = require("catppuccin.groups.integrations.bufferline").get_theme({
highlights = require("catppuccin.special.bufferline").get_theme({
styles = { "italic", "bold" },
custom = {
all = {

View File

@@ -0,0 +1,60 @@
-- Some language servers are distributed only as npm packages, and Node on Arch
-- ships without npm. Without this guard you get two separate rounds of errors:
--
-- 1. mason-lspconfig retries the install on every startup and fails, once per
-- server ("failed to install yamlls" ...).
-- 2. LazyVim still enables the server, so opening any matching file fails with
-- "Spawning language server with cmd: { "yaml-language-server", ... } failed".
--
-- So each server below is disabled unless its binary can actually be found.
-- Nothing is hardcoded to this host: the check is a PATH lookup plus Mason's own
-- bin directory, so the moment the server exists it enables itself again.
--
-- To get them: sudo pacman -S npm
-- nvim +"MasonInstall yaml-language-server dockerfile-language-server" +qa
-- LazyVim server name -> the executable Mason/npm installs for it.
local npm_servers = {
yamlls = "yaml-language-server",
dockerls = "docker-langserver",
docker_compose_language_service = "docker-compose-langserver",
}
local mason_bin = vim.fs.joinpath(vim.fn.stdpath("data"), "mason", "bin")
---@param bin string
---@return boolean
local function available(bin)
if vim.fn.executable(bin) == 1 then
return true
end
-- Mason prepends its bin dir to PATH only after setup, so look there directly.
return vim.uv.fs_stat(vim.fs.joinpath(mason_bin, bin)) ~= nil
end
local missing = {}
for server, bin in pairs(npm_servers) do
if not available(bin) then
missing[#missing + 1] = server
end
end
if #missing == 0 then
return {}
end
return {
{
"neovim/nvim-lspconfig",
opts = function(_, opts)
opts.servers = opts.servers or {}
for _, server in ipairs(missing) do
opts.servers[server] = vim.tbl_deep_extend("force", opts.servers[server] or {}, {
enabled = false, -- do not try to spawn a binary that is not there
mason = false, -- and do not retry the impossible install every startup
})
end
return opts
end,
},
}

View File

@@ -0,0 +1,55 @@
-- 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 = " " },
},
},
},
}

389
nvim/lua/util/project.lua Normal file
View File

@@ -0,0 +1,389 @@
-- Language-aware project runner.
--
-- Detects what kind of project the current buffer lives in and exposes a small
-- set of verbs (run / run file / build / test / flash / ...) that map onto the
-- right tool for that project. Bound under <leader>R -- see
-- lua/plugins/project-run.lua.
--
-- Everything is discovered from the project on disk; nothing is hardcoded to a
-- machine, and per-project choices (like the Zephyr board) are cached in
-- stdpath("state") rather than written into the repo.
local M = {}
---------------------------------------------------------------------------
-- helpers
---------------------------------------------------------------------------
--- The file the project should be judged from.
---
--- Not simply the current buffer: after one of these verbs opens a terminal,
--- that terminal is the focused buffer, and walking up from it finds no project
--- markers. So prefer the focused buffer only when it is a real file, and
--- otherwise fall back to the most recently used normal buffer, then cwd.
---@return string
function M.source_path()
local buf = vim.api.nvim_get_current_buf()
if vim.bo[buf].buftype == "" then
local name = vim.api.nvim_buf_get_name(buf)
if name ~= "" then
return name
end
end
-- Tracked by the autocmd in lua/plugins/project-run.lua.
local last = vim.g.project_last_file
if type(last) == "string" and last ~= "" then
return last
end
return vim.uv.cwd()
end
---@param markers string[]
---@return string|nil
local function root_with(markers)
return vim.fs.root(M.source_path(), markers)
end
local function exists(path)
return path and vim.uv.fs_stat(path) ~= nil
end
--- Run a command in a terminal at `cwd` so you can watch it and answer prompts.
local function term(cmd, cwd, opts)
opts = opts or {}
local ok, Snacks = pcall(require, "snacks")
if ok and Snacks.terminal then
Snacks.terminal.open(cmd, {
cwd = cwd,
interactive = true,
win = { position = opts.position or "float" },
})
else
vim.cmd("botright split | terminal " .. cmd)
end
vim.notify(cmd, vim.log.levels.INFO, { title = "project" })
end
--- Prefer a project-local virtualenv interpreter when there is one.
local function python_for(root)
for _, rel in ipairs({ ".venv/bin/python", "venv/bin/python" }) do
local p = vim.fs.joinpath(root, rel)
if exists(p) then
return vim.fn.shellescape(p)
end
end
return "python3"
end
---------------------------------------------------------------------------
-- per-project state (board selection, etc.)
---------------------------------------------------------------------------
local state_file = vim.fs.joinpath(vim.fn.stdpath("state"), "project-run.json")
local function load_state()
if not exists(state_file) then
return {}
end
local ok, data = pcall(function()
return vim.json.decode(table.concat(vim.fn.readfile(state_file), "\n"))
end)
return (ok and type(data) == "table") and data or {}
end
local function save_state(tbl)
pcall(vim.fn.writefile, vim.fn.split(vim.json.encode(tbl), "\n"), state_file)
end
---@param root string
---@param key string
function M.get_setting(root, key)
local s = load_state()
return (s[root] or {})[key]
end
---@param root string
---@param key string
---@param value any
function M.set_setting(root, key, value)
local s = load_state()
s[root] = s[root] or {}
s[root][key] = value
save_state(s)
end
---------------------------------------------------------------------------
-- project detection
---------------------------------------------------------------------------
--- Order matters: a Zephyr app is also a CMake project, so it must win.
local DETECT = {
{ type = "zephyr", markers = { "west.yml", ".west", "prj.conf" } },
{ type = "rust", markers = { "Cargo.toml" } },
{ type = "python", markers = { "pyproject.toml", "setup.py", "requirements.txt" } },
{ type = "cmake", markers = { "CMakeLists.txt", "CMakePresets.json" } },
{ type = "make", markers = { "Makefile" } },
}
---@return string type, string root
function M.detect()
for _, d in ipairs(DETECT) do
local root = root_with(d.markers)
if root then
-- A Zephyr app has prj.conf next to CMakeLists.txt; plain CMake does not.
return d.type, root
end
end
return "unknown", vim.uv.cwd()
end
function M.info()
local t, root = M.detect()
local extra = ""
if t == "zephyr" then
extra = " board: " .. (M.get_setting(root, "board") or "<not set>")
end
vim.notify(("project: %s\nroot: %s%s"):format(t, root, extra), vim.log.levels.INFO, { title = "project" })
end
---------------------------------------------------------------------------
-- Zephyr
---------------------------------------------------------------------------
local board_list_cache = nil
--- `west boards` walks the whole tree and is slow, so cache the result.
local function zephyr_boards(root, cb)
if board_list_cache then
return cb(board_list_cache)
end
vim.notify("listing boards (west boards)...", vim.log.levels.INFO, { title = "zephyr" })
vim.system({ "west", "boards", "-f", "{name}" }, { cwd = root, text = true }, function(res)
vim.schedule(function()
if res.code ~= 0 then
vim.notify("west boards failed:\n" .. (res.stderr or ""), vim.log.levels.ERROR, { title = "zephyr" })
return cb({})
end
local boards = {}
for _, line in ipairs(vim.split(res.stdout or "", "\n")) do
line = vim.trim(line)
if line ~= "" then
boards[#boards + 1] = line
end
end
table.sort(boards)
board_list_cache = boards
cb(boards)
end)
end)
end
--- Pick a board with the configured fuzzy picker (vim.ui.select is routed to it).
---@param root string
---@param cb fun(board:string)|nil
function M.zephyr_select_board(root, cb)
root = root or select(2, M.detect())
zephyr_boards(root, function(boards)
if #boards == 0 then
return
end
vim.ui.select(boards, { prompt = "Zephyr board:" }, function(choice)
if not choice then
return
end
M.set_setting(root, "board", choice)
vim.notify("board = " .. choice, vim.log.levels.INFO, { title = "zephyr" })
if cb then
cb(choice)
end
end)
end)
end
--- Get the board, prompting for one if it has not been chosen yet.
local function with_board(root, cb)
local board = M.get_setting(root, "board")
if board then
return cb(board)
end
M.zephyr_select_board(root, cb)
end
local function zephyr_build_dir(root)
return M.get_setting(root, "build_dir") or "build"
end
---------------------------------------------------------------------------
-- verbs
---------------------------------------------------------------------------
--- Primary "run this project".
function M.run()
local t, root = M.detect()
if t == "rust" then
term("cargo run", root)
elseif t == "python" then
local py = python_for(root)
-- main.py at the root wins; then any package with a __main__.py.
if exists(vim.fs.joinpath(root, "main.py")) then
term(py .. " main.py", root)
return
end
local mains = vim.fs.find("__main__.py", { path = root, type = "file", limit = 5 })
if #mains > 0 then
local dir = vim.fs.dirname(mains[1])
local pkg = vim.fs.basename(dir)
local parent = vim.fs.dirname(dir)
-- run as a module so intra-package imports resolve
term(("PYTHONPATH=%s %s -m %s"):format(vim.fn.shellescape(parent), py, pkg), root)
return
end
M.run_file()
elseif t == "zephyr" then
M.flash()
elseif t == "cmake" then
-- run the first executable cmake produced, if we can find one
local bin = vim.fs.find(function(name, path)
return path:match("/build$") ~= nil and vim.fn.executable(vim.fs.joinpath(path, name)) == 1
end, { path = vim.fs.joinpath(root, "build"), type = "file", limit = 1 })[1]
if bin then
term(vim.fn.shellescape(bin), root)
else
vim.notify("no executable found in build/ -- build first", vim.log.levels.WARN, { title = "project" })
end
elseif t == "make" then
term("make run", root)
else
M.run_file()
end
end
--- Run just the current file.
function M.run_file()
local file = M.source_path()
if file == "" or vim.fn.filereadable(file) == 0 then
return vim.notify("no file to run", vim.log.levels.WARN, { title = "project" })
end
local _, root = M.detect()
local ft = vim.filetype.match({ filename = file }) or vim.bo.filetype
local runners = {
python = function()
return python_for(root) .. " " .. vim.fn.shellescape(file)
end,
lua = function()
return "lua " .. vim.fn.shellescape(file)
end,
sh = function()
return "bash " .. vim.fn.shellescape(file)
end,
rust = function()
return "cargo run"
end,
go = function()
return "go run " .. vim.fn.shellescape(file)
end,
}
local build = runners[ft]
if not build then
-- Compiled languages have no meaningful "run this one file"; say what to
-- use instead rather than just refusing.
return vim.notify(
("no single-file runner for '%s' -- use <leader>Rr to run the project"):format(ft),
vim.log.levels.WARN,
{ title = "project" }
)
end
term(build(), root)
end
function M.build()
local t, root = M.detect()
if t == "zephyr" then
with_board(root, function(board)
term(("west build -b %s -d %s ."):format(board, zephyr_build_dir(root)), root)
end)
elseif t == "rust" then
term("cargo build", root)
elseif t == "cmake" then
term("cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && cmake --build build", root)
elseif t == "make" then
term("make", root)
elseif t == "python" then
term(python_for(root) .. " -m build", root)
else
vim.notify("no build for project type '" .. t .. "'", vim.log.levels.WARN, { title = "project" })
end
end
function M.test()
local t, root = M.detect()
if t == "rust" then
term("cargo test", root)
elseif t == "python" then
term(python_for(root) .. " -m pytest", root)
elseif t == "zephyr" then
with_board(root, function(board)
term(("west twister -p %s -T ."):format(board), root)
end)
elseif t == "cmake" then
term("ctest --test-dir build --output-on-failure", root)
elseif t == "make" then
term("make test", root)
else
vim.notify("no test for project type '" .. t .. "'", vim.log.levels.WARN, { title = "project" })
end
end
--- Zephyr flash (and the obvious analogue elsewhere).
function M.flash()
local t, root = M.detect()
if t ~= "zephyr" then
return vim.notify("flash is Zephyr-only (project is '" .. t .. "')", vim.log.levels.WARN, { title = "project" })
end
with_board(root, function(board)
term(("west build -b %s -d %s . && west flash -d %s"):format(board, zephyr_build_dir(root), zephyr_build_dir(root)), root)
end)
end
function M.clean()
local t, root = M.detect()
if t == "zephyr" then
term("west build -t pristine -d " .. zephyr_build_dir(root), root)
elseif t == "rust" then
term("cargo clean", root)
elseif t == "cmake" then
term("cmake --build build --target clean", root)
elseif t == "make" then
term("make clean", root)
else
vim.notify("no clean for project type '" .. t .. "'", vim.log.levels.WARN, { title = "project" })
end
end
--- Zephyr menuconfig / rust clippy / python lint -- the "configure" slot.
function M.configure()
local t, root = M.detect()
if t == "zephyr" then
term("west build -t menuconfig -d " .. zephyr_build_dir(root), root)
elseif t == "rust" then
term("cargo clippy --all-targets", root)
elseif t == "cmake" then
term("cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", root)
else
vim.notify("nothing to configure for '" .. t .. "'", vim.log.levels.WARN, { title = "project" })
end
end
--- Select the target: Zephyr board today, extensible later.
function M.select_target()
local t, root = M.detect()
if t == "zephyr" then
M.zephyr_select_board(root)
else
vim.notify("no target to select for project type '" .. t .. "'", vim.log.levels.WARN, { title = "project" })
end
end
return M