Skip to content

Commit

Permalink
Improve deprecation checks
Browse files Browse the repository at this point in the history
- Move `layout_defaults` handling to `deprecated.lua`
- Check for "layout keys" outside of `layout_config` on `setup`
  • Loading branch information
l-kershaw committed Jun 25, 2021
1 parent eb62a0f commit be9944f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
14 changes: 5 additions & 9 deletions lua/telescope/config.lua
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion lua/telescope/deprecated.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit be9944f

Please sign in to comment.