Skip to main content

FileResolver

Trait FileResolver 

Source
pub trait FileResolver {
    // Required methods
    fn path(&self, file: File) -> &str;
    fn input(&self, file: File) -> Input;
    fn notebook_index(&self, file: &UnifiedFile) -> Option<NotebookIndex>;
    fn is_notebook(&self, file: &UnifiedFile) -> bool;
    fn current_directory(&self) -> &Path;
}
Expand description

A trait that facilitates the retrieval of source code from a Span.

At present, this is tightly coupled with a Salsa database. In the future, it is intended for this resolver to become an abstraction providing a similar API. We define things this way for now to keep the Salsa coupling at “arm’s” length, and to make it easier to do the actual de-coupling in the future.

For example, at time of writing (2025-03-07), the plan is (roughly) for Ruff to grow its own interner of file paths so that a Span can store an interned ID instead of a (roughly) Arc<Path>. This interner is planned to be entirely separate from the Salsa interner used by ty, and so, callers will need to pass in a different “resolver” for turning Spans into actual file paths/contents. The infrastructure for this isn’t fully in place, but this type serves to demarcate the intended abstraction boundary.

Required Methods§

Source

fn path(&self, file: File) -> &str

Returns the path associated with the file given.

Source

fn input(&self, file: File) -> Input

Returns the input contents associated with the file given.

Source

fn notebook_index(&self, file: &UnifiedFile) -> Option<NotebookIndex>

Returns the NotebookIndex associated with the file given, if it’s a Jupyter notebook.

Source

fn is_notebook(&self, file: &UnifiedFile) -> bool

Returns whether the file given is a Jupyter notebook.

Source

fn current_directory(&self) -> &Path

Returns the current working directory.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§