mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 19:39:58 +00:00
Introduce a new CST element for slice segments (#3195)
This commit is contained in:
parent
eb15371453
commit
6eaacf96be
8 changed files with 425 additions and 143 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::core::visitor;
|
||||
use crate::core::visitor::Visitor;
|
||||
use crate::cst::{Expr, Stmt};
|
||||
use crate::cst::{Alias, Excepthandler, Expr, SliceIndex, Stmt};
|
||||
use crate::trivia::{decorate_trivia, TriviaIndex, TriviaToken};
|
||||
|
||||
struct AttachmentVisitor {
|
||||
|
@ -23,6 +23,30 @@ impl<'a> Visitor<'a> for AttachmentVisitor {
|
|||
}
|
||||
visitor::walk_expr(self, expr);
|
||||
}
|
||||
|
||||
fn visit_alias(&mut self, alias: &'a mut Alias) {
|
||||
let trivia = self.index.alias.remove(&alias.id());
|
||||
if let Some(comments) = trivia {
|
||||
alias.trivia.extend(comments);
|
||||
}
|
||||
visitor::walk_alias(self, alias);
|
||||
}
|
||||
|
||||
fn visit_excepthandler(&mut self, excepthandler: &'a mut Excepthandler) {
|
||||
let trivia = self.index.excepthandler.remove(&excepthandler.id());
|
||||
if let Some(comments) = trivia {
|
||||
excepthandler.trivia.extend(comments);
|
||||
}
|
||||
visitor::walk_excepthandler(self, excepthandler);
|
||||
}
|
||||
|
||||
fn visit_slice_index(&mut self, slice_index: &'a mut SliceIndex) {
|
||||
let trivia = self.index.slice_index.remove(&slice_index.id());
|
||||
if let Some(comments) = trivia {
|
||||
slice_index.trivia.extend(comments);
|
||||
}
|
||||
visitor::walk_slice_index(self, slice_index);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn attach(python_cst: &mut [Stmt], trivia: Vec<TriviaToken>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue