Skip to content

Commit

Permalink
lsp: settings autosetup after downlaod
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Lobpreis <[email protected]>
  • Loading branch information
Filip Lobpreis committed Aug 18, 2024
1 parent 40cf644 commit f0902d7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 74 deletions.
1 change: 0 additions & 1 deletion lua/usr/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

92 changes: 19 additions & 73 deletions lua/usr/lsp/lsp-installer.lua
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions lua/usr/lsp/settings/init.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f0902d7

Please sign in to comment.