[red-knot] Upgrade to the *new* *new* salsa (#12406)

This commit is contained in:
Micha Reiser 2024-07-29 09:21:24 +02:00 committed by GitHub
parent 9495331a5f
commit e18b4e42d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 483 additions and 415 deletions

View file

@ -2,7 +2,6 @@ use std::ops::Deref;
use std::sync::Arc;
use countme::Count;
use salsa::DebugWithDb;
use ruff_notebook::Notebook;
use ruff_python_ast::PySourceType;
@ -14,9 +13,10 @@ use crate::Db;
/// Reads the source text of a python text file (must be valid UTF8) or notebook.
#[salsa::tracked]
pub fn source_text(db: &dyn Db, file: File) -> SourceText {
let _span = tracing::trace_span!("source_text", ?file).entered();
let path = file.path(db);
let _span = tracing::trace_span!("source_text", file=?path).entered();
let is_notebook = match file.path(db) {
let is_notebook = match path {
FilePath::System(system) => system.extension().is_some_and(|extension| {
PySourceType::try_from_extension(extension) == Some(PySourceType::Ipynb)
}),
@ -129,7 +129,7 @@ enum SourceTextKind {
/// Computes the [`LineIndex`] for `file`.
#[salsa::tracked]
pub fn line_index(db: &dyn Db, file: File) -> LineIndex {
let _span = tracing::trace_span!("line_index", file = ?file.debug(db)).entered();
let _span = tracing::trace_span!("line_index", file = ?file).entered();
let source = source_text(db, file);
@ -139,6 +139,7 @@ pub fn line_index(db: &dyn Db, file: File) -> LineIndex {
#[cfg(test)]
mod tests {
use salsa::EventKind;
use salsa::Setter as _;
use ruff_source_file::OneIndexed;
use ruff_text_size::TextSize;