Skip to content

fix(composer): enable preserve_order to fix position tracking for out-of-order packages#86

Merged
bug-ops merged 1 commit intomainfrom
84-composer-position-tracking
Mar 28, 2026
Merged

fix(composer): enable preserve_order to fix position tracking for out-of-order packages#86
bug-ops merged 1 commit intomainfrom
84-composer-position-tracking

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 28, 2026

Summary

  • Enable serde_json preserve_order feature in deps-composer so composer.json entries are iterated in file order (via IndexMap) rather than alphabetical order (via BTreeMap)
  • Add regression test: test_position_tracking_out_of_alphabetical_order covering the exact reproduction case from the issue

Root cause

parse_section() advanced search_start sequentially as each dependency was matched. Without preserve_order, serde_json::Map iterates alphabetically. A package appearing earlier in the file but later alphabetically was searched starting from a byte offset already past its location, leaving name_range/version_range at (0,0)→(0,0).

Impact before fix

  • Hover: returned null for affected packages
  • Inlay hints: missing version badge
  • Diagnostics: outdated versions not flagged

Fixes #84

Test plan

  • New test test_position_tracking_out_of_alphabetical_order covers the exact reproduction scenario (laravel/framework → guzzlehttp/guzzle → symfony/console)
  • All 1305 workspace tests pass
  • cargo clippy --workspace --all-targets --all-features -- -D warnings clean
  • cargo +nightly fmt --all -- --check clean

@github-actions github-actions Bot added documentation Improvements or additions to documentation rust Rust code changes parser Parser changes needs-review Needs review size: M 50-200 lines changed labels Mar 28, 2026
@bug-ops bug-ops force-pushed the 84-composer-position-tracking branch from bb62f3d to 1206b06 Compare March 28, 2026 21:08
@bug-ops bug-ops enabled auto-merge (squash) March 28, 2026 21:08
@bug-ops bug-ops force-pushed the 84-composer-position-tracking branch from 1206b06 to 3ee9e9a Compare March 28, 2026 21:17
…-of-order packages

serde_json::Map without preserve_order uses BTreeMap which iterates alphabetically.
parse_section() advanced search_start sequentially, so packages appearing earlier
in the file but later alphabetically were searched from a position already past
their location, leaving name_range/version_range at (0,0)->( 0,0).

Enabling the preserve_order feature makes serde_json use IndexMap, preserving
insertion (file) order so sequential search_start advancement stays correct.

Fixes #84
@bug-ops bug-ops force-pushed the 84-composer-position-tracking branch from 3ee9e9a to 3c3f86b Compare March 28, 2026 21:25
@bug-ops bug-ops merged commit 6fe1052 into main Mar 28, 2026
20 checks passed
@bug-ops bug-ops deleted the 84-composer-position-tracking branch March 28, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation needs-review Needs review parser Parser changes rust Rust code changes size: M 50-200 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(composer): position tracking incorrect for out-of-alphabetical-order packages

1 participant