Skip to content

Combine three dependency data structures into single HashSet#129

Open
devind-ra wants to merge 23 commits into
jkeresman01:mainfrom
devind-ra:fix/dependency-data-structures-into-hashset
Open

Combine three dependency data structures into single HashSet#129
devind-ra wants to merge 23 commits into
jkeresman01:mainfrom
devind-ra:fix/dependency-data-structures-into-hashset

Conversation

@devind-ra

@devind-ra devind-ra commented Dec 2, 2025

Copy link
Copy Markdown
Collaborator

Description

Refactoring usage in tests and files where all three data structures were used.

Fix for issue #110

Type of change

  • Refactor of tests and codebase

How Has This Been Tested?

Manual testing and unit tests

Configuration:

  • Neovim version (nvim --version): 0.11.5
  • Operating system and version: MacOS 26.1

Checklist:

  • My code follows the style guidelines of this project (stylua)
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation

@devind-ra

Copy link
Copy Markdown
Collaborator Author

Hey @jkeresman01, I think I've been able to do it. Let me know if you find any issues or tweaks that I need to make. Thanks!

@jkeresman01 jkeresman01 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @devind-ra

Sorry for slow response on this.

When I tried testing your changes I've got this 2 errors.

  1. When selecting unique dep for the first time.
E5108: Error executing lua: ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:165: attempt to get length of field 'selected_dependencies' (a nil value)                                                                                                                
stack traceback:                                                                                                                                                                                                                                                                  
        ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:165: in function 'record_selection'                                                                                                                                                                           
        ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:205: in function 'on_select'                                                                                                                                                                                  
        ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:252: in function 'run_replace_or_original'                                                                                                                                                                    
        ...packer/start/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func'                                                                                                                                                                                    
        ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:253: in function <...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:252>    
  1. When trying to remove selected dependency.
E5108: Error executing lua: ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:182: attempt to call method 'remove_key' (a nil value)                                                                                                                                   
stack traceback:                                                                                                                                                                                                                                                                  
        ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:182: in function 'remove_dependency'                                                                                                                                                                          
        ...lizr/ui/components/dependencies/dependencies_display.lua:346: in function 'remove_focused_card'                                                                                                                                                                        
        ...lizr/ui/components/dependencies/dependencies_display.lua:380: in function <...lizr/ui/components/dependencies/dependencies_display.lua:379>                                                                                                                            
Press ENTER or type command to continue              

Didn't quite catch enough time to pinpoint exact root cause.
Could you also look it up, see if same issue is present from your side.

@devind-ra

Copy link
Copy Markdown
Collaborator Author

@jkeresman01, no worries. I'll look into the issue on my side as well and see what's going on. Thanks for the review

@devind-ra

Copy link
Copy Markdown
Collaborator Author

@jkeresman01, apologies for the delay it was a simpler fix than I thought. Let me know how it works on your side!

@jkeresman01

jkeresman01 commented Dec 6, 2025

Copy link
Copy Markdown
Owner

@jkeresman01, apologies for the delay it was a simpler fix than I thought. Let me know how it works on your side!

Hi first issue was resolved and I no longer see errors when selecting dependencies. Nice work on that.

E5108: Error executing lua: ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:165: attempt to get length of field 'selected_dependencies' (a nil value)                                                                                                                
stack traceback:                                                                                                                                                                                                                                                                  
        ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:165: in function 'record_selection'                                                                                                                                                                           
        ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:205: in function 'on_select'                                                                                                                                                                                  
        ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:252: in function 'run_replace_or_original'                                                                                                                                                                    
        ...packer/start/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func'                                                                                                                                                                                    
        ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:253: in function <...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:252>    
        

But second problem is still seen:

Steps to reproduce:

  1. Open telescope picker
  2. Select any dependecy
  3. Move to dependencies panel by pressing
  4. Try to remove selected dependency with dd
  5. Error occurs
E5108: Error executing lua: ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:182: attempt to call method 'remove_key' (a nil value)                                                                                                                                   
stack traceback:                                                                                                                                                                                                                                                                  
        ...alizr.nvim/lua/spring-initializr/telescope/telescope.lua:182: in function 'remove_dependency'                                                                                                                                                                          
        ...lizr/ui/components/dependencies/dependencies_display.lua:346: in function 'remove_focused_card'                                                                                                                                                                        
        ...lizr/ui/components/dependencies/dependencies_display.lua:380: in function <...lizr/ui/components/dependencies/dependencies_display.lua:379>                                                                                                                            

@devind-ra

Copy link
Copy Markdown
Collaborator Author

