lune
lune copied to clipboard
Add XDG Base Directory Specification support
Summary
Implements XDG Base Directory Specification compliance for Lune's cache and state directories while maintaining full backwards compatibility with existing installations.
- Cache directory:
$XDG_CACHE_HOME/lune(fallback:~/.lune) - State directory:
$XDG_STATE_HOME/lune(fallback:~/.luneor$XDG_CACHE_HOME/lune) - REPL history: Stored in state directory as
.lune_history - Type definitions: Remain in
~/.lune/.typedefs/for LSP compatibility
Key Features
- Full backwards compatibility: Automatically detects and prefers existing legacy directories
- Environment variable support:
LUNE_CACHEandLUNE_STATEoverride all other settings - Cross-platform: Works on Linux (XDG), Windows (Known Folders), and macOS (Standard Directories)
Implementation Details
- Uses existing
directoriescrate - New
dirsmodule providescache_dir(),state_dir(), andtypedefs_dir()functions - Integrated across all components: build cache, REPL history, LSP setup
- Automatic directory creation prevents file operation errors
Backwards Compatibility
The implementation prioritizes existing user setups:
- If legacy
.lune/targetexists but XDG cache doesn't → use legacy - If legacy
.lune_historyexists but XDG state doesn't → use legacy - Environment variables (
LUNE_CACHE/LUNE_STATE) always take precedence - Fallback to original logic if XDG detection fails
Test Plan
- [x] All existing functionality works unchanged
- [x] New XDG directories are created and used appropriately
- [x] Environment variable overrides work correctly
- [x] Backwards compatibility scenarios function properly
- [x] Cross-platform compatibility verified
- [x] Error handling and fallbacks tested
- [x] Thread safety and cleanup in tests
Fixes #300