aboutsummaryrefslogtreecommitdiffstats
path: root/modules/tools/editor/neovim/plugins/config/lsp-config.lua
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2024-10-01 00:45:02 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2024-10-01 00:45:02 +0530
commit9dc8cc8176be54df0d9ff4e7ef904e619deea3c2 (patch)
tree9f03e241cd286c361c6f50a14c2adb60d6615353 /modules/tools/editor/neovim/plugins/config/lsp-config.lua
parent5f8027fef5ab482be9275aa310ac22dd1d414159 (diff)
downloadhome-manager-config-9dc8cc8176be54df0d9ff4e7ef904e619deea3c2.tar.gz
home-manager-config-9dc8cc8176be54df0d9ff4e7ef904e619deea3c2.zip
Added a minimal and full configuration settings to neovim.
Added language server support for the full neovim configuration.
Diffstat (limited to 'modules/tools/editor/neovim/plugins/config/lsp-config.lua')
-rw-r--r--modules/tools/editor/neovim/plugins/config/lsp-config.lua51
1 files changed, 51 insertions, 0 deletions
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", "<C-c>", 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,
+});