Can you have a go at seeing if the dd removes the dependency on your side? I tried using that keybind but it wasn't working for me even in main.

Also apologies, I committed to main to fix an issue with the HashSet. It's all reverted now and committed to here instead!

@jkeresman01

Copy link
Copy Markdown
Owner

Can you have a go at seeing if the dd removes the dependency on your side? I tried using that keybind but it wasn't working for me even in main.

Also apologies, I committed to main to fix an issue with the HashSet. It's all reverted now and committed to here instead!

Removing with dd doesn't work after state is restored. If you close the editor and then reopen it at some point it will no longer work. It's reported in here: #136 -- working on fix for that.

You can just reset the form with <C-r> Ctrl + r as a workaround.
After that it should start working.

@devind-ra

Copy link
Copy Markdown
Collaborator Author

Can you have a go at seeing if the dd removes the dependency on your side? I tried using that keybind but it wasn't working for me even in main.
Also apologies, I committed to main to fix an issue with the HashSet. It's all reverted now and committed to here instead!

Removing with dd doesn't work after state is restored. If you close the editor and then reopen it at some point it will no longer work. It's reported in here: #136 -- working on fix for that.

You can just reset the form with <C-r> Ctrl + r as a workaround. After that it should start working.

Ah yep I see what you mean in that issue. With 'Ctrl + r' it seems to be working fine then on my side.

@jkeresman01

Copy link
Copy Markdown
Owner

Can you have a go at seeing if the dd removes the dependency on your side? I tried using that keybind but it wasn't working for me even in main.
Also apologies, I committed to main to fix an issue with the HashSet. It's all reverted now and committed to here instead!

Removing with dd doesn't work after state is restored. If you close the editor and then reopen it at some point it will no longer work. It's reported in here: #136 -- working on fix for that.
You can just reset the form with <C-r> Ctrl + r as a workaround. After that it should start working.

Ah yep I see what you mean in that issue. With 'Ctrl + r' it seems to be working fine then on my side.

Still doesn't work on my side.

But perhaps I explained it a bit poorly in my previous message.

On main removal withdd doesn't work after state is restored, but if we reset form with Ctrl + r and then add some deps and then we try to remove them with dd it will work.

When I checkout your branch the removal with dd no longer works at all with latest changes.

@devind-ra

Copy link
Copy Markdown
Collaborator Author

Hi @jkeresman01, sorry I've been AWOL with contributing to this. Seems to be an issue with removal which I've now carried out using a remove_by_key() method. Lmk if there is other cases I need to be testing which could cause issues!

@jkeresman01 jkeresman01 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

great work but few small improvements are needed.

Comment thread lua/spring-initializr/ui/init.lua Outdated
Comment thread lua/spring-initializr/ui/init.lua Outdated
@devind-ra

Copy link
Copy Markdown
Collaborator Author

Changes should be made now

@jkeresman01

Copy link
Copy Markdown
Owner

Changes should be made now

Hi,

I've started testing this now and found one additional bug that needs to be fixed:

The bug is in restore_saved_state() that causes error when loading saved projects with corrupted data:

The issue is -> Lines 158-183 don't check for nil dependencies before processing them, and there's a duplicate add() call.

This fixes it:

-- Line 154: Initialize HashSet with key function (remove duplicate initialization)
local key_fn = function(entry)
    return entry.id
end
telescope.selected_dependencies_set = HashSet.new({ key_fn = key_fn })

if project.dependencies then
    for _, dep in ipairs(project.dependencies) do
        -- Line 161: Add nil check here
        if dep then
            local entry
            if type(dep) == "table" and dep.id then
                entry = {
                    id = dep.id,
                    name = dep.name or dep.id,
                    description = dep.description or "",
                    group = dep.group or "",
                    label = string.format("[%s] %s", dep.group or "", dep.name or dep.id),
                }
            elseif type(dep) == "string" and dep ~= "" then  -- Add empty string check
                entry = {
                    id = dep,
                    name = dep,
                    description = "",
                    group = "",
                    label = dep,
                }
            end

            -- Only add once (remove the duplicate add() from line 167)
            if entry then
                telescope.selected_dependencies_set:add(entry)
            end
        end
    end
end

Changes needed to make this work:
Add if dep then check before processing and dep ~= "" for string dependencies
Remove duplicate HashSet initialization (line 154) and remove duplicate add(dep.id) call (was line 167)

I've tested changes with this fix and it seems to be working as expected.
It prevents crashes when saved files contain nil or invalid dependencies.

@devind-ra

Copy link
Copy Markdown
Collaborator Author

Thanks for spotting that, changes should be implemented from your comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants