forked from dmtrKovalenko/fff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfff.lua
More file actions
107 lines (97 loc) · 3.66 KB
/
Copy pathfff.lua
File metadata and controls
107 lines (97 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
if vim.g.fff_loaded then return end
vim.g.fff_loaded = true
-- Defer indexing until after UIEnter, so as to not block the UI.
-- This is equivalent to lazy.nvim's VeryLazy, but works with all plugin managers.
local init = vim.schedule_wrap(function()
if vim.v.exiting ~= vim.NIL then return end
-- PERF: We query the vim.g.fff config to avoid eagerly requiring Lua modules
local lazy_sync = vim.tbl_get(vim.g, 'fff', 'lazy_sync')
if lazy_sync == nil or not lazy_sync then require('fff.core').ensure_initialized() end
end)
if vim.v.vim_did_enter == 1 then
init()
else
vim.api.nvim_create_autocmd('UIEnter', {
group = vim.api.nvim_create_augroup('fff.main', {}),
once = true,
nested = true,
callback = init,
})
end
vim.api.nvim_create_user_command('FFFFind', function(opts)
local fff = require('fff')
if opts.args and opts.args ~= '' then
-- If argument looks like a directory, use it as base path
if vim.fn.isdirectory(opts.args) == 1 then
fff.find_files_in_dir(opts.args)
else
-- Otherwise treat as search query
fff.search_and_show(opts.args)
end
else
fff.find_files()
end
end, {
nargs = '?',
complete = function(arg_lead)
-- Complete with directories and common search terms
local dirs = vim.fn.glob(arg_lead .. '*', false, true)
local results = {}
for _, dir in ipairs(dirs) do
if vim.fn.isdirectory(dir) == 1 then table.insert(results, dir) end
end
return results
end,
desc = 'Find files with FFF (use directory path or search query)',
})
vim.api.nvim_create_user_command('FFFScan', function() require('fff').scan_files() end, {
desc = 'Scan files for FFF',
})
vim.api.nvim_create_user_command('FFFRefreshGit', function() require('fff').refresh_git_status() end, {
desc = 'Manually refresh git status for all files',
})
vim.api.nvim_create_user_command('FFFClearCache', function(opts) require('fff').clear_cache(opts.args) end, {
nargs = '?',
complete = function() return { 'all', 'frecency', 'files' } end,
desc = 'Clear FFF caches (all|frecency|files)',
})
vim.api.nvim_create_user_command('FFFHealth', function() vim.cmd('checkhealth fff') end, {
desc = 'Check FFF health',
})
vim.api.nvim_create_user_command('FFFDebug', function(opts)
local config = require('fff.conf').get()
if opts.args == 'toggle' or opts.args == '' then
config.debug.show_scores = not config.debug.show_scores
config.debug.enabled = config.debug.show_scores
local status = config.debug.show_scores and 'enabled' or 'disabled'
vim.notify('FFF debug scores ' .. status, vim.log.levels.INFO)
elseif opts.args == 'on' then
config.debug.show_scores = true
config.debug.enabled = true
vim.notify('FFF debug scores enabled', vim.log.levels.INFO)
elseif opts.args == 'off' then
config.debug.show_scores = false
config.debug.enabled = false
vim.notify('FFF debug scores disabled', vim.log.levels.INFO)
else
vim.notify('Usage: :FFFDebug [on|off|toggle]', vim.log.levels.ERROR)
end
end, {
nargs = '?',
complete = function() return { 'on', 'off', 'toggle' } end,
desc = 'Toggle FFF debug scores display',
})
vim.api.nvim_create_user_command('FFFOpenLog', function()
local fff = require('fff')
local config = require('fff.conf').get()
if fff.log_file_path then
vim.cmd('tabnew ' .. vim.fn.fnameescape(fff.log_file_path))
elseif config and config.logging and config.logging.log_file then
-- Fallback to the configured log file path even if tracing wasn't initialized
vim.cmd('tabnew ' .. vim.fn.fnameescape(config.logging.log_file))
else
vim.notify('Log file path not available', vim.log.levels.ERROR)
end
end, {
desc = 'Open FFF log file in new tab',
})