From 9dc8cc8176be54df0d9ff4e7ef904e619deea3c2 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Tue, 1 Oct 2024 00:45:02 +0530 Subject: Added a minimal and full configuration settings to neovim. Added language server support for the full neovim configuration. --- .../editor/neovim/plugins/config/lsp-config.lua | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 modules/tools/editor/neovim/plugins/config/lsp-config.lua (limited to 'modules/tools/editor/neovim/plugins/config/lsp-config.lua') diff --git a/modules/tools/editor/neovim/plugins/config/lsp-config.lua b/modules/tools/editor/neovim/plugins/config/lsp-config.lua new file mode 100644 index 0000000..43cdb95 --- /dev/null +++ b/modules/tools/editor/neovim/plugins/config/lsp-config.lua @@ -0,0 +1,51 @@ +local lspconfig = require("lspconfig"); + +local filetype_to_lsp = { + lua = "lua_ls", + cpp = "clangd", + c = "clangd", + python = "pyright", + javascript = "tsserver", + typescript = "tsserver", + go = "gopls", + html = "html", + css = "cssls", + json = "jsonls", + bash = "bashls", + graphql = "graphql", + dockerfile = "dockerls", + php = "phpactor", + rust = "rust_analyzer", + haskell = "hls", + deno = "denols", + vim = "vimls", + elixir = "elixirls", + clojure = "clojure_lsp", + scala = "scala_metals", + ruby = "sorbet", +}; + +-- Keeping track of all the lsps that have been already configured +local lsp_setup_done = {}; + +-- Function to setup LSP based on filetype +local function setup_lsp(filetype) + local lsp_server = filetype_to_lsp[filetype]; + if lsp_server and not lsp_setup_done[lsp_server] then + lsp_setup_done[lsp_server] = true; + lspconfig[lsp_server].setup({}); + end +end + +vim.keymap.set("n", "gd", vim.lsp.buf.definition, { noremap = true, silent = true }); +vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { noremap = true, silent = true }); +vim.keymap.set("n", "gr", vim.lsp.buf.references, { noremap = true, silent = true }); +vim.keymap.set("i", "", vim.lsp.buf.completion, { noremap = true, silent = true }); +vim.keymap.set("n", "gk", vim.lsp.buf.hover, { noremap = true, silent = true }); + +vim.api.nvim_create_autocmd("FileType", { + pattern = "*", -- Match all file types + callback = function() + setup_lsp(vim.bo.filetype); -- Call the setup_lsp function only if the filetype is in the mapping + end, +}); -- cgit v1.2.3