fix: sigh

This commit is contained in:
dlond 2025-09-03 09:20:23 +12:00 committed by Daniel Lond
parent 829e0c4bc5
commit d214e73407
1 changed files with 16 additions and 29 deletions

View File

@ -39,48 +39,35 @@ function M.pick_compile_commands()
return return
end end
-- Multiple files found, show picker -- Use Telescope's built-in find_files with custom settings
local pickers = require('telescope.pickers') local builtin = require('telescope.builtin')
local finders = require('telescope.finders')
local conf = require('telescope.config').values
local actions = require('telescope.actions') local actions = require('telescope.actions')
local action_state = require('telescope.actions.state') local action_state = require('telescope.actions.state')
-- Create a simple path array for the finder builtin.find_files({
local paths = {}
local path_to_info = {}
for _, file in ipairs(files) do
table.insert(paths, file.path)
path_to_info[file.path] = file
end
pickers.new({}, {
prompt_title = 'Select compile_commands.json', prompt_title = 'Select compile_commands.json',
finder = finders.new_table { cwd = vim.fn.getcwd(),
results = paths, -- Pass simple path strings find_command = { 'find', '.', '-name', 'compile_commands.json', '-type', 'f' },
entry_maker = function(path)
local info = path_to_info[path]
return {
value = info,
display = info.display,
ordinal = info.display,
path = path, -- This is what the previewer needs
}
end,
},
sorter = conf.generic_sorter{},
previewer = conf.file_previewer{},
attach_mappings = function(prompt_bufnr, map) attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function() actions.select_default:replace(function()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry() local selection = action_state.get_selected_entry()
if selection then if selection then
M.set_compile_commands(selection.value) -- Convert the selection to our file_info format
local path = selection[1]
local relative = path:gsub('^%./', '')
local file_info = {
path = vim.fn.getcwd() .. '/' .. relative,
display = relative,
dir = vim.fn.fnamemodify(path, ':h'),
relative_dir = vim.fn.fnamemodify(relative, ':h'),
}
M.set_compile_commands(file_info)
end end
end) end)
return true return true
end, end,
}):find() })
end end
function M.set_compile_commands(file_info) function M.set_compile_commands(file_info)