From 72fef12c297838e5af8f4bfdf6770e1a562af574 Mon Sep 17 00:00:00 2001 From: Wesley Irvin Date: Sun, 4 Aug 2024 21:03:03 -0400 Subject: [PATCH] LSP Integration Integrated LSP functionality into neovim configurations. Installed Mason to manage the installation of language servers. Used mason-lspconfig for the bridge between Mason and nvim-lspconfig. Also installed telescope-ui-select plugin to telescope to allow it to use telescope and it's windows for code actions. --- .gitignore | 1 + .../nvim/lua/plugins/lsp-config.lua | 39 +++++++++++++++ .../dot-config/nvim/lua/plugins/telescope.lua | 49 ++++++++++++++++--- 3 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 nvim/dot-config/nvim/lua/plugins/lsp-config.lua diff --git a/.gitignore b/.gitignore index 9c11390..099419a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ nvim/dot-config/nvim/lazy-lock.json +nvim/dot-config/nvim/.luarc.json diff --git a/nvim/dot-config/nvim/lua/plugins/lsp-config.lua b/nvim/dot-config/nvim/lua/plugins/lsp-config.lua new file mode 100644 index 0000000..645de15 --- /dev/null +++ b/nvim/dot-config/nvim/lua/plugins/lsp-config.lua @@ -0,0 +1,39 @@ +return { + { + "williamboman/mason.nvim", + config = function () + require("mason").setup() + end + }, + { + "williamboman/mason-lspconfig.nvim", + config = function () + require("mason-lspconfig").setup({ + ensure_installed = { + "clangd", + "cmake", + "lua_ls", + "pyright", + "rust_analyzer", + "taplo", + } + }) + end + }, + { + "neovim/nvim-lspconfig", + config = function() + local lspconfig = require("lspconfig") + lspconfig.clangd.setup({}) + lspconfig.cmake.setup({}) + lspconfig.lua_ls.setup({}) + lspconfig.pyright.setup({}) + lspconfig.rust_analyzer.setup({}) + lspconfig.taplo.setup({}) + + vim.keymap.set('n', 'K', vim.lsp.buf.hover, {}) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {}) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, {}) + end + }, +} diff --git a/nvim/dot-config/nvim/lua/plugins/telescope.lua b/nvim/dot-config/nvim/lua/plugins/telescope.lua index 2b34e1f..22e4660 100644 --- a/nvim/dot-config/nvim/lua/plugins/telescope.lua +++ b/nvim/dot-config/nvim/lua/plugins/telescope.lua @@ -1,10 +1,43 @@ return { - 'nvim-telescope/telescope.nvim', - branch = '0.1.x', - dependencies = { 'nvim-lua/plenary.nvim' }, - config = function() - local builtin = require('telescope.builtin') - vim.keymap.set('n', '', builtin.find_files, {}) - vim.keymap.set('n', 'fg', builtin.live_grep, {}) - end + { + 'nvim-telescope/telescope.nvim', + branch = '0.1.x', + dependencies = { 'nvim-lua/plenary.nvim' }, + config = function() + local builtin = require('telescope.builtin') + vim.keymap.set('n', '', builtin.find_files, {}) + vim.keymap.set('n', 'fg', builtin.live_grep, {}) + end + }, + { + 'nvim-telescope/telescope-ui-select.nvim', + config = function () + -- This is your opts table + require("telescope").setup { + extensions = { + ["ui-select"] = { + require("telescope.themes").get_dropdown { + -- even more opts + } + -- pseudo code / specification for writing custom displays, like the one + -- for "codeactions" + -- specific_opts = { + -- [kind] = { + -- make_indexed = function(items) -> indexed_items, width, + -- make_displayer = function(widths) -> displayer + -- make_display = function(displayer) -> function(e) + -- make_ordinal = function(e) -> string + -- }, + -- -- for example to disable the custom builtin "codeactions" display + -- do the following + -- codeactions = false, + -- } + } + } + } + -- To get ui-select loaded and working with telescope, you need to call + -- load_extension, somewhere after setup function: + require("telescope").load_extension("ui-select") + end + } }