Skip to content

Commit

Permalink
perf: setup legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 committed Jul 29, 2023
1 parent fcbdbbe commit ebbed25
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
7 changes: 7 additions & 0 deletions lua/fzfx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ local Configs = {}
local function setup(options)
Configs = vim.tbl_deep_extend("force", Defaults, options or {})

-- log
log.setup({
level = Configs.debug.enable and "DEBUG" or "INFO",
console_log = Configs.debug.console_log,
Expand All @@ -105,13 +106,19 @@ local function setup(options)
end
vim.env._FZFX_DEBUG = Configs.debug.enable

-- legacy
require("fzfx.legacy").setup()

-- files
require("fzfx.files").setup(
vim.tbl_deep_extend(
"force",
vim.deepcopy(Configs.files),
{ debug = Configs.debug.enable }
)
)

-- live_grep
require("fzfx.live_grep").setup(
vim.tbl_deep_extend(
"force",
Expand Down
51 changes: 29 additions & 22 deletions lua/fzfx/legacy.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
local log = require("fzfx.log")
local path = require("fzfx.path")

local Context = {
--- @type string|nil
fzf_autoload_sid = nil,
}

--- @alias VimScriptId string
--- @alias VimScriptPath string
--- @alias VimScriptIdInfoKey "script_id"|"script_path"
Expand Down Expand Up @@ -124,33 +129,35 @@ local function get_func_ref(sid, func_name)
return string.format("<SNR>%s_%s", tostring(sid), tostring(func_name))
end

-- vim.fn["fzf#vim#_uniq"]()
local fzf_autoload_sid = get_fzf_autoload_sid()
log.debug("|fzfx.legacy| fzf_autoload_sid:%s", fzf_autoload_sid)

--- @type table<string, any>
local M = {}

for color, hl in pairs({
black = "Comment",
red = "Exception",
green = "Constant",
yellow = "Number",
blue = "Operator",
magenta = "Special",
cyan = "String",
}) do
M[color] = function(text)
local snr = get_func_ref(fzf_autoload_sid --[[@as string]], color)
log.debug(
"|fzfx.legacy| color:%s, snr:%s",
vim.inspect(color),
vim.inspect(snr)
)
return vim.fn.call(vim.fn[snr], { text, hl })
local function setup()
Context.fzf_autoload_sid = get_fzf_autoload_sid()

for color, hl in pairs({
black = "Comment",
red = "Exception",
green = "Constant",
yellow = "Number",
blue = "Operator",
magenta = "Special",
cyan = "String",
}) do
M[color] = function(text)
local snr =
get_func_ref(Context.fzf_autoload_sid --[[@as string]], color)
log.debug(
"|fzfx.legacy| color:%s, snr:%s",
vim.inspect(color),
vim.inspect(snr)
)
return vim.fn.call(vim.fn[snr], { text, hl })
end
end
log.debug("|fzfx.legacy| Context:%s", vim.inspect(Context))
end

log.debug("|fzfx.legacy| %s", vim.inspect(M))
M.setup = setup

return M
5 changes: 5 additions & 0 deletions lua/fzfx/live_grep.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ local utils = require("fzfx.utils")
local path = require("fzfx.path")
local legacy = require("fzfx.legacy")

local Context = {
unrestricted_header = nil,
restricted_header = nil,
}

--- @param query string
--- @param fullscreen boolean|integer
--- @param opts Config
Expand Down

0 comments on commit ebbed25

Please sign in to comment.