Skip to content

Commit 91ed022

Browse files
author
Bassam Data
committed
chore: clean up code and fix preview highlight clearing
1 parent daa0582 commit 91ed022

2 files changed

Lines changed: 5 additions & 62 deletions

File tree

lua/namu/core/format_utils.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ function M.add_tree_state_to_items(items)
207207
local items_with_parent = 0
208208
local root_item_count = 0
209209

210-
-- Build the maps and collect stats
211210
for i, item in ipairs(items) do
212211
if item.value and item.value.signature then
213212
items_with_signature = items_with_signature + 1

lua/namu/core/symbol_utils.lua

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -351,18 +351,9 @@ end
351351
local function filter_by_buffer(items, filter, opts, metadata)
352352
local buffer_filtered = {}
353353

354-
if opts.debug then
355-
logger.log("Buffer filtering for pattern: " .. filter.buffer_pattern)
356-
end
357-
358354
-- Step 1: Find all matching buffer headers
359355
local matching_buffers, direct_match_count = find_matching_buffers(items, filter, opts, buffer_filtered)
360356

361-
if opts.debug then
362-
logger.log("Matching buffers found: " .. vim.inspect(matching_buffers))
363-
logger.log("Buffer filtered items after first pass: " .. #buffer_filtered)
364-
end
365-
366357
-- Step 2: Add all symbols from matching buffers
367358
add_buffer_symbols(items, matching_buffers, opts, buffer_filtered)
368359

@@ -497,30 +488,16 @@ local function filter_by_symbol(items, filter, opts, metadata)
497488
-- If not preserving hierarchy, use a simple optimized filter
498489
if not opts.preserve_hierarchy then
499490
local filtered, count = filter_symbols_simple(items, kinds_lookup)
500-
501491
-- Update metadata
502492
metadata.filter_type = filter.filter_type
503493
metadata.description = filter.description
504494
metadata.direct_match_count = count
505-
506495
return filtered, filter.remaining, metadata
507496
end
508497

509498
-- For preserving hierarchy, use the hierarchical filter
510499
local result_items, direct_match_count, parent_count = filter_symbols_hierarchy(items, kinds_lookup, opts)
511500

512-
-- Conditionally log only when debugging is enabled
513-
if opts.debug then
514-
logger.log(
515-
string.format(
516-
"Filter results: %d items (%d direct + %d parents)",
517-
#result_items,
518-
direct_match_count,
519-
parent_count
520-
)
521-
)
522-
end
523-
524501
-- Update metadata
525502
metadata.filter_type = filter.filter_type
526503
metadata.description = filter.description
@@ -618,7 +595,7 @@ function M.show_picker(
618595
ui.apply_highlights(buf, filtered_items, opts)
619596
end,
620597
on_buffer_clear = function()
621-
ui.clear_preview_highlight(state.original_win, state.preview_ns)
598+
ui.clear_preview_highlight(state.original_win, state.preview_ns, state)
622599
if state.original_win and state.original_pos and api.nvim_win_is_valid(state.original_win) then
623600
api.nvim_win_set_cursor(state.original_win, state.original_pos)
624601
end
@@ -665,7 +642,7 @@ function M.show_picker(
665642
end,
666643
on_close = function()
667644
-- Always clean up preview highlights when picker closes
668-
ui.clear_preview_highlight(state.original_win, state.preview_ns)
645+
ui.clear_preview_highlight(state.original_win, state.preview_ns, state)
669646
end,
670647
-- BUG: cursor position outside
671648
-- Error /namu.nvim/lua/namu/core/symbol_utils.lua:889: Cursor position outside buffer
@@ -758,71 +735,38 @@ function M.create_keymaps_handlers(opts, state, ui, selecta, ext, utils)
758735
return true
759736
end
760737
end
738+
761739
handlers.quickfix = function(items_or_item, picker_state)
762740
local items_to_send
763-
764741
if type(items_or_item) == "table" and #items_or_item > 0 then
765742
items_to_send = items_or_item
766743
else
767744
items_to_send = picker_state.filtered_items
768745
end
769-
770746
local success = selecta.add_to_quickfix(items_to_send, state)
771747
if success and opts.actions.close_on_quickfix then
772748
return true
773749
end
774750
return false
775751
end
776-
handlers.sidebar = function(items_or_item, picker_state)
777-
-- Debug: Log the parameters
778-
logger.log("=== SIDEBAR DEBUG ===")
779-
logger.log("items_or_item type: " .. type(items_or_item))
780-
if type(items_or_item) == "table" and items_or_item.text then
781-
logger.log("items_or_item is single item: " .. items_or_item.text)
782-
elseif type(items_or_item) == "table" and #items_or_item > 0 then
783-
logger.log("items_or_item is array with " .. #items_or_item .. " items")
784-
end
785-
786-
logger.log("picker_state type: " .. type(picker_state))
787-
if picker_state then
788-
logger.log("picker_state.selected_count: " .. tostring(picker_state.selected_count))
789-
logger.log("picker_state.filtered_items count: " .. (#picker_state.filtered_items or 0))
790-
end
791752

753+
handlers.sidebar = function(items_or_item, picker_state)
792754
local items_to_show
793-
794-
-- Check if we received selected items as first parameter
795755
if type(items_or_item) == "table" and #items_or_item > 0 and items_or_item[1] and items_or_item[1].text then
796-
-- We received an array of selected items
797756
items_to_show = items_or_item
798-
logger.log("Using selected items passed as parameter")
799757
else
800-
-- We received a single item, use all filtered items from picker state
801758
items_to_show = picker_state.filtered_items
802-
logger.log("Using all filtered items from picker state")
803759
end
804-
805-
logger.log("items_to_show type: " .. type(items_to_show))
806-
if items_to_show then
807-
logger.log("items_to_show count: " .. #items_to_show)
808-
end
809-
logger.log("=== END SIDEBAR DEBUG ===")
810-
811760
local original_picker_opts = picker_state.original_opts or {}
812-
if original_picker_opts then
813-
logger.log("Original picker options found: " .. vim.inspect(picker_state))
814-
end
815761
-- Create sidebar options by copying ALL original options
816762
local sidebar_opts = vim.tbl_deep_extend("force", original_picker_opts, {
817763
-- Only override sidebar-specific settings
818764
sidebar_mode = true,
819765
position = picker_config.sidebar and picker_config.sidebar.position or "right",
820766
width = picker_config.sidebar and picker_config.sidebar.width or 40,
821767
})
822-
823768
selecta.create_sidebar(items_to_show, sidebar_opts, state)
824-
825-
return true -- Close original picker
769+
return true
826770
end
827771

828772
handlers.bookmark = function(items_or_item, picker_state)

0 commit comments

Comments
 (0)