From 68bc8119a4f77eedfd10065097eaaff4c5028628 Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 4 Sep 2024 14:23:08 -0400 Subject: [PATCH] add cmake-tools and some initial config/support for cmake projects --- init.lua | 1 + lazy-lock.json | 1 + lua/autocmds.lua | 18 ++++++++++++++++++ lua/plugins/cmake-tools.lua | 6 ++++++ lua/plugins/lsp.lua | 1 + lua/plugins/which-key.lua | 2 +- 6 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 lua/autocmds.lua create mode 100644 lua/plugins/cmake-tools.lua diff --git a/init.lua b/init.lua index 6e0cd6c..262fe16 100644 --- a/init.lua +++ b/init.lua @@ -26,6 +26,7 @@ vim.g.have_nerd_font = true require 'options' require 'keymaps' require 'lazy-bootstrap' +require 'autocmds' require 'lazy-plugins' require 'helper/health' diff --git a/lazy-lock.json b/lazy-lock.json index 2c98a0f..89f502b 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -2,6 +2,7 @@ "LuaSnip": { "branch": "master", "commit": "45db5addf8d0a201e1cf247cae4cdce605ad3768" }, "barbar.nvim": { "branch": "master", "commit": "31b6951c53a59bccfa91bf3984ed1510a940c836" }, "beacon.nvim": { "branch": "master", "commit": "098ff96c33874339d5e61656f3050dbd587d6bd5" }, + "cmake-tools.nvim": { "branch": "master", "commit": "4be3c229fe932043fd83ad52fdf0ba9af7297789" }, "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, "cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "031e6ba70b0ad5eee49fd2120ff7a2e325b17fa7" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, diff --git a/lua/autocmds.lua b/lua/autocmds.lua new file mode 100644 index 0000000..5b1f0b2 --- /dev/null +++ b/lua/autocmds.lua @@ -0,0 +1,18 @@ +-- TODO: why does this cmake-tools autocmd ONLY work when it is here and not +-- when it is inside that plugin's `config` function? that `config` +-- function pattern seems to work with a bunch of other plugins' autocmds ... ? + +vim.api.nvim_create_autocmd('User', { + pattern = 'CMakeToolsEnterProject', + callback = function(event) + local map = function(keys, func, desc, mode) + mode = mode or 'n' + vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'CMake: ' .. desc }) + end + + map('cc', 'CMakeClean', '[C]lean') + map('cg', 'CMakeGenerate', '[G]enerate') + map('cr', 'CMakeRun', '[R]un') + map('cd', 'CMakeDebug', '[D]ebug') + end, +}) diff --git a/lua/plugins/cmake-tools.lua b/lua/plugins/cmake-tools.lua new file mode 100644 index 0000000..4c6d00d --- /dev/null +++ b/lua/plugins/cmake-tools.lua @@ -0,0 +1,6 @@ +return { + { + 'Civitasv/cmake-tools.nvim', + opts = {}, + }, +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 004c442..e439a8a 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -169,6 +169,7 @@ return { -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { clangd = {}, + cmake = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- -- Some languages (like typescript) have entire language plugins that can be useful: diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua index 754679e..c62c1ea 100644 --- a/lua/plugins/which-key.lua +++ b/lua/plugins/which-key.lua @@ -42,13 +42,13 @@ return { -- Document existing key chains spec = { - { 'c', group = '[C]ode', mode = { 'n', 'x' } }, { 'd', group = '[D]ebug' }, { 's', group = '[S]earch' }, { 't', group = '[T]oggle' }, { 'l', group = '[L]SP' }, { 'b', group = '[B]uffer' }, { 'r', group = '[R]ust' }, + { 'c', group = '[C]Make' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, }, },