From 0b39fbff53a3147fbad63d59b3df3dd203e46085 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 23 Dec 2024 14:10:59 +0100 Subject: [PATCH] refactor!: make unsued util functions private 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 Work on https://github.com/neovim/nvim-lspconfig/issues/2079. --- lua/lspconfig/util.lua | 18 ++---------------- plugin/lspconfig.lua | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index e2bba2e19c..e517d798fa 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -208,7 +208,7 @@ function M.insert_package_json(config_files, field, fname) return config_files end -function M.get_active_clients_list_by_ft(filetype) +local function get_active_clients_list_by_ft(filetype) local clients = M.get_lsp_clients() local clients_list = {} for _, client in pairs(clients) do @@ -225,7 +225,7 @@ 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 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 @@ -240,20 +240,6 @@ function M.get_other_matching_providers(filetype) 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 diff --git a/plugin/lspconfig.lua b/plugin/lspconfig.lua index 0283d84732..4e3886295f 100644 --- a/plugin/lspconfig.lua +++ b/plugin/lspconfig.lua @@ -63,6 +63,21 @@ 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`' }) @@ -77,7 +92,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