mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:09:22 +00:00

## Summary This PR removes the cyclic dev dependency some of the crates had with the parser crate. The cyclic dependencies are: * `ruff_python_ast` has a **dev dependency** on `ruff_python_parser` and `ruff_python_parser` directly depends on `ruff_python_ast` * `ruff_python_trivia` has a **dev dependency** on `ruff_python_parser` and `ruff_python_parser` has an indirect dependency on `ruff_python_trivia` (`ruff_python_parser` - `ruff_python_ast` - `ruff_python_trivia`) Specifically, this PR does the following: * Introduce two new crates * `ruff_python_ast_integration_tests` and move the tests from the `ruff_python_ast` crate which uses the parser in this crate * `ruff_python_trivia_integration_tests` and move the tests from the `ruff_python_trivia` crate which uses the parser in this crate ### Motivation The main motivation for this PR is to help development. Before this PR, `rust-analyzer` wouldn't provide any intellisense in the `ruff_python_parser` crate regarding the symbols in `ruff_python_ast` crate. ``` [ERROR][2024-05-03 13:47:06] .../vim/lsp/rpc.lua:770 "rpc" "/Users/dhruv/.cargo/bin/rust-analyzer" "stderr" "[ERROR project_model::workspace] cyclic deps: ruff_python_parser(Idx::<CrateData>(50)) -> ruff_python_ast(Idx::<CrateData>(37)), alternative path: ruff_python_ast(Idx::<CrateData>(37)) -> ruff_python_parser(Idx::<CrateData>(50))\n" ``` ## Test Plan Check the logs of `rust-analyzer` to not see any signs of cyclic dependency.
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
use ruff_python_parser::{parse_suite, ParseError};
|
|
use ruff_python_trivia::has_trailing_content;
|
|
use ruff_source_file::Locator;
|
|
use ruff_text_size::Ranged;
|
|
|
|
#[test]
|
|
fn trailing_content() -> Result<(), ParseError> {
|
|
let contents = "x = 1";
|
|
let program = parse_suite(contents)?;
|
|
let stmt = program.first().unwrap();
|
|
let locator = Locator::new(contents);
|
|
assert!(!has_trailing_content(stmt.end(), &locator));
|
|
|
|
let contents = "x = 1; y = 2";
|
|
let program = parse_suite(contents)?;
|
|
let stmt = program.first().unwrap();
|
|
let locator = Locator::new(contents);
|
|
assert!(has_trailing_content(stmt.end(), &locator));
|
|
|
|
let contents = "x = 1 ";
|
|
let program = parse_suite(contents)?;
|
|
let stmt = program.first().unwrap();
|
|
let locator = Locator::new(contents);
|
|
assert!(!has_trailing_content(stmt.end(), &locator));
|
|
|
|
let contents = "x = 1 # Comment";
|
|
let program = parse_suite(contents)?;
|
|
let stmt = program.first().unwrap();
|
|
let locator = Locator::new(contents);
|
|
assert!(!has_trailing_content(stmt.end(), &locator));
|
|
|
|
let contents = r"
|
|
x = 1
|
|
y = 2
|
|
"
|
|
.trim();
|
|
let program = parse_suite(contents)?;
|
|
let stmt = program.first().unwrap();
|
|
let locator = Locator::new(contents);
|
|
assert!(!has_trailing_content(stmt.end(), &locator));
|
|
|
|
Ok(())
|
|
}
|