1 unstable release

Uses new Rust 2024

new 0.0.1 Mar 29, 2025

#30 in #source-map


Used in 11 crates

MIT license

15KB
302 lines

Source Map Cache

Manages source files for a compiler, providing mapping between file IDs, paths, and source locations (line/column).

Overview

This crate provides the SourceMap struct, which is responsible for:

  • Mounting Directories: Associates symbolic names ("mounts") with file system directories containing source code.
  • Reading & Caching: Reads source files either by absolute path or relative to a mount point, caching their contents and metadata.
  • File IDs: Assigns a unique FileId (u16) to each loaded file.
  • Location Mapping: Efficiently converts byte offsets within a file (often obtained from parsers or lexers using crates like source-map-node) into human-readable line and column numbers.
  • Source Snippets: Retrieves the source text corresponding to a given span (file ID, offset, length).

Installation

Add this to your Cargo.toml:

[dependencies]
source-map-cache = "0.0.1"

License

This project is licensed under the MIT License - see the LICENSE file for details.

Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/swamp/swamp

Dependencies

~31KB