feat(go): Add Go ecosystem support - Complete (Phases 1-4)#40
Merged
Conversation
Add Go ecosystem support for deps-lsp. This phase implements: Core Types (types.rs): - GoDependency with module_path, version, directive, indirect - GoDirective enum (Require, Replace, Exclude, Retract) - GoVersion with pseudo-version and retracted tracking - GoMetadata with pkg.go.dev documentation URL go.mod Parser (parser.rs): - LineOffsetTable for O(log n) position lookups - UTF-16 character position calculation for LSP - Support for require, replace, exclude directives - Multi-line block parsing with state machine - Inline comment handling (including URL-aware // stripping) - Indirect dependency marker extraction Version Utilities (version.rs): - Module path escaping (uppercase → !lowercase) - Pseudo-version detection and base version extraction - Semantic version comparison with +incompatible handling Error Handling (error.rs): - 10 error variants with thiserror integration - Bidirectional deps_core::DepsError conversion - Helper factory methods for common errors Tests: 41 unit tests, all passing Coverage: ~85% across all modules Snapshots: insta snapshot tests for parser output
Codecov Report❌ Patch coverage is @@ Coverage Diff @@
## main #40 +/- ##
==========================================
+ Coverage 85.42% 85.72% +0.29%
==========================================
Files 46 54 +8
Lines 12655 14684 +2029
==========================================
+ Hits 10811 12588 +1777
- Misses 1844 2096 +252
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Add GoRegistry for proxy.golang.org integration: - HTTP client with HttpCache for ETag/Last-Modified caching - get_versions() - fetch all available versions for a module - get_version_info() - get metadata for specific version - get_latest() - fetch latest stable version - get_go_mod() - retrieve go.mod content for a version - Module path escaping (uppercase to !lowercase) - deps_core::Registry trait implementation Security hardening: - Module path length validation (max 500 chars) - Version string validation (no path traversal, valid chars) - Input sanitization before URL construction Performance optimizations: - Zero-copy parsing with std::str::from_utf8 - Synchronous parse functions (no async overhead) - Efficient module path escaping with encode_utf8() 62 tests passing with comprehensive coverage.
Add full LSP support for Go modules (go.mod files): GoFormatter (formatter.rs): - Unquoted version format for go.mod - Package URLs to pkg.go.dev - Version matching with boundary checking - URL encoding for special characters GoEcosystem (ecosystem.rs): - Ecosystem trait implementation for LSP handlers - Inlay hints, hover, code actions, diagnostics - Version completion from proxy.golang.org - Retracted version filtering LSP Integration (state.rs): - Go variant in Ecosystem enum with go.mod detection - UnifiedDependency::Go and UnifiedVersion::Go - GoEcosystem registration in ServerState Performance optimizations: - Single-pass version completion (no double iteration) - Parser Vec pre-allocation 690 tests passing.
Add 25 new tests to address critical coverage gaps: Ecosystem Tests (ecosystem.rs): - Inlay hint generation (up-to-date, needs update, no cache) - Hover generation for module paths - Code action generation - Completion context detection (package name, version) - Parse manifest error handling State Integration Tests (state.rs): - Ecosystem detection from filenames (go.mod) - Ecosystem detection from URIs - UnifiedDependency::Go variant methods - UnifiedVersion::Go variant methods - DocumentState Go ecosystem support Coverage improvements: - ecosystem.rs: 73% -> 83% - state.rs: Go variants fully covered 713 tests passing (9 ignored for network access).
README updates: - Add Go Modules to supported ecosystems table - Add go.sum to lock file support list - Add deps-go to project structure - Create deps-go README with usage examples - Update deps-core to mention deps-go CI updates: - Add deps-go to per-crate coverage generation - Add codecov upload step for deps-go coverage Other: - Add **/snapshots/ to .gitignore
Implement LockFileProvider for Go ecosystem: - Parse go.sum format (module_path version h1:hash) - Skip /go.mod entries (module file checksums) - Validate h1: prefix for checksums - First occurrence wins (Go's MVS algorithm) - Async file operations with staleness detection - Workspace search (up to 5 levels) Integration: - GoEcosystem::lockfile_provider() returns GoSumParser - Resolved versions now available for inlay hints 22 lockfile tests, 97.66% coverage.
- Rewrite test_parse_complex_go_mod to use regular assertions - Remove insta dev-dependency from deps-go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds complete Go ecosystem support to deps-lsp, implementing all 4 phases plus lockfile support.
Phase 1: Core Types and Parser
Core Types (
types.rs)GoDependencywith module_path, version, directive, indirect flagsGoDirectiveenum: Require, Replace, Exclude, RetractGoVersionwith pseudo-version and retracted trackingGoMetadatawith pkg.go.dev documentation URLgo.mod Parser (
parser.rs)LineOffsetTablefor O(log n) position lookupshttps://correctly)Version Utilities (
version.rs)!lowercase)+incompatiblehandlingError Handling (
error.rs)deps_core::DepsErrorconversionPhase 2: Registry Client
registry.rs)/@v/listendpoint/@latestendpointPhase 3: LSP Features Integration
EcosystemHandler (
ecosystem.rs)deps_core::EcosystemHandlertraitFormatter (
formatter.rs)Phase 4: Comprehensive Testing
Lockfile Support
lockfile.rs)LockFileProvidertraitmodule_path version h1:hashformat/go.modchecksum entriesh1:hash prefixReview Process
Each phase went through:
CI/CD Updates
Test plan
cargo nextest run -p deps-go)cargo test -p deps-go --doc)cargo clippy -p deps-go --all-targets -- -D warnings)cargo doc -p deps-go --no-deps)cargo +nightly fmt --check)cargo deny check)