A Scala library providing compile-time source code metadata like file, line, and name, similar to Python's __name__ or C++'s __LINE__.
SourceCode is a Scala library that provides compile-time source code metadata, such as file names, line numbers, and variable names, to programs at runtime. It solves the problem of manually tagging debug statements or logging with contextual information, reducing boilerplate and improving debuggability in applications like logging systems, domain-specific languages, and enumeration definitions.
Scala developers building applications that require detailed debugging, logging, or DSLs where automatic source context improves maintainability and reduces manual errors.
Developers choose SourceCode because it offers a lightweight, performant way to embed source metadata without runtime overhead, works across Scala platforms (JVM, JS, Native), and integrates seamlessly via implicits to keep code clean and expressive.
Scala library providing "source" metadata to your program, similar to Python's name, C++'s LINE or Ruby's FILE.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses macros to avoid runtime reflection, making it orders of magnitude faster than stack inspection and compatible with Scala.js where reflection isn't available, as stated in the README.
Works seamlessly on Scala-JVM, Scala.js, and Scala Native with the same codebase, demonstrated by cross-build instructions in the download section.
Allows functions to automatically capture source context via implicit parameters, reducing boilerplate in logging and DSLs, as shown in examples like the debug function with sourcecode.Enclosing.
Provides a wide range of source information including file, line, name, full name, enclosing, and source text capture, with options for synthetic names via .Machine variants, detailed in the Overview.
Requires Scala 2.12+ or Scala 3.3.1+ as of version 0.4.0, which can exclude projects on older compiler versions, limiting adoption in legacy environments.
Relies on compile-time macros that can be tricky to debug and may not work smoothly with all IDEs or build tools, as indicated by past fixes for REPL issues in the version history.
Primarily tailored for debugging, logging, and DSLs, so it might not justify inclusion in general-purpose projects where source metadata isn't a priority.