mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
lsp_workspace filter
This commit is contained in:
parent
e547c1cd32
commit
2f7636ba0f
@ -6,7 +6,6 @@ if not has_telescope then
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- start the database client
|
-- start the database client
|
||||||
-- print("start")
|
|
||||||
local db_client = require("telescope._extensions.frecency.db_client")
|
local db_client = require("telescope._extensions.frecency.db_client")
|
||||||
-- vim.defer_fn(db_client.init, 100) -- TODO: this is a crappy attempt to lessen loadtime impact, use VimEnter?
|
-- vim.defer_fn(db_client.init, 100) -- TODO: this is a crappy attempt to lessen loadtime impact, use VimEnter?
|
||||||
db_client.init()
|
db_client.init()
|
||||||
@ -21,7 +20,7 @@ local pickers = require "telescope.pickers"
|
|||||||
local previewers = require "telescope.previewers"
|
local previewers = require "telescope.previewers"
|
||||||
-- local sorters = require "telescope.sorters"
|
-- local sorters = require "telescope.sorters"
|
||||||
local sorters = require "telescope._extensions.frecency.sorter"
|
local sorters = require "telescope._extensions.frecency.sorter"
|
||||||
local conf = require('telescope.config').values
|
-- local conf = require('telescope.config').values
|
||||||
local path = require('telescope.path')
|
local path = require('telescope.path')
|
||||||
local utils = require('telescope.utils')
|
local utils = require('telescope.utils')
|
||||||
|
|
||||||
@ -29,7 +28,9 @@ local frecency = function(opts)
|
|||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
|
local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
|
||||||
local results = db_client.get_file_scores()
|
-- opts.lsp_workspace_filter = true
|
||||||
|
-- TODO: decide on how to handle cwd or lsp_workspace for pathname shorten?
|
||||||
|
local results = db_client.get_file_scores(opts) -- TODO: pass `filter_workspace` option
|
||||||
|
|
||||||
local displayer = entry_display.create {
|
local displayer = entry_display.create {
|
||||||
separator = "",
|
separator = "",
|
||||||
|
|||||||
@ -18,7 +18,6 @@ local sql_wrapper = nil
|
|||||||
local function import_oldfiles()
|
local function import_oldfiles()
|
||||||
local oldfiles = vim.api.nvim_get_vvar("oldfiles")
|
local oldfiles = vim.api.nvim_get_vvar("oldfiles")
|
||||||
for _, filepath in pairs(oldfiles) do
|
for _, filepath in pairs(oldfiles) do
|
||||||
-- TODO: don't touch existing entries
|
|
||||||
sql_wrapper:update(filepath)
|
sql_wrapper:update(filepath)
|
||||||
end
|
end
|
||||||
print(("Telescope-Frecency: Imported %d entries from oldfiles."):format(#oldfiles))
|
print(("Telescope-Frecency: Imported %d entries from oldfiles."):format(#oldfiles))
|
||||||
@ -66,7 +65,17 @@ local function filter_timestamps(timestamps, file_id)
|
|||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_file_scores()
|
local function filter_workspace(filelist, workspace_path)
|
||||||
|
local res = {}
|
||||||
|
for _, entry in pairs(filelist) do
|
||||||
|
if util.string_starts(entry.path, workspace_path) then
|
||||||
|
table.insert(res, entry)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_file_scores(opts)
|
||||||
if not sql_wrapper then return {} end
|
if not sql_wrapper then return {} end
|
||||||
|
|
||||||
local queries = sql_wrapper.queries
|
local queries = sql_wrapper.queries
|
||||||
@ -78,6 +87,14 @@ local function get_file_scores()
|
|||||||
-- print(vim.inspect(timestamp_ages))
|
-- print(vim.inspect(timestamp_ages))
|
||||||
if vim.tbl_isempty(files) then return scores end
|
if vim.tbl_isempty(files) then return scores end
|
||||||
|
|
||||||
|
-- filter to LSP workspace directory
|
||||||
|
local buf_workspaces = opts.lsp_workspace_filter and vim.lsp.buf.list_workspace_folders() or {}
|
||||||
|
if not vim.tbl_isempty(buf_workspaces) then
|
||||||
|
for _, ws_path in pairs(buf_workspaces) do
|
||||||
|
files = filter_workspace(files, ws_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
for _, file_entry in ipairs(files) do
|
for _, file_entry in ipairs(files) do
|
||||||
table.insert(scores, {
|
table.insert(scores, {
|
||||||
filename = file_entry.path,
|
filename = file_entry.path,
|
||||||
@ -86,10 +103,7 @@ local function get_file_scores()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- sort the table
|
-- sort the table
|
||||||
local function compare(a, b)
|
table.sort(scores, function(a, b) return a.score > b.score end)
|
||||||
return a.score > b.score
|
|
||||||
end
|
|
||||||
table.sort(scores, compare)
|
|
||||||
|
|
||||||
return scores
|
return scores
|
||||||
end
|
end
|
||||||
|
|||||||
@ -6,6 +6,10 @@ util.string_isempty = function(s)
|
|||||||
return s == nil or s == ''
|
return s == nil or s == ''
|
||||||
end
|
end
|
||||||
|
|
||||||
|
util.string_starts = function(str, start)
|
||||||
|
return string.sub(str, 1, str.len(start)) == start
|
||||||
|
end
|
||||||
|
|
||||||
util.split = function(s, delimiter)
|
util.split = function(s, delimiter)
|
||||||
local result = {}
|
local result = {}
|
||||||
for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
|
for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user