mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Replace row/column based Location
with byte-offsets. (#3931)
This commit is contained in:
parent
ee91598835
commit
cab65b25da
418 changed files with 6203 additions and 7040 deletions
|
@ -1,8 +1,8 @@
|
|||
use ruff_text_size::TextRange;
|
||||
use rustc_hash::FxHashMap;
|
||||
use rustpython_parser::ast::Location;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::Range;
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A representation of an individual name imported via any import statement.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
@ -102,31 +102,28 @@ impl FutureImport for AnyImport<'_> {
|
|||
}
|
||||
|
||||
/// A representation of a module reference in an import statement.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct ModuleImport {
|
||||
module: String,
|
||||
location: Location,
|
||||
end_location: Location,
|
||||
range: TextRange,
|
||||
}
|
||||
|
||||
impl ModuleImport {
|
||||
pub fn new(module: String, location: Location, end_location: Location) -> Self {
|
||||
Self {
|
||||
module,
|
||||
location,
|
||||
end_location,
|
||||
}
|
||||
pub fn new(module: String, range: TextRange) -> Self {
|
||||
Self { module, range }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&ModuleImport> for Range {
|
||||
fn from(import: &ModuleImport) -> Range {
|
||||
Range::new(import.location, import.end_location)
|
||||
impl From<&ModuleImport> for TextRange {
|
||||
fn from(import: &ModuleImport) -> TextRange {
|
||||
import.range
|
||||
}
|
||||
}
|
||||
|
||||
/// A representation of the import dependencies between modules.
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct ImportMap {
|
||||
/// A map from dot-delimited module name to the list of imports in that module.
|
||||
module_to_imports: FxHashMap<String, Vec<ModuleImport>>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue