Rename ruff_python_semantic's Context struct to SemanticModel (#4565)

This commit is contained in:
Charlie Marsh 2023-05-21 22:35:03 -04:00 committed by GitHub
parent 3238743a7b
commit 19c4b7bee6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
304 changed files with 1253 additions and 1142 deletions

View file

@ -1,6 +1,5 @@
use ruff_text_size::TextRange;
use rustc_hash::FxHashMap;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

View file

@ -1,8 +1,9 @@
use memchr::{memchr2, memrchr2};
use ruff_text_size::{TextLen, TextRange, TextSize};
use std::iter::FusedIterator;
use std::ops::Deref;
use memchr::{memchr2, memrchr2};
use ruff_text_size::{TextLen, TextRange, TextSize};
/// Extension trait for [`str`] that provides a [`UniversalNewlineIterator`].
pub trait StrExt {
fn universal_newlines(&self) -> UniversalNewlineIterator<'_>;
@ -337,10 +338,12 @@ impl Deref for LineEnding {
#[cfg(test)]
mod tests {
use super::UniversalNewlineIterator;
use crate::newlines::Line;
use ruff_text_size::TextSize;
use crate::newlines::Line;
use super::UniversalNewlineIterator;
#[test]
fn universal_newlines_empty_str() {
let lines: Vec<_> = UniversalNewlineIterator::from("").collect();

View file

@ -9,7 +9,6 @@ use rustpython_parser::ast::{
};
use crate::newlines::LineEnding;
use crate::source_code::stylist::{Indentation, Quote, Stylist};
mod precedence {
@ -1457,9 +1456,9 @@ impl<'a> Generator<'a> {
#[cfg(test)]
mod tests {
use crate::newlines::LineEnding;
use rustpython_parser as parser;
use crate::newlines::LineEnding;
use crate::source_code::stylist::{Indentation, Quote};
use crate::source_code::Generator;

View file

@ -1,13 +1,15 @@
use crate::source_code::SourceLocation;
use ruff_text_size::{TextLen, TextRange, TextSize};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt::{Debug, Formatter};
use std::num::NonZeroUsize;
use std::ops::Deref;
use std::sync::Arc;
use ruff_text_size::{TextLen, TextRange, TextSize};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::source_code::SourceLocation;
/// Index for fast [byte offset](TextSize) to [`SourceLocation`] conversions.
///
/// Cloning a [`LineIndex`] is cheap because it only requires bumping a reference count.
@ -312,9 +314,10 @@ const fn unwrap<T: Copy>(option: Option<T>) -> T {
#[cfg(test)]
mod tests {
use ruff_text_size::TextSize;
use crate::source_code::line_index::LineIndex;
use crate::source_code::{OneIndexed, SourceLocation};
use ruff_text_size::TextSize;
#[test]
fn ascii_index() {

View file

@ -1,11 +1,13 @@
//! Struct used to efficiently slice source code at (row, column) Locations.
use crate::newlines::find_newline;
use crate::source_code::{LineIndex, OneIndexed, SourceCode, SourceLocation};
use std::ops::Add;
use memchr::{memchr2, memrchr2};
use once_cell::unsync::OnceCell;
use ruff_text_size::{TextLen, TextRange, TextSize};
use std::ops::Add;
use crate::newlines::find_newline;
use crate::source_code::{LineIndex, OneIndexed, SourceCode, SourceLocation};
pub struct Locator<'a> {
contents: &'a str,

View file

@ -1,22 +1,25 @@
mod generator;
mod indexer;
mod line_index;
mod locator;
mod stylist;
use std::fmt::{Debug, Formatter};
use std::sync::Arc;
pub use crate::source_code::line_index::{LineIndex, OneIndexed};
pub use generator::Generator;
pub use indexer::Indexer;
pub use locator::Locator;
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser as parser;
use rustpython_parser::{lexer, Mode, ParseError};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Formatter};
use std::sync::Arc;
pub use generator::Generator;
pub use indexer::Indexer;
pub use locator::Locator;
pub use stylist::{Quote, Stylist};
pub use crate::source_code::line_index::{LineIndex, OneIndexed};
mod generator;
mod indexer;
mod line_index;
mod locator;
mod stylist;
/// Run round-trip source code generation on a given Python code.
pub fn round_trip(code: &str, source_path: &str) -> Result<String, ParseError> {
let locator = Locator::new(code);

View file

@ -9,7 +9,6 @@ use rustpython_parser::lexer::LexResult;
use rustpython_parser::Tok;
use crate::newlines::{find_newline, LineEnding};
use crate::source_code::Locator;
use crate::str::leading_quote;
@ -164,10 +163,10 @@ impl Deref for Indentation {
#[cfg(test)]
mod tests {
use crate::newlines::{find_newline, LineEnding};
use rustpython_parser::lexer::lex;
use rustpython_parser::Mode;
use crate::newlines::{find_newline, LineEnding};
use crate::source_code::stylist::{Indentation, Quote};
use crate::source_code::{Locator, Stylist};