Expand description
ยง๐ Oak VFS: Virtual File System
oak-vfs provides a unified Virtual File System (VFS) abstraction for the Oak language framework. It manages source files, metadata, and coordinate mapping (line/column to byte offset).
ยง๐ Features
- Abstraction: Unified interface for memory-based and disk-based storage.
- Coordinate Mapping: Efficiently convert between byte offsets and LSP-compatible line/column positions.
- Metadata: Access file types, lengths, and modification timestamps.
- Change Tracking: Watch for file system changes (disk-based VFS).
- WASM Compatible: Works in browser environments via
MemoryVfs.
ยง๐ฆ Quick Start
ยงUsing Memory Vfs
use oak_vfs::{MemoryVfs, Vfs, WritableVfs};
let vfs = MemoryVfs::new();
vfs.write_file("file:///test.txt", "line 1\nline 2");
if let Some(source) = vfs.get_source("file:///test.txt") {
println!("Content: {}", source.get_text());
}ยงCoordinate Conversion
use oak_vfs::LineMap;
use oak_core::source::SourceText;
let source = SourceText::new("first line\nsecond line");
let line_map = LineMap::from_source(&source);
// Convert byte offset to (line, col)
let (line, col) = line_map.offset_to_line_col_utf16(&source, 15);
println!("Position: {}:{}", line, col);ยง๐๏ธ Core Components
- Vfs: The primary trait for file access.
- MemoryVfs: Thread-safe, in-memory implementation.
- DiskVfs: Physical file system access.
- LineMap: Fast lookup table for line starts.
ยง๐ ๏ธ Architecture
The VFS layer sits between the raw source text and higher-level language services. It ensures that components like the Lexer and Parser can work with Source abstractions without worrying about where the data originates.
Re-exportsยง
pub use vfs::MemoryVfs;pub use vfs::DiskVfs;pub use vfs::DiskWatcher;pub use vfs::VfsEvent;pub use vfs::VfsWatcher;
Modulesยง
- vfs
- Virtual File System implementation and utilities. Virtual File System (VFS) implementations and management.
Structsยง
- File
Metadata - Metadata for a file or directory in the VFS.
- LineMap
- A map that tracks line starts in a source file for efficient coordinate conversion.
Enumsยง
- File
Type - Type of a file in the VFS.
Traitsยง
- Vfs
- A trait for a Virtual File System that can provide source content and location mapping.
- Writable
Vfs - A trait for a Virtual File System that supports writing.