From 462ded6ee3d80e4a84ec890a95b3140ba44aefe6 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 5 Apr 2025 16:36:39 -0700 Subject: refactor: deprecate add_hook_before/after #3695 These are special-purpose functions that should never have been "public". --- doc/lspconfig.txt | 22 ---------------------- lua/lspconfig/util.lua | 50 ++++++++++++++++++++++++++------------------------ 2 files changed, 26 insertions(+), 46 deletions(-) diff --git a/doc/lspconfig.txt b/doc/lspconfig.txt index c2f02a8b..b38d9038 100644 --- a/doc/lspconfig.txt +++ b/doc/lspconfig.txt @@ -148,28 +148,6 @@ The global defaults for all servers can be overridden by extending the ) < -============================================================================== -SETUP HOOK *lspconfig-setup-hook* - -`lspconfig` will execute the `on_setup` hook for each setup call to a server after -validating its configuration, and before attempting to launch the server -itself. One typical usage is to allow ad-hoc substitution for any -configuration entry, such as `cmd`. - ->lua - local lspconfig = require 'lspconfig' - lspconfig.util.on_setup = lspconfig.util.add_hook_before(lspconfig.util.on_setup, function(config) - if some_condition and config.name == "clangd" then - local custom_server_prefix = "/my/custom/server/prefix" - config.cmd = { custom_server_prefix .. "/bin/clangd" } - end - end) - - -Note: This is primarily targeted at plugins developers, so make sure to use -`util.add_hook_before()` as a wrapper instead of overriding the original function -completely, to void breaking external integrations with lspconfig. - ============================================================================== SERVER CONFIGS *lspconfig-configurations* diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 0e4ab120..0935ec40 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -34,30 +34,6 @@ function M.validate_bufnr(bufnr) return bufnr == 0 and api.nvim_get_current_buf() or bufnr end -function M.add_hook_before(func, new_fn) - if func then - return function(...) - -- TODO which result? - new_fn(...) - return func(...) - end - else - return new_fn - end -end - -function M.add_hook_after(func, new_fn) - if func then - return function(...) - -- TODO which result? - func(...) - return new_fn(...) - end - else - return new_fn - end -end - -- Maps lspconfig-style command options to nvim_create_user_command (i.e. |command-attributes|) option names. local opts_aliases = { ['description'] = 'desc', @@ -367,4 +343,30 @@ function M.get_lsp_clients(filter) return nvim_eleven and lsp.get_clients(filter) or lsp.get_active_clients(filter) end +--- @deprecated Will be removed. Do not use. +function M.add_hook_before(func, new_fn) + if func then + return function(...) + -- TODO which result? + new_fn(...) + return func(...) + end + else + return new_fn + end +end + +--- @deprecated Will be removed. Do not use. +function M.add_hook_after(func, new_fn) + if func then + return function(...) + -- TODO which result? + func(...) + return new_fn(...) + end + else + return new_fn + end +end + return M -- cgit v1.2.3-70-g09d2