diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index 6ef831e..ce2b846 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -3,6 +3,7 @@ "LuaSnip": { "branch": "master", "commit": "f03089854a8e15594a01562fa7192d0009a6fbe7" }, "Navigator.nvim": { "branch": "master", "commit": "91d86506ac2a039504d5205d32a1d4bc7aa57072" }, "bufferline.nvim": { "branch": "main", "commit": "1a3397556d194bb1f2cc530b07124ccc512c5501" }, + "cmake-tools.nvim": { "branch": "master", "commit": "edbf419e00b21e83d45f4a17edffb2035d7a0ce6" }, "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, "fidget.nvim": { "branch": "main", "commit": "785efc604f6ffe3c3fdd2ea86262804d48863ee1" }, @@ -17,6 +18,7 @@ "nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" }, "nvim-lastplace": { "branch": "main", "commit": "0bb6103c506315044872e0f84b1f736c4172bb20" }, "nvim-lspconfig": { "branch": "master", "commit": "694aaec65733e2d54d393abf80e526f86726c988" }, + "nvim-notify": { "branch": "master", "commit": "e4a2022f4fec2d5ebc79afa612f96d8b11c627b3" }, "nvim-tree.lua": { "branch": "master", "commit": "05f55c1fd6470b31627655c528245794e3cd4b2c" }, "nvim-treesitter": { "branch": "master", "commit": "0791b5ebb590a2d44e20640c52679df1fc42e8ab" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "ec1c5bdb3d87ac971749fa6c7dbc2b14884f1f6a" }, diff --git a/.config/nvim/lua/config/lsp/clangd.lua b/.config/nvim/lua/config/lsp/clangd.lua new file mode 100644 index 0000000..7676737 --- /dev/null +++ b/.config/nvim/lua/config/lsp/clangd.lua @@ -0,0 +1,3 @@ +return { + autoformat = true, +} diff --git a/.config/nvim/lua/config/lsp/init.lua b/.config/nvim/lua/config/lsp/init.lua index 168ce95..9ce5d42 100644 --- a/.config/nvim/lua/config/lsp/init.lua +++ b/.config/nvim/lua/config/lsp/init.lua @@ -1,103 +1,28 @@ --- This function gets run when an LSP connects to a particular buffer. +require('mason').setup() +require('mason-lspconfig').setup() + +local mason_lspconfig = require('mason-lspconfig') + local on_attach = function(_, bufnr) - -- NOTE: Remember that lua is a real programming language, and as such it is possible - -- to define small helper and utility functions so you don't have to repeat yourself - -- many times. - -- - -- In this case, we create a function that lets us more easily define mappings specific - -- for LSP related items. It sets the mode, buffer and description for us each time. - local nmap = function(keys, func, desc) - if desc then - desc = 'LSP: ' .. desc - end + require("config.lsp.keybinds").init_keymap(bufnr) - vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) - end - - nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') - nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') - - nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') - nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') - nmap('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') - - nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') - - -- See `:help K` for why this keymap - nmap('K', vim.lsp.buf.hover, 'Hover Documentation') - nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') - - -- Lesser used LSP functionality - nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') - nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') - nmap('wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, '[W]orkspace [L]ist Folders') - - -- Create a command `:Format` local to the LSP buffer vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) vim.lsp.buf.format() end, { desc = 'Format current buffer with LSP' }) end --- document existing key chains --- require('which-key').register { --- ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, --- ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, --- ['g'] = { name = '[G]it', _ = 'which_key_ignore' }, --- ['h'] = { name = 'More git', _ = 'which_key_ignore' }, --- ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, --- ['s'] = { name = '[S]earch', _ = 'which_key_ignore' }, --- ['w'] = { name = '[W]orkspace', _ = 'which_key_ignore' }, --- } - --- mason-lspconfig requires that these setup functions are called in this order --- before setting up the servers. -require('mason').setup() -require('mason-lspconfig').setup() - --- Enable the following language servers --- Feel free to add/remove any LSPs that you want here. They will automatically be installed. --- --- Add any additional override configuration in the following tables. They will be passed to --- the `settings` field of the server config. You must look up that documentation yourself. --- --- If you want to override the default filetypes that your language server will attach to you can --- define the property 'filetypes' to the map in question. local servers = { - clangd = {}, - -- gopls = {}, - -- pyright = {}, - -- rust_analyzer = {}, - -- tsserver = {}, - -- html = { filetypes = { 'html', 'twig', 'hbs'} }, - - lua_ls = { - Lua = { - workspace = { checkThirdParty = false }, - telemetry = { enable = false }, - -- NOTE: toggle below to ignore Lua_LS's noisy `missing-fields` warnings - -- diagnostics = { disable = { 'missing-fields' } }, - }, - }, + clangd = require("config.lsp.clangd"), + pyright = require("config.lsp.pyright"), + lua_ls = require("config.lsp.lua_ls"), } --- Setup neovim lua configuration -require('neodev').setup() - --- nvim-cmp supports additional completion capabilities, so broadcast that to servers local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) --- Ensure the servers above are installed -local mason_lspconfig = require 'mason-lspconfig' - -mason_lspconfig.setup { +mason_lspconfig.setup({ ensure_installed = vim.tbl_keys(servers), -} +}) mason_lspconfig.setup_handlers { function(server_name) diff --git a/.config/nvim/lua/config/lsp/keybinds.lua b/.config/nvim/lua/config/lsp/keybinds.lua new file mode 100644 index 0000000..cc3a3bd --- /dev/null +++ b/.config/nvim/lua/config/lsp/keybinds.lua @@ -0,0 +1,36 @@ +local M = {} + +function M.init_keymap(bufnr) + local nmap = function(keys, func, desc) + if desc then + desc = 'LSP: ' .. desc + end + + vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) + end + + nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') + nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') + + nmap('gd', require('telescope.builtin').lsp_definitions, '[G]oto [D]efinition') + nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') + nmap('gI', require('telescope.builtin').lsp_implementations, '[G]oto [I]mplementation') + nmap('D', require('telescope.builtin').lsp_type_definitions, 'Type [D]efinition') + + nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') + nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + + -- See `:help K` for why this keymap + nmap('K', vim.lsp.buf.hover, 'Hover Documentation') + nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') + + -- Lesser used LSP functionality + nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') + nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') + nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') + nmap('wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, '[W]orkspace [L]ist Folders') +end + +return M diff --git a/.config/nvim/lua/config/lsp/lua_ls.lua b/.config/nvim/lua/config/lsp/lua_ls.lua new file mode 100644 index 0000000..d106223 --- /dev/null +++ b/.config/nvim/lua/config/lsp/lua_ls.lua @@ -0,0 +1,8 @@ +require('neodev').setup() + +return { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + }, +} diff --git a/.config/nvim/lua/config/lsp/pyright.lua b/.config/nvim/lua/config/lsp/pyright.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/.config/nvim/lua/config/lsp/pyright.lua @@ -0,0 +1 @@ +return {} diff --git a/.config/nvim/lua/config/mappings.lua b/.config/nvim/lua/config/mappings.lua index e25ae31..557b78b 100644 --- a/.config/nvim/lua/config/mappings.lua +++ b/.config/nvim/lua/config/mappings.lua @@ -5,8 +5,8 @@ map('n', '', '') map('v', 'K', '') -- Movement between buffers -map({'n', 'v', 'i'}, '', ':bp') -map({'n', 'v', 'i'}, '', ':bn') +map({ 'n', 'v', 'i' }, '', ':bp') +map({ 'n', 'v', 'i' }, '', ':bn') -- Remap for dealing with word wrap map('n', 'k', 'v:count == 0 ? "gk" : "k"', { expr = true, silent = true }) @@ -14,8 +14,9 @@ map('n', 'j', 'v:count == 0 ? "gj" : "j"', { expr = true, silent = true }) -- Exit buffers/nvim with map('n', 'q', function() require('utils.close_buffer').close_buffer() end) -map('n', '', function() require('utils.close_buffer').close_buffer(true) end) +map('n', '1', function() require('utils.close_buffer').close_buffer(true) end) map('n', 'Q', ':%bd | quit') +map('n', '!', ':%bd! | quit!') map('n', 'w', ':write') -- Copy and paste from clipboard @@ -23,3 +24,8 @@ map('n', 'y', '"+yy') map('v', 'y', '"+y') map({ 'n', 'v' }, 'p', '"+p') map({ 'n', 'v' }, 'P', '"+P') + +-- Remap to remove last word +map('i', '', '') + +map('n', 'F', function() vim.lsp.buf.format() end) diff --git a/.config/nvim/lua/config/plugins/cmake-tools.lua b/.config/nvim/lua/config/plugins/cmake-tools.lua index 17a0afa..f5f4854 100644 --- a/.config/nvim/lua/config/plugins/cmake-tools.lua +++ b/.config/nvim/lua/config/plugins/cmake-tools.lua @@ -8,7 +8,7 @@ require("cmake-tools").setup { -- ${kitGenerator} -- ${variant:xx} cmake_build_directory = "cmake-build-${variant:buildType}", -- this is used to specify generate directory for cmake, allows macro expansion - cmake_soft_link_compile_commands = false, -- this will automatically make a soft link from compile commands file to project root dir + cmake_soft_link_compile_commands = true, -- this will automatically make a soft link from compile commands file to project root dir cmake_compile_commands_from_lsp = false, -- this will automatically set compile commands file location using lsp, to use it, please set `cmake_soft_link_compile_commands` to false cmake_kits_path = nil, -- this is used to specify global cmake kits path, see CMakeKits for detailed usage cmake_variants_message = { @@ -56,12 +56,20 @@ require("cmake-tools").setup { start_insert_in_launch_task = false, -- If you want to enter terminal with :startinsert upon using :CMakeRun start_insert_in_other_tasks = false, -- If you want to enter terminal with :startinsert upon launching all other cmake tasks in the terminal. Generally set as false focus_on_main_terminal = false, -- Focus on cmake terminal when cmake task is launched. Only used if executor is terminal. - focus_on_launch_terminal = false, -- Focus on cmake launch terminal when executable target in launched. + focus_on_launch_terminal = true, -- Focus on cmake launch terminal when executable target in launched. }, }, cmake_notifications = { - enabled = true, -- show cmake execution progress in nvim-notify + enabled = false, -- show cmake execution progress in nvim-notify spinner = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }, -- icons used for progress display refresh_rate_ms = 100, -- how often to iterate icons }, } + +local map = vim.keymap.set + +-- Mappings +map('n', 'b', ':CMakeBuild') +map('n', 'c', ':CMakeClose') +map('n', 'r', ':CMakeRun') + diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index 9d11505..fa1c230 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -9,6 +9,7 @@ return { 'nvim-tree/nvim-tree.lua', 'nvim-tree/nvim-web-devicons', 'Civitasv/cmake-tools.nvim', + 'rcarriga/nvim-notify', { 'numToStr/Comment.nvim', opts = {} }, { 'akinsho/bufferline.nvim', config = {} }, { 'ethanholz/nvim-lastplace', config = {} }, diff --git a/.config/nvim/lua/plugins/nvim-lspconfig.lua b/.config/nvim/lua/plugins/nvim-lspconfig.lua index d9782dc..8b84ac5 100644 --- a/.config/nvim/lua/plugins/nvim-lspconfig.lua +++ b/.config/nvim/lua/plugins/nvim-lspconfig.lua @@ -1,16 +1,11 @@ return { - -- LSP Configuration & Plugins 'neovim/nvim-lspconfig', dependencies = { - -- Automatically install LSPs to stdpath for neovim 'williamboman/mason.nvim', 'williamboman/mason-lspconfig.nvim', - -- Useful status updates for LSP - -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` { 'j-hui/fidget.nvim', opts = {} }, - -- Additional lua configuration, makes nvim stuff amazing! 'folke/neodev.nvim', }, }