Skip to content

Commit c704c76

Browse files
authored
refactor: trait-based ecosystem architecture (#27)
* refactor(deps-core): add trait-based ecosystem architecture - Add Ecosystem trait for plugin-based ecosystem support - Add EcosystemRegistry for dynamic ecosystem registration - Add Registry, Version, Metadata traits with trait objects - Add ParseResult, Dependency traits for manifest parsing - Add comprehensive tests for all new traits - Mark legacy traits as deprecated with migration guide * refactor(deps-cargo): implement Ecosystem trait - Add CargoEcosystem implementing Ecosystem trait - Implement Registry trait for CratesIoRegistry - Implement Version trait for CargoVersion - Implement Metadata trait for CrateInfo - Implement Dependency trait for ParsedDependency - Implement ParseResult trait for CargoParser output - All LSP operations delegated to ecosystem methods * test(deps-cargo): add ecosystem.rs tests and fix panic - Add 15 unit tests for CargoEcosystem trait implementation - Fix potential panic in version comparison (unwrap → unwrap_or) - Test coverage: ranges_overlap, inlay hints, trait methods - Add once_cell to workspace dev-dependencies * refactor(deps-lsp): add ecosystem registry and simplified handlers - Add EcosystemRegistry to ServerState for dynamic ecosystem routing - Add ecosystem_id and parse_result fields to DocumentState - Create new simplified handlers delegating to ecosystem traits: - inlay_hints_new.rs - hover_new.rs - code_actions_new.rs - diagnostics_new.rs - Add document_lifecycle_new.rs for unified document handling - Maintain backward compatibility with legacy handlers * refactor(npm,pypi): implement Ecosystem trait and add error modules Phase 4: npm and PyPI Migration - Create NpmEcosystem with full Ecosystem trait implementation - Create PypiEcosystem with full Ecosystem trait implementation - Add ecosystem-specific error modules (NpmError, CargoError) - Implement Dependency, Version, Metadata traits for both ecosystems - Register npm and PyPI ecosystems in ServerState - Fix security issues: - URL-encode package names in package_url() to prevent injection - Use checked_add() for version upper bound calculation - Update parse_content signatures to include URI parameter - Add thiserror dependency to npm and cargo crates * refactor: clean up legacy handlers and integrate error modules - Remove _new suffixes from handler files, replacing old implementations - Delete legacy ecosystem-specific handlers (cargo/npm/pypi_handler_impl.rs) - Unify server.rs to use single handle_open/handle_change via EcosystemRegistry - Integrate NpmError in deps-npm parser with Result<T> alias - Integrate CargoError in deps-cargo parser with Result<T> alias - Remove recursive fallback patterns from all handlers - Fix unused import warnings in test modules Deleted files: - document_lifecycle_new.rs (content moved to document_lifecycle.rs) - code_actions_new.rs, diagnostics_new.rs, hover_new.rs, inlay_hints_new.rs - cargo_handler_impl.rs, npm_handler_impl.rs, pypi_handler_impl.rs This completes the migration to trait-based ecosystem architecture. * feat(core): add ecosystem templates and boilerplate macros Phase 5 deliverables: Templates (templates/deps-ecosystem/): - Cargo.toml.template - crate configuration - lib.rs.template - module exports - error.rs.template - error types with From conversions - types.rs.template - Dependency/Version types - parser.rs.template - manifest parser with position tracking - registry.rs.template - package registry client - ecosystem.rs.template - Ecosystem trait implementation Documentation (docs/): - ECOSYSTEM_GUIDE.md - step-by-step implementation guide Macros (deps-core/src/macros.rs): - impl_dependency! - implements Dependency + DependencyInfo traits - impl_version! - implements Version + VersionInfo traits - impl_metadata! - implements Metadata + PackageMetadata traits - impl_parse_result! - implements ParseResult trait Each macro reduces ~30-50 lines of boilerplate per ecosystem. Phase 6 will apply these macros to existing ecosystems. * refactor(types): apply boilerplate macros to ecosystem types Phase 6 deliverables: - Applied impl_dependency!, impl_version!, impl_metadata! macros to deps-npm - NpmDependency, NpmVersion, NpmPackage now use macro implementations - Reduced ~100 lines of boilerplate trait implementations - Applied impl_version! macro to deps-pypi (PypiVersion) - PypiDependency and PypiPackage require custom logic (source mapping, URL lookups) - deps-cargo types unchanged (require custom source mapping and features logic) - Fixed clippy warnings: - assert!(bool) instead of assert_eq!(bool, true/false) - Moved trait impls before test modules in deps-cargo/types.rs - Removed empty placeholder tests from deps-lsp handlers - Updated benchmark files with uri parameter for parser functions Macro usage summary: - deps-npm: 3 types using macros (full coverage) - deps-pypi: 1 type using macros (PypiVersion) - deps-cargo: 0 types (custom logic required) * fix(docs): wrap bare URL in angle brackets for rustdoc * test(deps-lsp): improve test coverage for handlers and document modules Coverage improvements: - handlers/code_actions.rs: 0% → 98.20% - handlers/diagnostics.rs: 0% → 97.14% - handlers/hover.rs: 0% → 100% - handlers/inlay_hints.rs: 17.78% → 98.72% - document.rs: 62.99% → 92.68% - document_lifecycle.rs: 0% → 33.67% Added 40+ unit tests covering: - Document lifecycle for all ecosystems (Cargo, npm, PyPI) - Handler functions with mock data - EcosystemRegistry operations - Edge cases and error handling Overall coverage: 77.81% → 83.69% (+5.88%) * style: fix formatting in test modules * feat(lsp): improve hover, code actions, and lock file support - Show resolved version from lock file in hover (Current field) - Add 'Press Cmd+. to update version' hint to hover popup - Change code actions from QUICKFIX to REFACTOR kind (LSP spec compliance) - Expand hover/code action trigger to name AND version ranges - Add build-system section parsing for PyPI - Fix position tracking with HashSet for duplicate dependencies - Remove quotes from PyPI code action new_text (version_range fix) * refactor(core): extract shared LSP logic into lsp_helpers module - Add EcosystemFormatter trait for ecosystem-specific formatting - Create CargoFormatter, NpmFormatter, PypiFormatter implementations - Refactor all ecosystems to delegate to shared lsp_helpers functions - Remove ~770 lines of duplicated code across ecosystems * chore(templates): update ecosystem templates to use lsp_helpers
1 parent d759583 commit c704c76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+7541
-1937
lines changed

Cargo.lock

Lines changed: 23 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ futures = "0.3"
2424
insta = "1"
2525
mockito = "1"
2626
node-semver = "2.2"
27+
once_cell = "1.20"
2728
pep440_rs = "0.7"
2829
pep508_rs = "0.9"
2930
reqwest = { version = "0.12", default-features = false }

crates/deps-cargo/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ async-trait = { workspace = true }
1515
semver = { workspace = true }
1616
serde = { workspace = true, features = ["derive"] }
1717
serde_json = { workspace = true }
18+
thiserror = { workspace = true }
1819
tokio = { workspace = true, features = ["fs"] }
1920
toml_edit = { workspace = true }
2021
tower-lsp = { workspace = true }
@@ -24,8 +25,10 @@ urlencoding = { workspace = true }
2425
[dev-dependencies]
2526
criterion = { workspace = true, features = ["html_reports"] }
2627
insta = { workspace = true, features = ["json"] }
28+
once_cell = { workspace = true }
2729
tempfile = { workspace = true }
2830
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
31+
tokio-test = { workspace = true }
2932

3033
[[bench]]
3134
name = "cargo_benchmarks"

0 commit comments

Comments
 (0)