Skip to content

Commit

Permalink
perf(log): migrate to 'lib.log' (#447)
Browse files Browse the repository at this point in the history
perf(yanks): migrate to 'detail.yanks'


docs(fix): remove broken 'findutils' from scoop for Windows
  • Loading branch information
linrongbin16 authored Dec 5, 2023
1 parent 7fcc3d8 commit bbd1d9d
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 179 deletions.
1 change: 1 addition & 0 deletions .luacov
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
modules = {
["fzfx"] = "lua/fzfx.lua",
["fzfx.*"] = "lua",
["fzfx.*.*"] = "lua",
}
exclude = {
"lua/fzfx/lib/actboy168_json.lua",
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Install with the below 3 options:

<img alt="install-windows-git3.png" src="https://raw.githubusercontent.com/linrongbin16/lin.nvim.dev/main/assets/installations/install-windows-git3.png" width="70%" />

After this step, **git.exe** and builtin linux commands(such as **echo.exe**, **grep.exe**, **find.exe**, **curl.exe**) will be available in `%PATH%`.
After this step, **git.exe** and builtin linux commands(such as **echo.exe**, **ls.exe**, **curl.exe**) will be available in `%PATH%`.

#### [scoop](https://scoop.sh/)

Expand All @@ -114,10 +114,9 @@ scoop install git # git, bash, sh
scoop install uutils-coreutils # echo, ls, cat
scoop install curl # curl
scoop install grep # grep
scoop install findutils # find
```

> Note: install the rust-reimplementation [uutils-coreutils](https://github.com/uutils/coreutils) instead of GNU [coreutils](https://www.gnu.org/software/coreutils/), which is more compatible on Windows (the `ls` from GNU coreutils is actually broken on my Windows 10 x86_64 PC).
> Note: install the rust-reimplementation [uutils-coreutils](https://github.com/uutils/coreutils) instead of GNU [coreutils](https://www.gnu.org/software/coreutils/), since some (for example `ls`) GNU commands is actually broken on Windows 10 x86_64 PC.
#### Fix conflicts between embedded commands in `C:\Windows\System32` and portable linux commands

Expand Down Expand Up @@ -1568,7 +1567,7 @@ require("fzfx").setup({

You can also use the `require("fzfx").register("ls", {...})` api to do that.

For detailed explanation of each components, please see [schema.lua](https://github.com/linrongbin16/fzfx.nvim/blob/main/lua/fzfx/schema.lua).
For detailed explanation of each components, please see [A General Schema for Creating FZF Command](https://github.com/linrongbin16/fzfx.nvim/wiki/A-General-Schema-for-Creating-FZF-Command) and [schema.lua](https://github.com/linrongbin16/fzfx.nvim/blob/main/lua/fzfx/schema.lua).

### API References

Expand Down
7 changes: 2 additions & 5 deletions REFERENCES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ They are supposed to be stable and tested (except those starting with underline
- [fzfx.lib.spawn](#fzfxlibspawn)
- [fzfx.lib.strings](#fzfxlibstrings)
- [fzfx.lib.tables](#fzfxlibtables)
- [Logger](#logger)
- [fzfx.log](#fzfxlog)
- [fzfx.lib.log](#fzfxliblog)

## [Line-Oriented Helpers](/lua/fzfx/helper)

Expand Down Expand Up @@ -449,9 +448,7 @@ curl
- if `i > 0`, `i` is in range `[1,n]`.
- if `i < 0`, `i` is in range `[-1,-n]`, `-1` maps to last position (e.g. `n`), `-n` maps to first position (e.g. `1`).

## Logger

### [fzfx.log](/lua/fzfx/log.lua)
### [fzfx.lib.log](/lua/fzfx/lib/log.lua)

- `debug(fmt:string, ...)`: debug, the `fmt` is formatting messages in C style formatters, e.g. `%d`, `%s`.
- `info(fmt:string, ...)`: info.
Expand Down
6 changes: 3 additions & 3 deletions lua/fzfx.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local log = require("fzfx.log")
local LogLevels = require("fzfx.log").LogLevels
local log = require("fzfx.lib.log")
local LogLevels = require("fzfx.lib.log").LogLevels
local general = require("fzfx.detail.general")

--- @param options fzfx.Options?
Expand Down Expand Up @@ -33,7 +33,7 @@ local function setup(options)
-- initialize
require("fzfx.detail.module").setup()
require("fzfx.detail.rpcserver").setup()
require("fzfx.yank_history").setup()
require("fzfx.detail.yanks").setup()
require("fzfx.detail.fzf_helpers").setup()
require("fzfx.detail.popup").setup()

Expand Down
5 changes: 2 additions & 3 deletions lua/fzfx/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ local colors = require("fzfx.lib.colors")
local paths = require("fzfx.lib.paths")
local fs = require("fzfx.lib.filesystems")
local tbls = require("fzfx.lib.tables")

local log = require("fzfx.log")
local LogLevels = require("fzfx.log").LogLevels
local log = require("fzfx.lib.log")
local LogLevels = require("fzfx.lib.log").LogLevels

local parsers_helper = require("fzfx.helper.parsers")
local queries_helper = require("fzfx.helper.queries")
Expand Down
6 changes: 3 additions & 3 deletions lua/fzfx/detail/fzf_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ local jsons = require("fzfx.lib.jsons")
local fs = require("fzfx.lib.filesystems")
local strs = require("fzfx.lib.strings")
local nvims = require("fzfx.lib.nvims")
local log = require("fzfx.lib.log")
local yanks = require("fzfx.detail.yanks")

local log = require("fzfx.log")
local conf = require("fzfx.config")
local yank_history = require("fzfx.yank_history")

-- visual select {

Expand Down Expand Up @@ -109,7 +109,7 @@ local function get_command_feed(feed_type, input_args, pipeline_name)
---@diagnostic disable-next-line: return-type-mismatch
return vim.fn.expand("<cword>"), nil
elseif feed_type == "put" then
local y = yank_history.get_yank()
local y = yanks.get_yank()
return (y ~= nil and type(y.regtext) == "string") and y.regtext or "", nil
elseif feed_type == "resume" then
local cache = make_last_query_cache(pipeline_name)
Expand Down
2 changes: 1 addition & 1 deletion lua/fzfx/detail/general.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ local fs = require("fzfx.lib.filesystems")
local nvims = require("fzfx.lib.nvims")
local tbls = require("fzfx.lib.tables")
local spawn = require("fzfx.lib.spawn")
local log = require("fzfx.lib.log")

local log = require("fzfx.log")
local conf = require("fzfx.config")

local ProviderTypeEnum = require("fzfx.schema").ProviderTypeEnum
Expand Down
3 changes: 2 additions & 1 deletion lua/fzfx/detail/module.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local log = require("fzfx.lib.log")

local conf = require("fzfx.config")
local log = require("fzfx.log")

local M = {}

Expand Down
3 changes: 1 addition & 2 deletions lua/fzfx/detail/popup.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
local nums = require("fzfx.lib.numbers")
local nvims = require("fzfx.lib.nvims")
local fs = require("fzfx.lib.filesystems")

local log = require("fzfx.log")
local log = require("fzfx.lib.log")

local fzf_helpers = require("fzfx.detail.fzf_helpers")

Expand Down
3 changes: 1 addition & 2 deletions lua/fzfx/detail/rpcserver.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
local consts = require("fzfx.lib.constants")
local paths = require("fzfx.lib.paths")
local nums = require("fzfx.lib.numbers")

local log = require("fzfx.log")
local log = require("fzfx.lib.log")

local M = {}

Expand Down
10 changes: 5 additions & 5 deletions lua/fzfx/detail/shell_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ else
end

local LoggerContext = {
level = M.DEBUG_ENABLE and require("fzfx.log").LogLevels.DEBUG
or require("fzfx.log").LogLevels.INFO,
level = M.DEBUG_ENABLE and require("fzfx.lib.log").LogLevels.DEBUG
or require("fzfx.lib.log").LogLevels.INFO,
console_log = M.DEBUG_ENABLE and true or false,
file_log = M.DEBUG_ENABLE and true or false,
file_path = nil,
Expand All @@ -40,7 +40,7 @@ end
--- @param level integer
--- @param msg string
local function _log(level, msg)
local LogLevelNames = require("fzfx.log").LogLevelNames
local LogLevelNames = require("fzfx.lib.log").LogLevelNames
if level < LoggerContext.level then
return
end
Expand Down Expand Up @@ -72,14 +72,14 @@ end
--- @param fmt string
--- @param ... any
M.log_debug = function(fmt, ...)
local LogLevels = require("fzfx.log").LogLevels
local LogLevels = require("fzfx.lib.log").LogLevels
_log(LogLevels.DEBUG, string.format(fmt, ...))
end

--- @param fmt string
--- @param ... any
M.log_err = function(fmt, ...)
local LogLevels = require("fzfx.log").LogLevels
local LogLevels = require("fzfx.lib.log").LogLevels
_log(LogLevels.ERROR, string.format(fmt, ...))
end

Expand Down
52 changes: 24 additions & 28 deletions lua/fzfx/yank_history.lua → lua/fzfx/detail/yanks.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
local env = require("fzfx.lib.env")
local nvims = require("fzfx.lib.nvims")
local paths = require("fzfx.lib.paths")
local log = require("fzfx.lib.log")

local conf = require("fzfx.config")
local log = require("fzfx.log")

local M = {}

--- @class fzfx.Yank
--- @field regname string
Expand Down Expand Up @@ -34,6 +36,8 @@ function Yank:new(regname, regtext, regtype, filename, filetype)
return o
end

M.Yank = Yank

--- @class fzfx.YankHistory
--- @field ring_buffer fzfx.RingBuffer
local YankHistory = {}
Expand Down Expand Up @@ -87,11 +91,13 @@ function YankHistory:rnext(pos)
return self.ring_buffer:rnext(pos)
end

M.YankHistory = YankHistory

--- @type fzfx.YankHistory?
local YankHistoryInstance = nil
M._YankHistoryInstance = nil

--- @return table
local function _get_register_info(regname)
M._get_register_info = function(regname)
return {
regname = regname,
regtext = vim.fn.getreg(regname),
Expand All @@ -100,8 +106,8 @@ local function _get_register_info(regname)
end

--- @return integer?
local function save_yank()
local r = _get_register_info(vim.v.event.regname)
M.save_yank = function()
local r = M._get_register_info(vim.v.event.regname)
local y = Yank:new(
r.regname,
r.regtext,
Expand All @@ -112,53 +118,43 @@ local function save_yank()
vim.bo.filetype
)
-- log.debug(
-- "|fzfx.yank_history - save_yank| r:%s, y:%s",
-- "|fzfx.helper.yanks - save_yank| r:%s, y:%s",
-- vim.inspect(r),
-- vim.inspect(y)
-- )

log.ensure(
YankHistoryInstance ~= nil,
"|fzfx.yank_history - save_yank| YankHistoryInstance must not be nil!"
M._YankHistoryInstance ~= nil,
"|fzfx.helper.yanks - save_yank| YankHistoryInstance must not be nil!"
)
---@diagnostic disable-next-line: need-check-nil
return YankHistoryInstance:push(y)
return M._YankHistoryInstance:push(y)
end

--- @return fzfx.Yank?
local function get_yank()
M.get_yank = function()
log.ensure(
YankHistoryInstance ~= nil,
"|fzfx.yank_history - get_yank| YankHistoryInstance must not be nil!"
M._YankHistoryInstance ~= nil,
"|fzfx.helper.yanks - get_yank| YankHistoryInstance must not be nil!"
)
---@diagnostic disable-next-line: need-check-nil
return YankHistoryInstance:get()
return M._YankHistoryInstance:get()
end

--- @return fzfx.YankHistory?
local function _get_yank_history_instance()
return YankHistoryInstance
M._get_yank_history_instance = function()
return M._YankHistoryInstance
end

local function setup()
YankHistoryInstance = YankHistory:new(
M.setup = function()
M._YankHistoryInstance = YankHistory:new(
env.debug_enabled() and 10
or conf.get_config().yank_history.other_opts.maxsize
)
vim.api.nvim_create_autocmd("TextYankPost", {
pattern = { "*" },
callback = save_yank,
callback = M.save_yank,
})
end

local M = {
setup = setup,
get_yank = get_yank,
save_yank = save_yank,
Yank = Yank,
YankHistory = YankHistory,
_get_register_info = _get_register_info,
_get_yank_history_instance = _get_yank_history_instance,
}

return M
4 changes: 2 additions & 2 deletions lua/fzfx/helper/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ local nums = require("fzfx.lib.numbers")
local parsers = require("fzfx.helper.parsers")
local prompts = require("fzfx.helper.prompts")

local log = require("fzfx.log")
local LogLevels = require("fzfx.log").LogLevels
local log = require("fzfx.lib.log")
local LogLevels = require("fzfx.lib.log").LogLevels

local M = {}

Expand Down
4 changes: 2 additions & 2 deletions lua/fzfx/helper/previewers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ local paths = require("fzfx.lib.paths")
local fs = require("fzfx.lib.filesystems")
local tbls = require("fzfx.lib.tables")

local log = require("fzfx.log")
local LogLevels = require("fzfx.log").LogLevels
local log = require("fzfx.lib.log")
local LogLevels = require("fzfx.lib.log").LogLevels

local parsers_helper = require("fzfx.helper.parsers")
local queries_helper = require("fzfx.helper.queries")
Expand Down
4 changes: 2 additions & 2 deletions lua/fzfx/helper/prompts.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local strs = require("fzfx.lib.strings")
local nvims = require("fzfx.lib.nvims")

local log = require("fzfx.log")
local LogLevels = require("fzfx.log").LogLevels
local log = require("fzfx.lib.log")
local LogLevels = require("fzfx.lib.log").LogLevels

local M = {}

Expand Down
4 changes: 2 additions & 2 deletions lua/fzfx/helper/providers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ local paths = require("fzfx.lib.paths")
local fs = require("fzfx.lib.filesystems")
local tbls = require("fzfx.lib.tables")

local log = require("fzfx.log")
local LogLevels = require("fzfx.log").LogLevels
local log = require("fzfx.lib.log")
local LogLevels = require("fzfx.lib.log").LogLevels

local parsers_helper = require("fzfx.helper.parsers")
local queries_helper = require("fzfx.helper.queries")
Expand Down
File renamed without changes.
Loading

0 comments on commit bbd1d9d

Please sign in to comment.