Skip to content

Commit

Permalink
playground: Add AST/Tokens/Formatter panels (astral-sh#5859)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser authored Jul 19, 2023
1 parent 9ed7cee commit 46a17d1
Show file tree
Hide file tree
Showing 19 changed files with 1,345 additions and 782 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion crates/ruff_formatter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod source_code;
use crate::formatter::Formatter;
use crate::group_id::UniqueGroupIdBuilder;
use crate::prelude::TagKind;
use std::fmt::Debug;
use std::fmt::{Debug, Display};
use std::marker::PhantomData;

use crate::format_element::document::Document;
Expand Down Expand Up @@ -331,6 +331,16 @@ where
Ok(printed)
}
}

impl<Context> Display for Formatted<Context>
where
Context: FormatContext,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.document.display(self.context.source_code()), f)
}
}

pub type PrintResult<T> = Result<T, PrintError>;

#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down
3 changes: 2 additions & 1 deletion crates/ruff_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ default = ["console_error_panic_hook"]
ruff = { path = "../ruff" }
ruff_diagnostics = { path = "../ruff_diagnostics" }
ruff_python_ast = { path = "../ruff_python_ast" }
ruff_python_formatter = { path = "../ruff_python_formatter" }
ruff_rustpython = { path = "../ruff_rustpython" }

console_error_panic_hook = { version = "0.1.7", optional = true }
Expand All @@ -30,7 +31,7 @@ rustpython-parser = { workspace = true }
serde = { workspace = true }
serde-wasm-bindgen = { version = "0.5.0" }
wasm-bindgen = { version = "0.2.84" }
js-sys = { version = "0.3.61" }

[dev-dependencies]
js-sys = { version = "0.3.61" }
wasm-bindgen-test = { version = "0.3.34" }
Loading

0 comments on commit 46a17d1

Please sign in to comment.