Add XDG Base Directory Specification support#342
Open
christopher-buss wants to merge 8 commits into
Open
Conversation
Adds etcetera 0.10.0 to enable cross-platform XDG directory compliance for cache and state files.
Adds cross-platform XDG-compliant directory handling for cache and state files while maintaining LSP compatibility for type definitions. - Add etcetera 0.10.0 dependency for robust XDG support - Create dirs.rs module with cache_dir(), state_dir(), and typedefs_dir() - Support LUNE_CACHE and LUNE_STATE environment variable overrides - Include comprehensive unit tests with cross-platform compatibility - Use proper anyhow::Result error handling matching project standards - Keep type definitions in ~/.lune/.typedefs/ for LSP compatibility Part of implementing issue lune-org#300 - XDG Base Directory specification support.
Implements XDG Base Directory Specification for cache and state directories while maintaining backwards compatibility by preferring existing legacy directories over new XDG locations to minimize user friction. Key features: - Respects XDG_CACHE_HOME and XDG_STATE_HOME environment variables - Supports LUNE_CACHE and LUNE_STATE override variables - Graceful fallback when state directory is unsupported (Windows/macOS) - Comprehensive test coverage with cross-platform compatibility - Maintains typedefs in home directory for LSP compatibility Addresses issue lune-org#300 - Cache & REPL history paths do not respect XDG
Eliminates duplicate dependency by using the existing directories crate instead of etcetera for XDG Base Directory support. Both provide identical XDG compliance and cross-platform directory handling. Changes: - Remove etcetera dependency from Cargo.toml - Update dirs.rs to use directories::BaseDirs instead of choose_base_strategy() - Fix test concurrency issues with proper mutex synchronization - Maintain identical XDG functionality and backwards compatibility Benefits: - Consistent dependency usage across codebase - Reduced dependency count and build complexity - Same XDG compliance behavior on all platforms - All existing functionality preserved
Integrates XDG helper functions throughout the Lune codebase, providing
full XDG Base Directory Specification compliance while maintaining
backwards compatibility.
Integration changes:
- Add dirs module declaration to main.rs for crate-wide access
- Update build target cache (target.rs) to use XDG cache_dir()
- Update REPL history (repl.rs) to use XDG state_dir()
- Update LSP typedefs (setup.rs) to use XDG typedefs_dir()
- Fix collapsible-if clippy warnings in test cleanup code
XDG compliance behavior:
- Build cache: $XDG_CACHE_HOME/lune/target (fallback: ~/.lune/target)
- REPL history: $XDG_STATE_HOME/lune/.lune_history (fallback: ~/.lune_history)
- LSP typedefs: ~/.lune/.typedefs/{version}/ (consistent for LSP compatibility)
All functions include robust error handling with fallback to original
logic if XDG helpers fail. Environment variable overrides (LUNE_CACHE,
LUNE_STATE) take precedence. Backwards compatibility ensures existing
user setups continue working without changes.
Documents the new XDG Base Directory Specification compliance with backwards compatibility for existing users. Includes details about directory locations, environment variable overrides, and automatic detection of existing installations.
Create parent directories for .lune_history file when using XDG state directory to prevent file creation errors when the state directory doesn't exist yet.
Replace unwrap_or_else with ignored error parameters with unwrap_or for better code clarity and performance in XDG fallback logic.
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
Implements XDG Base Directory Specification compliance for Lune's cache and state directories while maintaining full backwards compatibility with existing installations.
$XDG_CACHE_HOME/lune(fallback:~/.lune)$XDG_STATE_HOME/lune(fallback:~/.luneor$XDG_CACHE_HOME/lune).lune_history~/.lune/.typedefs/for LSP compatibilityKey Features
LUNE_CACHEandLUNE_STATEoverride all other settingsImplementation Details
directoriescratedirsmodule providescache_dir(),state_dir(), andtypedefs_dir()functionsBackwards Compatibility
The implementation prioritizes existing user setups:
.lune/targetexists but XDG cache doesn't → use legacy.lune_historyexists but XDG state doesn't → use legacyLUNE_CACHE/LUNE_STATE) always take precedenceTest Plan
Fixes #300