Skip to content

Commit

Permalink
refactor: change type for logging module
Browse files Browse the repository at this point in the history
  • Loading branch information
delphinus committed Jul 28, 2023
1 parent bf08574 commit 5b3e0a5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lua/frecency/database.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ end
---@return FrecencyFile[]
function Database:get_files(workspace)
local query = workspace and { contains = { path = { workspace .. "*" } } } or {}
log:debug("%s", { query = query })
log:debug { query = query }
return self.sqlite.files:get(query)
end

Expand Down
4 changes: 2 additions & 2 deletions lua/frecency/finder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Finder:start(opts)
entry_maker = entry_maker,
}
end
log:debug("%s", { finder = opts })
log:debug { finder = opts }
return finders.new_dynamic { entry_maker = entry_maker, fn = self:create_fn { path = opts.workspace } }
end

Expand All @@ -51,7 +51,7 @@ function Finder:create_fn(opts)
return results
end
called = called + 1
log:debug("called: %d", called)
log:debug { called = called }
local count = 0
while true do
local ok, name = pcall(it)
Expand Down
2 changes: 1 addition & 1 deletion lua/frecency/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ end

---@param path string
function FS:scan_dir(path)
log:debug("%s", { path = path })
log:debug { path = path }
local gitignore = self:make_gitignore(path)
return coroutine.wrap(function()
for name, type in
Expand Down
13 changes: 7 additions & 6 deletions lua/frecency/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ Log.new = function()
return setmetatable({ count = 0, dev = false }, { __index = Log })
end

---@param fmt string
---@param fmt any
---@param args any[]
---@param level integer
function Log:log(fmt, args, level)
args = vim.tbl_map(function(v)
local function dump(v)
return type(v) == "table" and vim.inspect(v, { indent = " ", newline = "" }) or v
end, args)
end
local msg = #args == 0 and dump(fmt) or fmt:format(unpack(vim.tbl_map(dump, args)))
self.count = self.count + 1
vim.notify(("[Telescope-Frecency: %d]: " .. fmt):format(self.count, unpack(args)), level)
vim.notify(("[Telescope-Frecency: %d]: %s"):format(self.count, msg), level)
end

---@param fmt string
---@param fmt any
---@param ... any
function Log:info(fmt, ...)
self:log(fmt, { ... }, vim.log.levels.INFO)
end

---@param fmt string
---@param fmt any
---@param ... any
function Log:debug(fmt, ...)
if self.dev then
Expand Down
1 change: 0 additions & 1 deletion lua/frecency/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ end
---@param filter string
---@return boolean
m.update = function(filter)
log:debug("filter: %s", filter or "NONE")
local filter_updated = false
local ws_dir = filter and m.config.workspaces[filter] or nil

Expand Down
6 changes: 3 additions & 3 deletions lua/frecency/pickers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function Picker:start(opts)
self.editing_bufnr = vim.api.nvim_get_current_buf()
self.lsp_workspaces = {}
self.workspace = self:get_workspace(opts.cwd, opts.workspace)
log:debug("%s", opts)
log:debug(opts)
if vim.tbl_isempty(self.results) then
self.results = self:fetch_results(self.workspace)
end
Expand Down Expand Up @@ -190,7 +190,7 @@ end
---@param workspace string?
---@return FrecencyFile[]
function Picker:fetch_results(workspace)
log:debug("workspace: %s", workspace or "NONE")
log:debug { workspace = workspace or "NONE" }
local files = self.database:get_files(workspace)
-- NOTE: this might get slower with big db, it might be better to query with db.get_timestamp.
-- TODO: test the above assumption
Expand Down Expand Up @@ -237,7 +237,7 @@ function Picker:on_input_filter_cb(prompt, cwd)
local matched, tag = prompt:match(self.workspace_tag_regex)
local opts = { prompt = matched and prompt:sub(matched:len() + 1) or prompt }
local workspace = self:get_workspace(cwd, tag) or self.workspace or self.config.default_workspace
log:debug("%s", { workspace = workspace, ["self.workspace"] = self.workspace })
log:debug { workspace = workspace, ["self.workspace"] = self.workspace }
if self.workspace ~= workspace then
self.workspace = workspace
--[[ opts.updated_finder = finders.new_table {
Expand Down

0 comments on commit 5b3e0a5

Please sign in to comment.