diff --git a/lua/usr/lsp/init.lua b/lua/usr/lsp/init.lua index 80f23d2..56ba3f4 100644 --- a/lua/usr/lsp/init.lua +++ b/lua/usr/lsp/init.lua @@ -5,5 +5,4 @@ require("usr.lsp.handlers").setup() require("usr.lsp.semantic") require("usr.lsp.signature") require("usr.lsp.null_ls") -vim.cmd("source " .. os.getenv("HOME") .. "/.config/nvim/lua/usr/lsp/settings/vimlatex.vim") diff --git a/lua/usr/lsp/lsp-installer.lua b/lua/usr/lsp/lsp-installer.lua index 2876d87..1a52ff7 100644 --- a/lua/usr/lsp/lsp-installer.lua +++ b/lua/usr/lsp/lsp-installer.lua @@ -1,88 +1,34 @@ local lspconfig = require("lspconfig") +local settings = require("usr.lsp.settings") local M = {} -M.servers = { - "bashls", - "clangd", - "cmake", - "jsonls", - "lemminx", - "marksman", - "pyright", - "lua_ls", - "texlab", - "tsserver", - "vimls", - "yamlls", - "matlab_ls", - "gopls", -} - -function M.setup() - for _, server in pairs(M.servers) do - opts = { +local function setup_lua_settings() + for _, name in pairs(settings.installed) do + local opts = { on_attach = require("usr.lsp.handlers").on_attach, capabilities = require("usr.lsp.handlers").capabilities, } - if server == "bashls" then - local bash_opts = require("usr.lsp.settings.bash") - opts = vim.tbl_deep_extend("force", bash_opts, opts) - end - - if server == "clangd" then - local clangd_opts = require("usr.lsp.settings.clangd") - opts = vim.tbl_deep_extend("force", clangd_opts, opts) - end - - if server == "cmake" then - local cmake_opts = require("usr.lsp.settings.cmake") - opts = vim.tbl_deep_extend("force", cmake_opts, opts) - end - - if server == "jsonls" then - local jsonls_opts = require("usr.lsp.settings.jsonls") - opts = vim.tbl_deep_extend("force", jsonls_opts, opts) - end - - if server == "lua_ls" then - local lua_opts = require("usr.lsp.settings.lua_ls") - opts = vim.tbl_deep_extend("force", lua_opts, opts) - end - - if server == "pyright" then - local pyright_opts = require("usr.lsp.settings.pyright") - opts = vim.tbl_deep_extend("force", pyright_opts, opts) - end - - if server == "lemminx" then - local xml_opts = require("usr.lsp.settings.lemminx") - opts = vim.tbl_deep_extend("force", xml_opts, opts) - end - - if server == "texlab" then - local latex_opts = require("usr.lsp.settings.texlab") - opts = vim.tbl_deep_extend("force", latex_opts, opts) - end - - if server == "yamlls" then - local yaml_opts = {} -- require("usr.lsp.serrings.yamlls") - opts = vim.tbl_deep_extend("force", yaml_opts, opts) - end - - if server == "matlab_ls" then - local matlab_opts = require("usr.lsp.settings.matlabls") - opts = vim.tbl_deep_extend("force", matlab_opts, opts) + local setting = settings.lua[name] + if not setting then + setting = require("lspconfig.server_configurations." .. name) end - if server == "gopls" then - local go_opts = require("usr.lsp.settings.go") - opts = vim.tbl_deep_extend("force", go_opts, opts) - end + opts = vim.tbl_deep_extend("force", opts, setting) + lspconfig[name].setup(opts) + end +end - lspconfig[server].setup(opts) +local function setup_vim_settings() + for name, _ in pairs(settings.vim) do + vim.cmd("source " .. os.getenv("HOME") .. "/.config/nvim/lua/usr/lsp/settings/" .. name .. ".vim") end end +function M.setup() + setup_lua_settings() + setup_vim_settings() +end + return M diff --git a/lua/usr/lsp/settings/init.lua b/lua/usr/lsp/settings/init.lua new file mode 100644 index 0000000..af6bed7 --- /dev/null +++ b/lua/usr/lsp/settings/init.lua @@ -0,0 +1,35 @@ +local current_path = vim.fn.expand("%") + +-- Find file in a input direcotory supplied into a function +local function find_file_in_dir(dir, file) + local file_path = dir .. "/" .. file + local f = io.open(file_path, "r") + if f ~= nil then + io.close(f) + return file_path + end + return nil +end + +local M = { + installed = require("mason-lspconfig").get_installed_servers(), + lua = { + -- WARN: The conde in current for requires that the name in the table must be the name of the lsp. + -- At the same time the setting file does not need to have the same name as the lsp. + bashls = require("usr.lsp.settings.bash"), + clangd = require("usr.lsp.settings.clangd"), + cmake = require("usr.lsp.settings.cmake"), + gopls = require("usr.lsp.settings.go"), + jsonls = require("usr.lsp.settings.jsonls"), + lemminx = require("usr.lsp.settings.lemminx"), + lua_ls = require("usr.lsp.settings.lua_ls"), + pyright = require("usr.lsp.settings.pyright"), + texlab = require("usr.lsp.settings.texlab"), + yamlls = require("lspconfig.server_configurations.yamlls"), + }, + vim = { + vimlatex = find_file_in_dir(current_path, "vimlatex.vim"), + } +} + +return M