lune icon indicating copy to clipboard operation
lune copied to clipboard

Add XDG Base Directory Specification support

Open christopher-buss opened this issue 4 months ago • 0 comments

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: ~/.lune or $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_CACHE and LUNE_STATE override all other settings
  • Cross-platform: Works on Linux (XDG), Windows (Known Folders), and macOS (Standard Directories)

Implementation Details

  • Uses existing directories crate
  • New dirs module provides cache_dir(), state_dir(), and typedefs_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:

  1. If legacy .lune/target exists but XDG cache doesn't → use legacy
  2. If legacy .lune_history exists but XDG state doesn't → use legacy
  3. Environment variables (LUNE_CACHE/LUNE_STATE) always take precedence
  4. 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

christopher-buss avatar Jul 30 '25 18:07 christopher-buss