## Summary This PR renames the `MagicCommand` token to `IpyEscapeCommand` token and `MagicKind` to `IpyEscapeKind` type to better reflect the purpose of the token and type. Similarly, it renames the AST nodes from `LineMagic` to `IpyEscapeCommand` prefixed with `Stmt`/`Expr` wherever necessary. It also makes renames from using `jupyter_magic` to `ipython_escape_commands` in various function names. The mode value is still `Mode::Jupyter` because the escape commands are part of the IPython syntax but the lexing/parsing is done for a Jupyter notebook. ### Motivation behind the rename: * IPython codebase defines it as "EscapeCommand" / "Escape Sequences": * Escape Sequences:292e3a2345/IPython/core/inputtransformer2.py (L329-L333)* Escape command:292e3a2345/IPython/core/inputtransformer2.py (L410-L411)* The word "magic" is used mainly for the actual magic commands i.e., the ones starting with `%`/`%%` (https://ipython.readthedocs.io/en/stable/interactive/reference.html#magic-command-system). So, this avoids any confusion between the Magic token (`%`, `%%`) and the escape command itself. ## Test Plan * `cargo test` to make sure all renames are done correctly. * `grep` for `jupyter_escape`/`magic` to make sure all renames are done correctly.
84 lines
2.8 KiB
Rust
84 lines
2.8 KiB
Rust
use crate::prelude::*;
|
|
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
|
|
use ruff_python_ast::Stmt;
|
|
|
|
pub(crate) mod stmt_ann_assign;
|
|
pub(crate) mod stmt_assert;
|
|
pub(crate) mod stmt_assign;
|
|
pub(crate) mod stmt_aug_assign;
|
|
pub(crate) mod stmt_break;
|
|
pub(crate) mod stmt_class_def;
|
|
pub(crate) mod stmt_continue;
|
|
pub(crate) mod stmt_delete;
|
|
pub(crate) mod stmt_expr;
|
|
pub(crate) mod stmt_for;
|
|
pub(crate) mod stmt_function_def;
|
|
pub(crate) mod stmt_global;
|
|
pub(crate) mod stmt_if;
|
|
pub(crate) mod stmt_import;
|
|
pub(crate) mod stmt_import_from;
|
|
pub(crate) mod stmt_ipy_escape_command;
|
|
pub(crate) mod stmt_match;
|
|
pub(crate) mod stmt_nonlocal;
|
|
pub(crate) mod stmt_pass;
|
|
pub(crate) mod stmt_raise;
|
|
pub(crate) mod stmt_return;
|
|
pub(crate) mod stmt_try;
|
|
pub(crate) mod stmt_try_star;
|
|
pub(crate) mod stmt_type_alias;
|
|
pub(crate) mod stmt_while;
|
|
pub(crate) mod stmt_with;
|
|
pub(crate) mod suite;
|
|
|
|
#[derive(Default)]
|
|
pub struct FormatStmt;
|
|
|
|
impl FormatRule<Stmt, PyFormatContext<'_>> for FormatStmt {
|
|
fn fmt(&self, item: &Stmt, f: &mut PyFormatter) -> FormatResult<()> {
|
|
match item {
|
|
Stmt::FunctionDef(x) => x.format().fmt(f),
|
|
Stmt::ClassDef(x) => x.format().fmt(f),
|
|
Stmt::Return(x) => x.format().fmt(f),
|
|
Stmt::Delete(x) => x.format().fmt(f),
|
|
Stmt::Assign(x) => x.format().fmt(f),
|
|
Stmt::AugAssign(x) => x.format().fmt(f),
|
|
Stmt::AnnAssign(x) => x.format().fmt(f),
|
|
Stmt::For(x) => x.format().fmt(f),
|
|
Stmt::While(x) => x.format().fmt(f),
|
|
Stmt::If(x) => x.format().fmt(f),
|
|
Stmt::With(x) => x.format().fmt(f),
|
|
Stmt::Match(x) => x.format().fmt(f),
|
|
Stmt::Raise(x) => x.format().fmt(f),
|
|
Stmt::Try(x) => x.format().fmt(f),
|
|
Stmt::TryStar(x) => x.format().fmt(f),
|
|
Stmt::Assert(x) => x.format().fmt(f),
|
|
Stmt::Import(x) => x.format().fmt(f),
|
|
Stmt::ImportFrom(x) => x.format().fmt(f),
|
|
Stmt::Global(x) => x.format().fmt(f),
|
|
Stmt::Nonlocal(x) => x.format().fmt(f),
|
|
Stmt::Expr(x) => x.format().fmt(f),
|
|
Stmt::Pass(x) => x.format().fmt(f),
|
|
Stmt::Break(x) => x.format().fmt(f),
|
|
Stmt::Continue(x) => x.format().fmt(f),
|
|
Stmt::TypeAlias(x) => x.format().fmt(f),
|
|
Stmt::IpyEscapeCommand(_) => todo!(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<'ast> AsFormat<PyFormatContext<'ast>> for Stmt {
|
|
type Format<'a> = FormatRefWithRule<'a, Stmt, FormatStmt, PyFormatContext<'ast>>;
|
|
|
|
fn format(&self) -> Self::Format<'_> {
|
|
FormatRefWithRule::new(self, FormatStmt)
|
|
}
|
|
}
|
|
|
|
impl<'ast> IntoFormat<PyFormatContext<'ast>> for Stmt {
|
|
type Format = FormatOwnedWithRule<Stmt, FormatStmt, PyFormatContext<'ast>>;
|
|
|
|
fn into_format(self) -> Self::Format {
|
|
FormatOwnedWithRule::new(self, FormatStmt)
|
|
}
|
|
}
|