From be9944f92af8794a1f9dfd40c3e6e1790d7a3b0b Mon Sep 17 00:00:00 2001 From: Luke Kershaw <35707277+l-kershaw@users.noreply.github.com> Date: Fri, 25 Jun 2021 16:58:52 +0100 Subject: [PATCH] Improve deprecation checks - Move `layout_defaults` handling to `deprecated.lua` - Check for "layout keys" outside of `layout_config` on `setup` --- lua/telescope/config.lua | 14 +++++--------- lua/telescope/deprecated.lua | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index 7cc659208a..9f84de6366 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -1,5 +1,5 @@ local strings = require "plenary.strings" -local log = require "telescope.log" +local deprecated = require "telescope.deprecated" local sorters = require "telescope.sorters" local if_nil = vim.F.if_nil @@ -308,14 +308,10 @@ function config.set_defaults(user_defaults, tele_defaults) user_defaults = if_nil(user_defaults, {}) tele_defaults = if_nil(tele_defaults, telescope_defaults) - if user_defaults.layout_defaults then - if user_defaults.layout_config == nil then - log.info "Using 'layout_defaults' in setup() is deprecated. Use 'layout_config' instead." - user_defaults.layout_config = user_defaults.layout_defaults - else - error "Using 'layout_defaults' in setup() is deprecated. Remove this key and use 'layout_config' instead." - end - end + -- Check if using layout keywords outside of `layout_config` + deprecated.picker_window_options(user_defaults) + -- Check if using `layout_defaults` instead of `layout_config` + user_defaults = deprecated.layout_configuration(user_defaults) local function get(name, default_val) if name == "layout_config" then diff --git a/lua/telescope/deprecated.lua b/lua/telescope/deprecated.lua index f1748a18b0..0d98c1d349 100644 --- a/lua/telescope/deprecated.lua +++ b/lua/telescope/deprecated.lua @@ -1,10 +1,11 @@ +local log = require "telescope.log" local deprecated = {} deprecated.picker_window_options = function(opts) local messages = {} - -- Deprecated: PR:922, 2021/05/17 + -- Deprecated: PR:922, 2021/06/25 -- Can be removed in a few weeks. if opts.width then @@ -43,4 +44,16 @@ deprecated.picker_window_options = function(opts) end end +deprecated.layout_configuration = function(user_defaults) + if user_defaults.layout_defaults then + if user_defaults.layout_config == nil then + log.warn "Using 'layout_defaults' in setup() is deprecated. Use 'layout_config' instead." + user_defaults.layout_config = user_defaults.layout_defaults + else + error "Using 'layout_defaults' in setup() is deprecated. Remove this key and use 'layout_config' instead." + end + end + return user_defaults +end + return deprecated