aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2023-02-22 10:11:46 +0100
committerFederico Igne <git@federicoigne.com>2023-02-22 10:11:46 +0100
commitc6dfb74bb0206a89d4b69311334133541d1d6aa5 (patch)
treead0e046ec8e35db5bb2dec0d42e79c0e2ff45708
parenta2216a0b7aae67ec6d59ae269806819070aab99e (diff)
downloaddotfiles-c6dfb74bb0206a89d4b69311334133541d1d6aa5.tar.gz
dotfiles-c6dfb74bb0206a89d4b69311334133541d1d6aa5.zip
[nvim] improve C++ bindings for cmake/docker tasks
-rw-r--r--neovim/.config/nvim/ftplugin/cpp.lua47
-rw-r--r--neovim/.config/nvim/plugin/mappings.lua10
2 files changed, 43 insertions, 14 deletions
diff --git a/neovim/.config/nvim/ftplugin/cpp.lua b/neovim/.config/nvim/ftplugin/cpp.lua
index f6e21f2..962b604 100644
--- a/neovim/.config/nvim/ftplugin/cpp.lua
+++ b/neovim/.config/nvim/ftplugin/cpp.lua
@@ -1,5 +1,5 @@
1--- Personal lua config files for NeoVim. 1--- Personal lua config files for NeoVim.
2-- Last Changed: 2019-01-27 2-- Last Changed: 2023-02-08
3-- Author: Federico Igne <git@federicoigne.com> 3-- Author: Federico Igne <git@federicoigne.com>
4-- License: This file is placed in the public domain. 4-- License: This file is placed in the public domain.
5 5
@@ -8,25 +8,32 @@ local cmake = require 'tasks.module.cmake'
8local cmd = vim.cmd 8local cmd = vim.cmd
9local map = require 'dyamon.util.map' 9local map = require 'dyamon.util.map'
10 10
11
12vim.b.ctags_command="ctags -R --c++-kinds=+p --fields=+iaS --extra=+qf --exclude=build ." 11vim.b.ctags_command="ctags -R --c++-kinds=+p --fields=+iaS --extra=+qf --exclude=build ."
13 12
13vim.b['surround_'..string.byte('h')] = "#ifndef \1#define: \r.*\r\\U&\\E_H\1\n#define \1\r.*\r\\U&\\E_H\1\n\n\r\n\n#endif //\1\r.*\r\\U&\\E_H\1"
14--- Tasks 14--- Tasks
15 15
16map.b.nore.n(0, '<leader>cb', '<cmd>Task start cmake build<cr>') 16map.b.nore.n(0, '<leader>cb', '<cmd>Task start cmake build<cr>')
17map.b.nore.n(0, '<leader>cc', '<cmd>Task start cmake configure<cr>') 17map.b.nore.n(0, '<leader>cc', '<cmd>Task start cmake configure<cr>')
18map.b.nore.n(0, '<leader>cd', '<cmd>Task start cmake debug<cr>') 18map.b.nore.n(0, '<leader>cg', '<cmd>Task start cmake debug<cr>')
19map.b.nore.n(0, '<leader>cdu', '<cmd>Task start docker up<cr>')
20map.b.nore.n(0, '<leader>cdd', '<cmd>Task start docker down<cr>')
19map.b.nore.n(0, '<leader>cr', '<cmd>Task start cmake run<cr>') 21map.b.nore.n(0, '<leader>cr', '<cmd>Task start cmake run<cr>')
20map.b.nore.n(0, '<leader>ct', '<cmd>Task set_module_param cmake target<cr>') 22map.b.nore.n(0, '<leader>ct', '<cmd>Task set_module_param cmake target<cr>')
21 23
22function compose(first, second, idx) 24function compose(first, second, idx)
23 if (type(first) == "table") then 25 if (type(first) == "table") then
24 local idx = idx or #first 26 -- NOTE we need a copy, first is passed by reference!
25 local task = first[idx] 27 local res = {}
26 first[idx] = function(module_config, _) 28 for _,t in ipairs(first) do
29 table.insert(res,t)
30 end
31 local idx = idx or #res
32 local task = res[idx]
33 res[idx] = function(module_config, _)
27 return second(task(module_config)) 34 return second(task(module_config))
28 end 35 end
29 return first 36 return res
30 else 37 else
31 return function(module_config, _) 38 return function(module_config, _)
32 return second(first(module_config)) 39 return second(first(module_config))
@@ -34,20 +41,39 @@ function compose(first, second, idx)
34 end 41 end
35end 42end
36 43
37local function lsp_restart(t) 44local function add_conan_options(t)
45 -- NOTE slow operation since it reads JSON from file
46 local build_type = require'tasks.project_config'.new().cmake.build_type
47 local args = {
48 "-D", "CONAN_OPTIONS=--build missing --settings build_type=" .. build_type ,
49 table.unpack(t.args)
50 }
51 t.args = args
52 return t
53end
54
55local function close_qf(t)
38 local old_after_success = t.after_success 56 local old_after_success = t.after_success
39 function t.after_success() 57 function t.after_success()
40 old_after_success() 58 old_after_success()
41 cmd.cclose() 59 cmd.cclose()
60 end
61 return t
62end
63
64local function lsp_restart(t)
65 local old_after_success = t.after_success
66 function t.after_success()
67 old_after_success()
42 cmd.LspRestart() 68 cmd.LspRestart()
43 end 69 end
44 return t 70 return t
45end 71end
46cmake.tasks.configure = compose(cmake.tasks.configure, lsp_restart)
47 72
48local function invoke_gdb(t) 73local function invoke_gdb(t)
49 local function after_success() 74 local function after_success()
50 cmd.cclose() 75 cmd.cclose()
76 cmd.only()
51 cmd.packadd("termdebug") 77 cmd.packadd("termdebug")
52 cmd.Termdebug(t.cmd) 78 cmd.Termdebug(t.cmd)
53 end 79 end
@@ -56,4 +82,7 @@ local function invoke_gdb(t)
56 after_success = after_success 82 after_success = after_success
57 } 83 }
58end 84end
85
86cmake.tasks.configure = compose(compose(compose(cmake.tasks.configure, add_conan_options), close_qf), lsp_restart)
87cmake.tasks.build = compose(cmake.tasks.build, close_qf)
59cmake.tasks.debug = compose(cmake.tasks.run, invoke_gdb) 88cmake.tasks.debug = compose(cmake.tasks.run, invoke_gdb)
diff --git a/neovim/.config/nvim/plugin/mappings.lua b/neovim/.config/nvim/plugin/mappings.lua
index 94958c7..ceaa408 100644
--- a/neovim/.config/nvim/plugin/mappings.lua
+++ b/neovim/.config/nvim/plugin/mappings.lua
@@ -11,12 +11,12 @@ vim.g.mapleader = ' '
11map.nore.n('<leader>bd', '<cmd>Bdelete<cr>') 11map.nore.n('<leader>bd', '<cmd>Bdelete<cr>')
12 12
13-- Compilation 13-- Compilation
14map.nore.n('<leader>cs', '^v$h:<c-u>SlimeSend1 <c-r>*<cr>') 14-- map.nore.n('<leader>cs', '^v$h"sy:SlimeSend1 <c-r>s<cr>')
15map.n('<leader>cS', '<Plug>SlimeParagraphSend') 15-- map.n('<leader>cS', '<Plug>SlimeParagraphSend')
16map.x('<leader>cs', '<Plug>SlimeRegionSend') 16-- map.x('<leader>cs', '<Plug>SlimeRegionSend')
17map.n('<leader>ct', '<cmd>TagsGenerate<cr>') 17-- map.n('<leader>ct', '<cmd>TagsGenerate<cr>')
18 18
19-- Files 19-- Navigation
20map.nore.n('-', ':NnnPicker %:p:h<cr>') 20map.nore.n('-', ':NnnPicker %:p:h<cr>')
21map.nore.n('<leader>n', '<cmd>NnnPicker<cr>') 21map.nore.n('<leader>n', '<cmd>NnnPicker<cr>')
22--map.nore.n('<leader>f', ':find<space>') 22--map.nore.n('<leader>f', ':find<space>')