Commit c704c76
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_helpers1 parent d759583 commit c704c76
File tree
58 files changed
+7541
-1937
lines changed- crates
- deps-cargo
- src
- deps-core/src
- deps-lsp/src
- handlers
- deps-npm
- benches
- src
- deps-pypi
- benches
- src
- docs
- templates
- deps-ecosystem
- src
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 changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
0 commit comments