Skip to content

Commit

Permalink
refactor: use logging plenary.log instead of mine
Browse files Browse the repository at this point in the history
  • Loading branch information
delphinus committed Jul 29, 2023
1 parent 92b87d7 commit 9fd9168
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 49 deletions.
4 changes: 2 additions & 2 deletions lua/frecency/database.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local sqlite = require "sqlite"
local log = require "frecency.log"
local log = require "plenary.log"

---@class FrecencyDatabaseConfig
---@field auto_validate boolean
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lua/frecency/finder.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions lua/frecency/frecency.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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", {})
Expand Down
4 changes: 2 additions & 2 deletions lua/frecency/fs.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
36 changes: 0 additions & 36 deletions lua/frecency/log.lua

This file was deleted.

8 changes: 4 additions & 4 deletions lua/frecency/picker.lua
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit 9fd9168

Please sign in to comment.