Skip to content

Commit

Permalink
fix: packer.nvim (#111)
Browse files Browse the repository at this point in the history
* perf: configs

* test: packer.nvim

* test: packer.nvim

* fix: packer.nvim

* lint: typecheck

* doc: fix packer.nvim
  • Loading branch information
linrongbin16 authored Aug 28, 2023
1 parent b6a7857 commit a05793a
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 26 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ return require('packer').startup(function(use)
use { "junegunn/fzf", run = ":call fzf#install()" }
use {
"linrongbin16/fzfx.nvim",
requires = { "junegunn/fzf" },
config = function()
require("fzfx").setup()
end
Expand Down
40 changes: 18 additions & 22 deletions lua/fzfx/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ local function echo_msg(msg, level)
vim.api.nvim_echo(msg_chunks, false, {})
end

--- @class GroupConfig
--- @field commands UserCommandConfig[]
--- @field providers table<PipelineName, ProviderConfig>
--- @field previewers table<PipelineName, PreviewerConfig>
--- @field interactions table<ActionKey, Interaction>?
--- @field actions table<ActionKey, Action>
--- @field fzf_opts FzfOpt[]

--- @class ProviderConfig
--- @field key ActionKey
--- @field provider Provider
Expand All @@ -107,11 +115,18 @@ end
--- @field previewer Previewer
--- @field previewer_type PreviewerType

--- @class UserCommandConfig
--- @field name string
--- @field feed CommandFeed
--- @field opts CommandOpt
--- @field default_provider PipelineName?

--- @alias Configs table<string, any>
--- @type Configs
local Defaults = {
-- the 'Files' commands
files = {
--- @type UserCommandConfig[]
commands = {
-- normal
{
Expand Down Expand Up @@ -239,6 +254,7 @@ local Defaults = {

-- the 'Live Grep' commands
live_grep = {
--- @type UserCommandConfig[]
commands = {
-- normal
{
Expand Down Expand Up @@ -615,6 +631,7 @@ local Defaults = {
},

-- the 'Git Commits' commands
--- @type GroupConfig
git_commits = {
commands = {
-- normal
Expand Down Expand Up @@ -699,24 +716,15 @@ local Defaults = {
},
},
providers = {
--- @type ProviderConfig
all_commits = {
--- @type ActionKey
key = "ctrl-a",
--- @type PlainProvider
provider = string.format(
"git log --pretty=%s --date=short --color=always",
utils.shellescape(default_git_log_pretty)
),
},
--- @type ProviderConfig
buffer_commits = {
--- @type ActionKey
key = "ctrl-u",
--- @type CommandProvider
--- @param query string?
--- @param context PipelineContext
--- @return string?
provider = function(query, context)
if not utils.is_buf_valid(context.bufnr) then
echo_msg(
Expand All @@ -738,18 +746,14 @@ local Defaults = {
},
},
previewers = {
--- @type PreviewerConfig
all_commits = {
--- @type CommandPreviewer
previewer = function(line)
local commit = vim.fn.split(line)[1]
return string.format("git show --color=always %s", commit)
end,
previewer_type = PreviewerTypeEnum.COMMAND,
},
--- @type PreviewerConfig
buffer_commits = {
--- @type CommandPreviewer
previewer = function(line)
local commit = vim.fn.split(line)[1]
return string.format("git show --color=always %s", commit)
Expand All @@ -775,6 +779,7 @@ local Defaults = {
},

-- the 'Git Blame' command
--- @type GroupConfig
git_blame = {
commands = {
-- normal
Expand Down Expand Up @@ -817,14 +822,8 @@ local Defaults = {
},
},
providers = {
--- @type ProviderConfig
default = {
--- @type ActionKey
key = "default",
--- @type CommandProvider
--- @param query string?
--- @param context PipelineContext
--- @return string
provider = function(query, context)
if not utils.is_buf_valid(context.bufnr) then
echo_msg(
Expand All @@ -843,14 +842,11 @@ local Defaults = {
bufpath
)
end,
--- @type ProviderType
provider_type = ProviderTypeEnum.COMMAND,
},
},
previewers = {
--- @type PreviewerConfig
default = {
--- @type CommandPreviewer
previewer = function(line)
local commit = vim.fn.split(line)[1]
return string.format("git show --color=always %s", commit)
Expand Down
4 changes: 1 addition & 3 deletions lua/fzfx/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ local function search_module_path(plugin, path)
)
return nil
end
local rtp = type(vim.o.runtimepath) == "string"
and vim.fn.split(vim.o.runtimepath, ",")
or {}
local rtp = vim.api.nvim_list_runtime_paths()
for i, p in ipairs(rtp) do
log.debug("|fzfx.module - search_module_path| p[%d]:%s", i, p)
if type(p) == "string" and string.match(p, path) then
Expand Down
25 changes: 25 additions & 0 deletions lua/fzfx/object.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- @class Object
--- @field __class string

local Object = {
__class = "object",
}

--- @param classname string?
function Object:new(classname)
return vim.tbl_deep_extend("force", vim.deepcopy(Object), {
__class = classname or "object",
})
end

--- @param o any?
--- @return boolean
function Object:instanceof(o)
return type(o) == "table" and o.__class == self.__class
end

local M = {
Object = Object,
}

return M
50 changes: 50 additions & 0 deletions lua/tests/minimal_packer_nvim_init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
vim.o.number = true
vim.o.autoread = true
vim.o.autowrite = true
vim.o.swapfile = false
vim.o.confirm = true
vim.o.termguicolors = true

local ensure_packer = function()
local fn = vim.fn
local install_path = fn.stdpath("data")
.. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({
"git",
"clone",
"--depth",
"1",
"https://github.com/wbthomason/packer.nvim",
install_path,
})
vim.cmd([[packadd packer.nvim]])
return true
end
return false
end

local packer_bootstrap = ensure_packer()

require("packer").startup(function(use)
use("wbthomason/packer.nvim")
use("folke/tokyonight.nvim")
use("nvim-tree/nvim-web-devicons")
use({ "junegunn/fzf", run = ":call fzf#install()" })
use({
vim.fn.expand("~/github/linrongbin16/fzfx.nvim"),
config = function()
require("fzfx").setup({
debug = { enable = true, file_log = true },
})
end,
})

if packer_bootstrap then
require("packer").sync()
end
end)

vim.cmd([[
colorscheme tokyonight
]])

0 comments on commit a05793a

Please sign in to comment.