Skip to content

fix: dedupe completion items so types/keywords don't appear twice - #26

Merged
cushycush merged 1 commit into
mainfrom
fix/dedup-completions
May 1, 2026
Merged

fix: dedupe completion items so types/keywords don't appear twice#26
cushycush merged 1 commit into
mainfrom
fix/dedup-completions

Conversation

@cushycush

Copy link
Copy Markdown
Owner

Closes #25.

The Neovim completion popup was showing every type and keyword twice (see the screenshot in #25Scatter3D, Surface3D, etc. all listed in pairs).

The completion handler builds its result list from two sources: an AST-driven block that picks categories based on the node under the cursor, and a context-switch fallback keyed off the current line. Both append the same generic buckets (types, imports, properties, keywords). When the user types an uppercase name inside an object body, which is the common case, both fire and every label gets added twice.

Fix is to dedupe by Label, first-occurrence wins, just before returning. First-occurrence is deliberate so the AST branch's more specific items (e.g. type-specific properties for the enclosing type) take precedence over the generic switch-case fallbacks that follow.

Added a regression test that walks three real positions through Completion() and asserts no label repeats. Confirmed it fails on the unfixed code with dozens of duplicates and passes with the dedupe in place.

Test plan

  • go test -race ./...
  • New TestCompletionNoDuplicateLabels covers type position, blank line in object body, and import position
  • Verified the test catches the bug by reverting the dedupe and watching it fail

Closes #25.

The completion handler builds its result list from two sources: an
AST-driven block that picks categories based on the node under the
cursor, and a context-switch fallback keyed off the current line. Both
appended the same generic buckets (types, imports, properties,
keywords), so when the user typed an uppercase name inside an object
body — the common case — every label appeared twice.

Dedupe by Label, first-occurrence wins, just before returning the list.
First-occurrence is deliberate: the AST branch runs first, so its more
specific items (e.g. type-specific properties for the enclosing type)
take precedence over the generic switch-case fallbacks that follow.

Added a regression test that walks three real positions through
Completion() and asserts no label repeats. Confirmed it fails on the
unfixed code with dozens of duplicates (Item, Rectangle, import,
property, ...) and passes with the dedupe in place.
@cushycush
cushycush merged commit 767f2d0 into main May 1, 2026
3 checks passed
@cushycush
cushycush deleted the fix/dedup-completions branch May 1, 2026 05:15
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.

double autocomplite suggestion

1 participant