Skip to content

Commit

Permalink
perf(config): migrate to provider decorators (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 authored Dec 8, 2023
1 parent 32599cd commit f825f32
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 68 deletions.
3 changes: 0 additions & 3 deletions bin/general/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ if metaopts.provider_decorator ~= nil then
vim.inspect(metaopts.provider_decorator)
)
local module_name = metaopts.provider_decorator.module
if metaopts.provider_decorator.builtin then
module_name = "fzfx.helper.provider_decorators." .. module_name
end
local ok, module_or_err = pcall(require, module_name)
shell_helpers.log_ensure(
ok and tbls.tbl_not_empty(module_or_err),
Expand Down
2 changes: 1 addition & 1 deletion lua/fzfx/cfg/buffers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ M.providers = {
key = "default",
provider = M._buffers_provider,
provider_type = ProviderTypeEnum.LIST,
line_opts = { prepend_icon_by_ft = true },
provider_decorator = { module = "prepend_icon_find", builtin = true },
}

M.previewers = {
Expand Down
4 changes: 2 additions & 2 deletions lua/fzfx/cfg/git_files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ M.providers = {
key = "ctrl-u",
provider = current_folder_provider,
provider_type = ProviderTypeEnum.COMMAND_LIST,
line_opts = { prepend_icon_by_ft = true },
provider_decorator = { module = "prepend_icon_find", builtin = true },
},
workspace = {
key = "ctrl-w",
provider = workspace_provider,
provider_type = ProviderTypeEnum.COMMAND_LIST,
line_opts = { prepend_icon_by_ft = true },
provider_decorator = { module = "prepend_icon_find", builtin = true },
},
}

Expand Down
6 changes: 1 addition & 5 deletions lua/fzfx/cfg/git_live_grep.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ M.providers = {
key = "default",
provider = M._git_live_grep_provider,
provider_type = ProviderTypeEnum.COMMAND_LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
}

M.previewers = {
Expand Down
18 changes: 3 additions & 15 deletions lua/fzfx/cfg/live_grep.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,31 +297,19 @@ M.providers = {
key = "ctrl-r",
provider = restricted_provider,
provider_type = ProviderTypeEnum.COMMAND_LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
},
unrestricted_mode = {
key = "ctrl-u",
provider = unrestricted_provider,
provider_type = ProviderTypeEnum.COMMAND_LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
},
buffer_mode = {
key = "ctrl-o",
provider = buffer_provider,
provider_type = ProviderTypeEnum.COMMAND_LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
},
}

Expand Down
6 changes: 1 addition & 5 deletions lua/fzfx/cfg/lsp_definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ M.providers = {
capability = "definitionProvider",
}),
provider_type = ProviderTypeEnum.LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
}

M.fzf_opts = {
Expand Down
12 changes: 2 additions & 10 deletions lua/fzfx/cfg/lsp_diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,13 @@ M.providers = {
key = "ctrl-w",
provider = M._make_lsp_diagnostics_provider(),
provider_type = ProviderTypeEnum.LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
},
buffer_diagnostics = {
key = "ctrl-u",
provider = M._make_lsp_diagnostics_provider({ buffer = true }),
provider_type = ProviderTypeEnum.LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
},
}

Expand Down
6 changes: 1 addition & 5 deletions lua/fzfx/cfg/lsp_implementations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ M.providers = {
capability = "implementationProvider",
}),
provider_type = ProviderTypeEnum.LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
}

M.previewers = _lsp_locations.previewers
Expand Down
6 changes: 1 addition & 5 deletions lua/fzfx/cfg/lsp_incoming_calls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ M.providers = {
capability = "callHierarchyProvider",
}),
provider_type = ProviderTypeEnum.LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
}

M.fzf_opts = {
Expand Down
6 changes: 1 addition & 5 deletions lua/fzfx/cfg/lsp_outgoing_calls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ M.providers = {
capability = "callHierarchyProvider",
}),
provider_type = ProviderTypeEnum.LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
}

M.previewers = _lsp_locations.previewers
Expand Down
6 changes: 1 addition & 5 deletions lua/fzfx/cfg/lsp_references.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ M.providers = {
capability = "referencesProvider",
}),
provider_type = ProviderTypeEnum.LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
}

M.fzf_opts = {
Expand Down
6 changes: 1 addition & 5 deletions lua/fzfx/cfg/lsp_type_definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ M.providers = {
capability = "typeDefinitionProvider",
}),
provider_type = ProviderTypeEnum.LIST,
line_opts = {
prepend_icon_by_ft = true,
prepend_icon_path_delimiter = ":",
prepend_icon_path_position = 1,
},
provider_decorator = { module = "prepend_icon_grep", builtin = true },
}

M.fzf_opts = {
Expand Down
6 changes: 5 additions & 1 deletion lua/fzfx/detail/general.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ local function make_provider_meta_opts(pipeline, provider_config)

-- provider_decorator
if tbls.tbl_get(provider_config, "provider_decorator") then
o.provider_decorator = provider_config.provider_decorator
o.provider_decorator = vim.deepcopy(provider_config.provider_decorator)
if o.provider_decorator.builtin then
o.provider_decorator.module = "fzfx.helper.provider_decorators."
.. o.provider_decorator.module
end
end

return o
Expand Down
2 changes: 1 addition & 1 deletion lua/fzfx/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ local ProviderTypeEnum = {
-- ========== Provider Decorator ==========
--
--- @alias fzfx._FunctionProviderDecorator fun(line:string?):string?
--- @alias fzfx.ProviderDecorator string|{module:string,rtp:string?,builtin:boolean?}
--- @alias fzfx.ProviderDecorator {module:string,rtp:string?,builtin:boolean?}
--
-- Note: in `fzfx._FunctionProviderDecorator`, the 1st parameter `line` is the raw generated line from providers.
--
Expand Down

0 comments on commit f825f32

Please sign in to comment.