Implement visitation of type aliases and parameters (#5927)

<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

Part of #5062 
Requires https://github.com/astral-sh/RustPython-Parser/pull/32

Adds visitation of type alias statements and type parameters in class
and function definitions.

Duplicates tests for `PreorderVisitor` into `Visitor` with new
snapshots. Testing required node implementations for the `TypeParam`
enum, which is a chunk of the diff and the reason we need `Ranged`
implementations in
https://github.com/astral-sh/RustPython-Parser/pull/32.

## Test Plan

<!-- How was it tested? -->

Adds unit tests with snapshots.
This commit is contained in:
Zanie Blue 2023-07-25 12:11:26 -05:00 committed by GitHub
parent 3000a47fe8
commit 389fe13c93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 837 additions and 8 deletions

View file

@ -3,7 +3,7 @@ use std::iter::Peekable;
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser::ast::{
Alias, Arg, ArgWithDefault, Arguments, Comprehension, Decorator, ElifElseClause, ExceptHandler,
Expr, Keyword, MatchCase, Mod, Pattern, Ranged, Stmt, WithItem,
Expr, Keyword, MatchCase, Mod, Pattern, Ranged, Stmt, TypeParam, WithItem,
};
use ruff_formatter::{SourceCode, SourceCodeSlice};
@ -291,6 +291,13 @@ impl<'ast> PreorderVisitor<'ast> for CommentsVisitor<'ast> {
}
self.finish_node(elif_else_clause);
}
fn visit_type_param(&mut self, type_param: &'ast TypeParam) {
if self.start_node(type_param).is_traverse() {
walk_type_param(self, type_param);
}
self.finish_node(type_param);
}
}
fn text_position(comment_range: TextRange, source_code: SourceCode) -> CommentLinePosition {