mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
* refactor(db): use new sql.nvim api * refactor(*): create const, algo and add more util * refactor(picker): try to cleanup and make it easy to read FIXME: it seems that I didn't refactor the entry maker right. * refactor(*): move util to lua/frecency * misc(db): flag possible bug * refactor(db): reflect changes introduced in https://github.com/tami5/sql.nvim/pull/96 * refactor(db): move set_config to frecency.lua * new(db): ignore term and octo paths This may possibly fix the issue with entry.count being nil. * misc(picker): move health out of export * refactor(util) * refactor(db): general * misc(*): nothing major * refactor(db): abbreviate table namespace access * refactor(picker): working-ish * fix(*): general * refactor(picker): move fd function to the end of the file * refactor(*): remove the need for db.init * new(db): use foreign keys * sync with sqlite.lua@#105 * feat: add settings for StyLua * fix: detect the valid module in healthcheck See #65 * style: fix by StyLua * fix: detect CWD tag to cut paths See #66 * fix: show icon before directory See #67 * fix: deal with show_filter_column option validly * feat: support opts.workspace (#68) * doc(readme): update config example (#33) remove comma causing error. * doc(readme): fix packer install instructions (#34) Co-authored-by: tami5 <65782666+tami5@users.noreply.github.com> * doc: follow sqlite new release (#40) * refactor(sql_wrapper): follow sqlite new release * update readme * refactor: follow telescope's interface changes See #46 * feat: add default_workspace tag See #43 * fix: fetch workspaces in addition to completing See #72 * Update url for sqlite dependency (#64) The old repository on github redirects to this one. * fix: use vim.notify not to block outputs See #75 * feat: opts.path_display to customize See #76 * Enable to specify tags to show the tails (#77) * Enable to specify tags to show the tails * Add doc for show_filter_column * feat: use more reasonable matcher to sort See #73 * Fix broken Frecency Algorithm link in README.md (#82) MDN appear to have removed the Frecency Algorithm page linked in the README document. Updating link to use archived version. * fix: set the telescope default filetype in prompt See #81 * feat: use the newer API to define autocmds See #79 * refactor: use new API and add check for devicons * feat: detect entries when it has added new ones See #87 * fix: use valid widths to show entries * fix: use substr matcher to use sorting by scores See #94 * Revert "fix: set the telescope default filetype in prompt" This reverts commit 4937f7045438412e31a77374f91230bdbcbeb34d. * fix: enable to filter by valid paths * refactor: do nothing until calling setup() See #80 * fix: fix typo for `workspaces` * fix: show `0` score for unindexed instead of `nil` * style: fix by StyLua * fix: return a valid entry with get() It have used where() to get the entry and where() uses get() to fetch from DB. But this table has been customized by overwriting get(), so it has a bug to return the same entry every time it calls. This fixes it. * refactor: get the buffer name explicitly * fix: clean up logic to validate DB * feat: enable to work db_root option * fix: show no msg when no need to validate in auto --------- Co-authored-by: Tami <65782666+tami5@users.noreply.github.com> Co-authored-by: Munif Tanjim <hello@muniftanjim.dev> Co-authored-by: premell <65544203+premell@users.noreply.github.com> Co-authored-by: Anshuman Medhi <amedhi@connect.ust.hk> Co-authored-by: Lucas Hoffmann <lucc@users.noreply.github.com> Co-authored-by: Rohan Orton <rohan.orton@gmail.com>
97 lines
2.6 KiB
Lua
97 lines
2.6 KiB
Lua
local uv = vim.loop
|
|
local const = require "frecency.const"
|
|
local Path = require "plenary.path"
|
|
|
|
local util = {}
|
|
|
|
-- stolen from penlight
|
|
|
|
---escape any Lua 'magic' characters in a string
|
|
util.escape = function(str)
|
|
return (str:gsub("[%-%.%+%[%]%(%)%$%^%%%?%*]", "%%%1"))
|
|
end
|
|
|
|
util.string_isempty = function(str)
|
|
return str == nil or str == ""
|
|
end
|
|
|
|
util.filemask = function(mask)
|
|
mask = util.escape(mask)
|
|
return "^" .. mask:gsub("%%%*", ".*"):gsub("%%%?", ".") .. "$"
|
|
end
|
|
|
|
util.path_is_ignored = function(filepath, ignore_patters)
|
|
local i = ignore_patters and vim.tbl_flatten { ignore_patters, const.ignore_patterns } or const.ignore_patterns
|
|
local is_ignored = false
|
|
for _, pattern in ipairs(i) do
|
|
if filepath:find(util.filemask(pattern)) ~= nil then
|
|
is_ignored = true
|
|
goto continue
|
|
end
|
|
end
|
|
|
|
::continue::
|
|
return is_ignored
|
|
end
|
|
|
|
util.path_exists = function(path)
|
|
return Path:new(path):exists()
|
|
end
|
|
|
|
util.path_invalid = function(path, ignore_patterns)
|
|
local p = Path:new(path)
|
|
if
|
|
util.string_isempty(path)
|
|
or (not p:is_file())
|
|
or (not p:exists())
|
|
or util.path_is_ignored(path, ignore_patterns)
|
|
then
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
|
|
util.confirm_deletion = function(num_of_entries)
|
|
local question = "Telescope-Frecency: remove %d entries from SQLite3 database?"
|
|
return vim.fn.confirm(question:format(num_of_entries), "&Yes\n&No", 2) == 1
|
|
end
|
|
|
|
util.abort_remove_unlinked_files = function()
|
|
---TODO: refactor all messages to a lua file. alarts.lua?
|
|
vim.notify "TelescopeFrecency: validation aborted."
|
|
end
|
|
|
|
util.tbl_match = function(field, val, tbl)
|
|
return vim.tbl_filter(function(t)
|
|
return t[field] == val
|
|
end, tbl)
|
|
end
|
|
|
|
---Wrappe around Path:new():make_relative
|
|
---@return string
|
|
util.path_relative = function(path, cwd)
|
|
return Path:new(path):make_relative(cwd)
|
|
end
|
|
|
|
---Given a filename, check if there's a buffer with the given name.
|
|
---@return boolean
|
|
util.buf_is_loaded = function(filename)
|
|
return vim.api.nvim_buf_is_loaded(vim.fn.bufnr(filename))
|
|
end
|
|
|
|
util.include_unindexed = function(files, ws_path)
|
|
local scan_opts = { respect_gitignore = true, depth = 100, hidden = true }
|
|
|
|
-- TODO: make sure scandir unindexed have opts.ignore_patterns applied
|
|
-- TODO: make filters handle mulitple directories
|
|
local unindexed_files = require("plenary.scandir").scan_dir(ws_path, scan_opts)
|
|
for _, file in pairs(unindexed_files) do
|
|
if not util.path_is_ignored(file) then -- this causes some slowdown on large dirs
|
|
table.insert(files, { id = 0, path = file, count = 0, directory_id = 0, score = 0 })
|
|
end
|
|
end
|
|
end
|
|
|
|
return util
|