From 69182fb677180613d3ba0e9042882a5694bb121a Mon Sep 17 00:00:00 2001 From: Aotrix Date: Mon, 24 Feb 2025 15:36:58 +0100 Subject: C++ autoformat finally works! --- lua/aotrix/plugins/autoformat.lua | 19 ++++++++------ lua/aotrix/plugins/lsp.lua | 55 +++++++++++++++++++++------------------ lua/aotrix/plugins/nvim_dap.lua | 39 ++++++++++++--------------- 3 files changed, 58 insertions(+), 55 deletions(-) (limited to 'lua/aotrix') diff --git a/lua/aotrix/plugins/autoformat.lua b/lua/aotrix/plugins/autoformat.lua index 4dec682..d46f8af 100644 --- a/lua/aotrix/plugins/autoformat.lua +++ b/lua/aotrix/plugins/autoformat.lua @@ -2,15 +2,18 @@ return { "stevearc/conform.nvim", opts = { notify_on_error = false, - format_on_save = { - timeout_ms = 500, - lsp_fallback = true, - }, + format_on_save = {timeout_ms = 500, lsp_fallback = true}, formatters_by_ft = { - lua = { "lua-format" }, - python = { "black", "pyink" }, - cpp = { "clang-format" }, - cmake = { "cmake_format" }, + lua = {"lua-format"}, + python = {"black", "pyink"}, + cpp = {"clang_format"}, + cmake = {"cmake_format"} }, + formatters = { + clang_format = { + prepend_args = {'--style={BasedOnStyle: LLVM, IndentWidth: 4}'} + }, + shfmt = {prepend_args = {'-i', '4'}} + } } } diff --git a/lua/aotrix/plugins/lsp.lua b/lua/aotrix/plugins/lsp.lua index 36486cc..d24b0d0 100644 --- a/lua/aotrix/plugins/lsp.lua +++ b/lua/aotrix/plugins/lsp.lua @@ -1,42 +1,47 @@ return { "neovim/nvim-lspconfig", + dependencies = { + "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim" + }, config = function() + require("mason").setup() + require("mason-lspconfig").setup({ + ensure_installed = {"cmake", "lua_ls"} + }) require('lspconfig').clangd.setup({ root_dir = function(fname) - return require("lspconfig.util").root_pattern( - "CMakeLists.txt", - "Makefile", - "configure.ac", - "configure.in", - "config.h.in", - "meson.build", - "meson_options.txt", - "build.ninja" - )(fname) or require("lspconfig.util").root_pattern("compile_commands.json", "compile_flags.txt")( - fname - ) or require("lspconfig.util").find_git_ancestor(fname) + return require("lspconfig.util").root_pattern("CMakeLists.txt", + "Makefile", + "configure.ac", + "configure.in", + "config.h.in", + "meson.build", + "meson_options.txt", + "build.ninja")( + fname) or + require("lspconfig.util").root_pattern( + "compile_commands.json", "compile_flags.txt")( + fname) or + require("lspconfig.util").find_git_ancestor(fname) end, - capabilities = { - offsetEncoding = { "utf-16" }, - }, + capabilities = {offsetEncoding = {"utf-16"}}, cmd = { - "clangd", - "--background-index", - "--clang-tidy", - "--header-insertion=iwyu", - "--completion-style=detailed", - "--function-arg-placeholders", - "--fallback-style=llvm", + "clangd", "--background-index", "--clang-tidy", + "--header-insertion=iwyu", "--completion-style=detailed", + "--function-arg-placeholders", "--fallback-style=llvm" }, init_options = { usePlaceholders = true, completeUnimported = true, - clangdFileStatus = true, - }, + clangdFileStatus = true + } }) vim.keymap.set("n", "o", "ClangdSwitchSourceHeader") require('lspconfig').cmake.setup({}) - end, + require('lspconfig').lua_ls.setup({ + settings = {completion = {callSnippet = 'Replace'}} + }) + end } diff --git a/lua/aotrix/plugins/nvim_dap.lua b/lua/aotrix/plugins/nvim_dap.lua index 13213d4..d5d0346 100644 --- a/lua/aotrix/plugins/nvim_dap.lua +++ b/lua/aotrix/plugins/nvim_dap.lua @@ -1,11 +1,9 @@ return { 'mfussenegger/nvim-dap', dependencies = { - 'rcarriga/nvim-dap-ui', - 'theHamsta/nvim-dap-virtual-text', - 'nvim-neotest/nvim-nio', - 'williamboman/mason.nvim', - 'jay-babu/mason-nvim-dap.nvim', + 'rcarriga/nvim-dap-ui', 'theHamsta/nvim-dap-virtual-text', + 'nvim-neotest/nvim-nio', 'williamboman/mason.nvim', + 'jay-babu/mason-nvim-dap.nvim' }, config = function() @@ -15,13 +13,11 @@ return { require("dapui").setup() require("nvim-dap-virtual-text").setup() require("mason").setup() - require("mason-nvim-dap").setup({ - ensure_installed = { "codelldb" } - }) + require("mason-nvim-dap").setup({ensure_installed = {"codelldb"}}) dap.adapters.codelldb = { type = "executable", - command = "codelldb", -- or if not in $PATH: "/absolute/path/to/codelldb" + command = "codelldb" -- or if not in $PATH: "/absolute/path/to/codelldb" } dap.configurations.cpp = { @@ -30,19 +26,16 @@ return { type = "codelldb", request = "launch", program = function() - return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file') + return vim.fn.input('Path to executable: ', + vim.fn.getcwd() .. '/', 'file') end, cwd = '${workspaceFolder}', - stopOnEntry = false, - }, + stopOnEntry = false + } } - dap.listeners.before.attach.dapui_config = function() - ui.open() - end - dap.listeners.before.launch.dapui_config = function() - ui.open() - end + dap.listeners.before.attach.dapui_config = function() ui.open() end + dap.listeners.before.launch.dapui_config = function() ui.open() end dap.listeners.before.event_terminated.dapui_config = function() ui.close() end @@ -50,11 +43,13 @@ return { ui.close() end - vim.keymap.set("n", "b", function() require("dap").toggle_breakpoint() end) - vim.keymap.set("n", "gb", function() require("dap").run_to_cursor() end) + vim.keymap.set("n", "b", + function() require("dap").toggle_breakpoint() end) + vim.keymap.set("n", "gb", + function() require("dap").run_to_cursor() end) -- Eval var under cursor vim.keymap.set("n", "?", function() - require("dapui").eval(nil, { enter = true }) + require("dapui").eval(nil, {enter = true}) end) vim.keymap.set("n", "", function() require("dap").continue() end) vim.keymap.set("n", "", function() require("dap").step_into() end) @@ -63,6 +58,6 @@ return { vim.keymap.set("n", "", function() require("dap").step_back() end) vim.keymap.set("n", "", function() require("dap").restart() end) - end, + end } -- cgit v1.2.3