Skip to content

Commit

Permalink
fix: centralize lsp config function
Browse files Browse the repository at this point in the history
`get_server_config` now accept a name or an index
  • Loading branch information
mike325 committed Jan 15, 2025
1 parent 8bad56d commit 92d6238
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion after/plugin/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if not nvim.plugins['nvim-lspconfig'] then

local server_idx = utils.check_language_server(ft)
if server_idx then
local server = RELOAD('configs.lsp.servers')[ft][server_idx]
local server = utils.get_server_config(ft, server_idx)
table.insert(servers, setup_server(server))
if ft == 'python' and vim.fs.basename(utils.get_name(server)) ~= 'ruff' and nvim.executable 'ruff' then
server = utils.get_server_config(ft, 'ruff')
Expand Down
6 changes: 3 additions & 3 deletions lua/configs/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if not lsp then
return false
end

local lsp_configs = require 'configs.lsp.servers'
local langservers = require 'configs.lsp.servers'
local nvim = require 'nvim'
local executable = require('utils.files').executable

Expand Down Expand Up @@ -62,7 +62,7 @@ local function setup(ft)
local server_idx = utils.check_language_server(ft)

if server_idx then
local server = RELOAD('configs.lsp.servers')[ft][server_idx]
local server = utils.get_server_config(ft, server_idx)
config_lsp(server)
-- NOTE: Always setup ruff in lsp mode
if ft == 'python' and vim.fs.basename(utils.get_name(server)) ~= 'ruff' and nvim.executable 'ruff' then
Expand All @@ -82,7 +82,7 @@ if null_ls and pcall(require, 'gitsigns') then
table.insert(null_sources, null_ls.builtins.code_actions.gitsigns)
end

for filetype, _ in pairs(lsp_configs) do
for filetype, _ in pairs(langservers) do
local has_server = setup(filetype)
local null_config = null_configs[filetype]

Expand Down
26 changes: 15 additions & 11 deletions lua/configs/lsp/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ end
function M.get_server_config(lang, name)
vim.validate {
lang = { lang, 'string' },
name = { name, 'string' },
name = { name, { 'string', 'number' } },
}

local configs = {
Expand All @@ -90,20 +90,24 @@ function M.get_server_config(lang, name)
}

if langservers[lang] then
for _, server in ipairs(langservers[lang]) do
if server.exec == name or server.config == name then
if configs[name] then
local config = configs[name]
local path = vim.fs.find(config, { upward = true, type = 'file' })[1]
if path then
if not server.cmd then
server.cmd = { server.exec or server.config }
if type(name) == type '' then
for _, server in ipairs(langservers[lang]) do
if server.exec == name or server.config == name then
if configs[name] then
local config = configs[name]
local path = vim.fs.find(config, { upward = true, type = 'file' })[1]
if path then
if not server.cmd then
server.cmd = { server.exec or server.config }
end
vim.list_extend(server.cmd, { '--config', path })
end
vim.list_extend(server.cmd, { '--config', path })
end
return server
end
return server
end
else
return langservers[lang][name] or false
end
end
return false
Expand Down

0 comments on commit 92d6238

Please sign in to comment.