Skip to content

Commit

Permalink
refactor!: make unsued util functions private
Browse files Browse the repository at this point in the history
If any public function is not used by any configuration, then we can
simply make them private. It is possible that there are external uses of
these functions, but a preliminary search indicated that usage is small
to non-existent.

Functions that are privatized:
- get_active_clients_list_by_ft
- get_config_by_ft
- get_managed_clients
- get_other_matching_providers

Work on neovim#2079.
  • Loading branch information
dundargoc committed Dec 23, 2024
1 parent c580f34 commit 3723b18
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 61 deletions.
34 changes: 33 additions & 1 deletion lua/lspconfig/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,38 @@ local function make_client_info(client, fname)
return table.concat(info_lines, '\n')
end

local function get_active_clients_list_by_ft(filetype)
local clients = M.get_lsp_clients()
local clients_list = {}
for _, client in pairs(clients) do
--- @diagnostic disable-next-line:undefined-field
local filetypes = client.config.filetypes or {}
for _, ft in pairs(filetypes) do
if ft == filetype then
table.insert(clients_list, client.name)
end
end
end
return clients_list
end

local function get_other_matching_providers(filetype)
local configs = require 'lspconfig.configs'
local active_clients_list = get_active_clients_list_by_ft(filetype)
local other_matching_configs = {}
for _, config in pairs(configs) do
if not vim.tbl_contains(active_clients_list, config.name) then
local filetypes = config.filetypes or {}
for _, ft in pairs(filetypes) do
if ft == filetype then
table.insert(other_matching_configs, config)
end
end
end
end
return other_matching_configs
end

local function check_lspconfig(bufnr)
bufnr = (bufnr and bufnr ~= -1) and bufnr or nil

Expand Down Expand Up @@ -267,7 +299,7 @@ local function check_lspconfig(bufnr)
end
end

local other_matching_configs = not bufnr and {} or util.get_other_matching_providers(buffer_filetype)
local other_matching_configs = not bufnr and {} or get_other_matching_providers(buffer_filetype)
if not vim.tbl_isempty(other_matching_configs) then
health.info(('Other clients that match the "%s" filetype:'):format(buffer_filetype))
for _, config in ipairs(other_matching_configs) do
Expand Down
57 changes: 0 additions & 57 deletions lua/lspconfig/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,52 +208,6 @@ function M.insert_package_json(config_files, field, fname)
return config_files
end

function M.get_active_clients_list_by_ft(filetype)
local clients = M.get_lsp_clients()
local clients_list = {}
for _, client in pairs(clients) do
--- @diagnostic disable-next-line:undefined-field
local filetypes = client.config.filetypes or {}
for _, ft in pairs(filetypes) do
if ft == filetype then
table.insert(clients_list, client.name)
end
end
end
return clients_list
end

function M.get_other_matching_providers(filetype)
local configs = require 'lspconfig.configs'
local active_clients_list = M.get_active_clients_list_by_ft(filetype)
local other_matching_configs = {}
for _, config in pairs(configs) do
if not vim.tbl_contains(active_clients_list, config.name) then
local filetypes = config.filetypes or {}
for _, ft in pairs(filetypes) do
if ft == filetype then
table.insert(other_matching_configs, config)
end
end
end
end
return other_matching_configs
end

function M.get_config_by_ft(filetype)
local configs = require 'lspconfig.configs'
local matching_configs = {}
for _, config in pairs(configs) do
local filetypes = config.filetypes or {}
for _, ft in pairs(filetypes) do
if ft == filetype then
table.insert(matching_configs, config)
end
end
end
return matching_configs
end

function M.get_active_client_by_name(bufnr, servername)
--TODO(glepnir): remove this for loop when we want only support 0.10+
for _, client in pairs(M.get_lsp_clients { bufnr = bufnr }) do
Expand All @@ -263,17 +217,6 @@ function M.get_active_client_by_name(bufnr, servername)
end
end

function M.get_managed_clients()
local configs = require 'lspconfig.configs'
local clients = {}
for _, config in pairs(configs) do
if config.manager then
vim.list_extend(clients, config.manager:clients())
end
end
return clients
end

function M.available_servers()
local servers = {}
local configs = require 'lspconfig.configs'
Expand Down
31 changes: 28 additions & 3 deletions plugin/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ local lsp_complete_configured_servers = function(arg)
end, util.available_servers()))
end

local function get_managed_clients()
local configs = require 'lspconfig.configs'
local clients = {}
for _, config in pairs(configs) do
if config.manager then
vim.list_extend(clients, config.manager:clients())
end
end
return clients
end

local lsp_get_active_clients = function(arg)
local clients = vim.tbl_map(function(client)
return ('%s'):format(client.name)
end, util.get_managed_clients())
end, get_managed_clients())

return completion_sort(vim.tbl_filter(function(s)
return s:sub(1, #arg) == arg
Expand All @@ -30,7 +41,7 @@ end
---@return vim.lsp.Client[] clients
local get_clients_from_cmd_args = function(arg)
local result = {}
local managed_clients = util.get_managed_clients()
local managed_clients = get_managed_clients()
local clients = {}
for _, client in pairs(managed_clients) do
clients[client.name] = client
Expand Down Expand Up @@ -63,6 +74,20 @@ local get_clients_from_cmd_args = function(arg)
return result
end

local function get_config_by_ft(filetype)
local configs = require 'lspconfig.configs'
local matching_configs = {}
for _, config in pairs(configs) do
local filetypes = config.filetypes or {}
for _, ft in pairs(filetypes) do
if ft == filetype then
table.insert(matching_configs, config)
end
end
end
return matching_configs
end

-- Called from plugin/lspconfig.vim because it requires knowing that the last
-- script in scriptnames to be executed is lspconfig.
api.nvim_create_user_command('LspInfo', ':che lspconfig', { desc = 'Deprecated alias to `:che lspconfig`' })
Expand All @@ -77,7 +102,7 @@ api.nvim_create_user_command('LspStart', function(info)
end
end

local matching_configs = util.get_config_by_ft(vim.bo.filetype)
local matching_configs = get_config_by_ft(vim.bo.filetype)
for _, config in ipairs(matching_configs) do
config.launch()
end
Expand Down

0 comments on commit 3723b18

Please sign in to comment.