diff --git a/lua/frecency/database.lua b/lua/frecency/database.lua index 507d361a..3e4cf38b 100644 --- a/lua/frecency/database.lua +++ b/lua/frecency/database.lua @@ -1,5 +1,5 @@ local sqlite = require "sqlite" -local log = require "frecency.log" +local log = require "plenary.log" ---@class FrecencyDatabaseConfig ---@field auto_validate boolean @@ -72,7 +72,7 @@ end ---@return FrecencyFile[] function Database:get_files(workspace) local query = workspace and { contains = { path = { workspace .. "*" } } } or {} - log:debug { query = query } + log.debug { query = query } return self.sqlite.files:get(query) end diff --git a/lua/frecency/finder.lua b/lua/frecency/finder.lua index c68e1ba8..9738585f 100644 --- a/lua/frecency/finder.lua +++ b/lua/frecency/finder.lua @@ -1,5 +1,5 @@ local finders = require "telescope.finders" -local log = require "frecency.log" +local log = require "plenary.log" ---@class FrecencyFinder ---@field private config FrecencyFinderConfig @@ -37,7 +37,7 @@ function Finder:start(filepath_formatter, initial_results, opts) entry_maker = entry_maker, } end - log:debug { finder = opts } + log.debug { finder = opts } return finders.new_dynamic { entry_maker = entry_maker, fn = self:create_fn(initial_results, opts.workspace) } end @@ -52,7 +52,7 @@ function Finder:create_fn(initial_results, path) ---@return table[] return function(_) called = called + 1 - log:debug { called = called } + log.debug { called = called } local count = 0 for name in it do table.insert(results, { path = vim.fs.joinpath(path, name), score = 0 }) diff --git a/lua/frecency/frecency.lua b/lua/frecency/frecency.lua index 1196162f..c7c9ae44 100644 --- a/lua/frecency/frecency.lua +++ b/lua/frecency/frecency.lua @@ -4,7 +4,7 @@ local FS = require "frecency.fs" local Finder = require "frecency.finder" local Picker = require "frecency.picker" local Recency = require "frecency.recency" -local log = require "frecency.log" +local log = require "plenary.log" ---@class Frecency ---@field config FrecencyConfig @@ -71,7 +71,7 @@ function Frecency:setup() -- TODO: Should we schedule this after loading shada? if not self.database:has_entry() then self.database:insert_files(vim.v.oldfiles) - log:info("Imported %d entries from oldfiles.", #vim.v.oldfiles) + log.info(("[Telescope-Frecency] Imported %d entries from oldfiles."):format(#vim.v.oldfiles)) end local group = vim.api.nvim_create_augroup("TelescopeFrecency", {}) diff --git a/lua/frecency/fs.lua b/lua/frecency/fs.lua index 5832be53..717fa78a 100644 --- a/lua/frecency/fs.lua +++ b/lua/frecency/fs.lua @@ -1,6 +1,6 @@ local Path = require "plenary.path" --[[@as PlenaryPath]] local scandir = require "plenary.scandir" -local log = require "frecency.log" +local log = require "plenary.log" local uv = vim.uv or vim.loop ---@class FrecencyFS @@ -32,7 +32,7 @@ end ---@param path string function FS:scan_dir(path) - log:debug { path = path } + log.debug { path = path } local gitignore = self:make_gitignore(path) return coroutine.wrap(function() for name, type in diff --git a/lua/frecency/log.lua b/lua/frecency/log.lua deleted file mode 100644 index f4a01080..00000000 --- a/lua/frecency/log.lua +++ /dev/null @@ -1,36 +0,0 @@ ----@class FrecencyLog ----@field count integer ----@field dev boolean -local Log = {} - -Log.new = function() - return setmetatable({ count = 0, dev = false }, { __index = Log }) -end - ----@param fmt any ----@param args any[] ----@param level integer -function Log:log(fmt, args, level) - local function dump(v) - return type(v) == "table" and vim.inspect(v, { indent = " ", newline = "" }) or v - 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]: %s"):format(self.count, msg), level) -end - ----@param fmt any ----@param ... any -function Log:info(fmt, ...) - self:log(fmt, { ... }, vim.log.levels.INFO) -end - ----@param fmt any ----@param ... any -function Log:debug(fmt, ...) - if self.dev then - self:log(fmt, { ... }, vim.log.levels.DEBUG) - end -end - -return Log.new() diff --git a/lua/frecency/picker.lua b/lua/frecency/picker.lua index e89c44c5..79955fb8 100644 --- a/lua/frecency/picker.lua +++ b/lua/frecency/picker.lua @@ -1,4 +1,4 @@ -local log = require "frecency.log" +local log = require "plenary.log" local actions = require "telescope.actions" local config_values = require("telescope.config").values local pickers = require "telescope.pickers" @@ -80,7 +80,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(opts) + log.debug(opts) if vim.tbl_isempty(self.results) then self.results = self:fetch_results(self.workspace) end @@ -180,7 +180,7 @@ end ---@param workspace string? ---@return FrecencyFile[] function Picker:fetch_results(workspace) - log:debug { workspace = 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 @@ -222,7 +222,7 @@ function Picker:on_input_filter_cb(picker_opts) local matched, tag = prompt:match(self.workspace_tag_regex) picker_opts.prompt = matched and prompt:sub(matched:len() + 1) or prompt local workspace = self:get_workspace(picker_opts.cwd, tag) or self.workspace or self.config.default_workspace - log:debug { workspace = workspace, ["self.workspace"] = self.workspace } + log.debug { workspace = workspace, ["self.workspace"] = self.workspace } if self.workspace ~= workspace then self.workspace = workspace picker_opts.updated_finder = self.finder:start(filepath_formatter, self.results, {