From 00883a477b5353b09eeb99bb0f8ba75416745712 Mon Sep 17 00:00:00 2001 From: Iordanis Petkakis <12776461+dpetka2001@users.noreply.github.com> Date: Fri, 18 Apr 2025 10:16:51 +0300 Subject: [PATCH] Make conditional check top-level Thanks to Echasnovski (a Reddit comment he made) to avoid having the conditional inside the function body and be executed every time the function is called. --- lua/lazyvim/util/lsp.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/util/lsp.lua b/lua/lazyvim/util/lsp.lua index 3d8c5be1..01aca62e 100644 --- a/lua/lazyvim/util/lsp.lua +++ b/lua/lazyvim/util/lsp.lua @@ -5,10 +5,12 @@ local M = {} ---@param method string ---@param bufnr? integer local function supports_method(client, method, bufnr) - if vim.fn.has("nvim-0.11") == 0 then + return client:supports_method(method, bufnr) +end +if vim.fn.has("nvim-0.11") == 0 then + function supports_method(client, method, bufnr) return client.supports_method and client.supports_method(method, { bufnr = bufnr }) end - return client:supports_method(method, bufnr) and client:supports_method(method, bufnr) end ---@alias lsp.Client.filter {id?: number, bufnr?: number, name?: string, method?: string, filter?:fun(client: lsp.Client):boolean}