Skip to content

Fix: remove duplicate word suggestions from multiple dictionaries - #82

Open
0xaaadnf wants to merge 1 commit into
uga-rosa:mainfrom
0xaaadnf:fix-duplicate-suggestions
Open

Fix: remove duplicate word suggestions from multiple dictionaries#82
0xaaadnf wants to merge 1 commit into
uga-rosa:mainfrom
0xaaadnf:fix-duplicate-suggestions

Conversation

@0xaaadnf

Copy link
Copy Markdown

Description

This PR fixes an issue where duplicate completion suggestions were returned if the same word existed across multiple dictionary files.

Problem

When multiple dictionary files contain overlapping words, the plugin includes the word as a suggestion for each file it appears in, resulting in duplicate entries in the completion menu.

How to Reproduce

  1. Configure the plugin with multiple dictionary paths:
local paths = {
    "/tmp/dict1.txt",
    "/tmp/dict2.txt",
}
require("cmp_dictionary").setup({
    paths = paths,
})
  1. Add overlapping words across the files:

/tmp/dict1.txt

red
blue
green

/tmp/dict2.txt

pink
blue
yellow
  1. Trigger completion for blue.
  • Expected: A single blue suggestion.
  • Actual (before fix): Two blue suggestions.

Solution

Added a filtering step using a local set (seen) to deduplicate completion items by label before returning them. blue (and any other repeated word) now appears only once.

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.

1 participant