mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Fix a few clippy lints
This commit is contained in:
parent
dd331f007c
commit
b73b4f33bc
@ -44,7 +44,7 @@ pub fn func(item: syn::Item) -> Result<TokenStream> {
|
|||||||
let vis = &item.vis;
|
let vis = &item.vis;
|
||||||
let ident = &item.sig.ident;
|
let ident = &item.sig.ident;
|
||||||
let s = ident.to_string();
|
let s = ident.to_string();
|
||||||
let mut chars = s.trim_end_matches("_").chars();
|
let mut chars = s.trim_end_matches('_').chars();
|
||||||
let ty = quote::format_ident!(
|
let ty = quote::format_ident!(
|
||||||
"{}{}Func",
|
"{}{}Func",
|
||||||
chars.next().unwrap().to_ascii_uppercase(),
|
chars.next().unwrap().to_ascii_uppercase(),
|
||||||
@ -98,8 +98,8 @@ pub fn section(docs: &mut String, title: &str, level: usize) -> Option<String> {
|
|||||||
let rest = &docs[start..];
|
let rest = &docs[start..];
|
||||||
let len = rest[1..]
|
let len = rest[1..]
|
||||||
.find("\n# ")
|
.find("\n# ")
|
||||||
.or(rest[1..].find("\n## "))
|
.or_else(|| rest[1..].find("\n## "))
|
||||||
.or(rest[1..].find("\n### "))
|
.or_else(|| rest[1..].find("\n### "))
|
||||||
.map(|x| 1 + x)
|
.map(|x| 1 + x)
|
||||||
.unwrap_or(rest.len());
|
.unwrap_or(rest.len());
|
||||||
let end = start + len;
|
let end = start + len;
|
||||||
|
@ -220,7 +220,7 @@ fn create(node: &Node) -> Result<TokenStream> {
|
|||||||
let scope = quote::format_ident!("__{}_keys", node.self_name);
|
let scope = quote::format_ident!("__{}_keys", node.self_name);
|
||||||
|
|
||||||
for property in node.properties.iter() {
|
for property in node.properties.iter() {
|
||||||
let (key, module) = create_property_module(node, &property);
|
let (key, module) = create_property_module(node, property);
|
||||||
modules.push(module);
|
modules.push(module);
|
||||||
|
|
||||||
let name = &property.name;
|
let name = &property.name;
|
||||||
|
@ -20,7 +20,7 @@ pub fn write_images(ctx: &mut PdfContext) {
|
|||||||
match image.decode().unwrap().as_ref() {
|
match image.decode().unwrap().as_ref() {
|
||||||
DecodedImage::Raster(dynamic, format) => {
|
DecodedImage::Raster(dynamic, format) => {
|
||||||
// TODO: Error if image could not be encoded.
|
// TODO: Error if image could not be encoded.
|
||||||
let (data, filter, has_color) = encode_image(*format, &dynamic).unwrap();
|
let (data, filter, has_color) = encode_image(*format, dynamic).unwrap();
|
||||||
let mut image = ctx.writer.image_xobject(image_ref, &data);
|
let mut image = ctx.writer.image_xobject(image_ref, &data);
|
||||||
image.filter(filter);
|
image.filter(filter);
|
||||||
image.width(width as i32);
|
image.width(width as i32);
|
||||||
@ -37,7 +37,7 @@ pub fn write_images(ctx: &mut PdfContext) {
|
|||||||
// Add a second gray-scale image containing the alpha values if
|
// Add a second gray-scale image containing the alpha values if
|
||||||
// this image has an alpha channel.
|
// this image has an alpha channel.
|
||||||
if dynamic.color().has_alpha() {
|
if dynamic.color().has_alpha() {
|
||||||
let (alpha_data, alpha_filter) = encode_alpha(&dynamic);
|
let (alpha_data, alpha_filter) = encode_alpha(dynamic);
|
||||||
let mask_ref = ctx.alloc.bump();
|
let mask_ref = ctx.alloc.bump();
|
||||||
image.s_mask(mask_ref);
|
image.s_mask(mask_ref);
|
||||||
image.finish();
|
image.finish();
|
||||||
@ -52,7 +52,7 @@ pub fn write_images(ctx: &mut PdfContext) {
|
|||||||
}
|
}
|
||||||
DecodedImage::Svg(svg) => {
|
DecodedImage::Svg(svg) => {
|
||||||
let next_ref = svg2pdf::convert_tree_into(
|
let next_ref = svg2pdf::convert_tree_into(
|
||||||
&svg,
|
svg,
|
||||||
svg2pdf::Options::default(),
|
svg2pdf::Options::default(),
|
||||||
&mut ctx.writer,
|
&mut ctx.writer,
|
||||||
image_ref,
|
image_ref,
|
||||||
|
@ -289,7 +289,7 @@ fn write_frame(ctx: &mut PageContext, frame: &Frame) {
|
|||||||
Element::Image(image, size) => write_image(ctx, x, y, image, *size),
|
Element::Image(image, size) => write_image(ctx, x, y, image, *size),
|
||||||
Element::Meta(meta, size) => match meta {
|
Element::Meta(meta, size) => match meta {
|
||||||
Meta::Link(dest) => write_link(ctx, pos, dest, *size),
|
Meta::Link(dest) => write_link(ctx, pos, dest, *size),
|
||||||
_ => {}
|
Meta::Node(_, _) => {}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ use tiny_skia as sk;
|
|||||||
use ttf_parser::{GlyphId, OutlineBuilder};
|
use ttf_parser::{GlyphId, OutlineBuilder};
|
||||||
use usvg::FitTo;
|
use usvg::FitTo;
|
||||||
|
|
||||||
use crate::doc::{Element, Frame, Group, Text};
|
use crate::doc::{Element, Frame, Group, Meta, Text};
|
||||||
use crate::geom::{
|
use crate::geom::{
|
||||||
self, Abs, Geometry, Paint, PathElement, Shape, Size, Stroke, Transform,
|
self, Abs, Geometry, Paint, PathElement, Shape, Size, Stroke, Transform,
|
||||||
};
|
};
|
||||||
@ -58,7 +58,10 @@ fn render_frame(
|
|||||||
Element::Image(image, size) => {
|
Element::Image(image, size) => {
|
||||||
render_image(canvas, ts, mask, image, *size);
|
render_image(canvas, ts, mask, image, *size);
|
||||||
}
|
}
|
||||||
Element::Meta(_, _) => {}
|
Element::Meta(meta, _) => match meta {
|
||||||
|
Meta::Link(_) => {}
|
||||||
|
Meta::Node(_, _) => {}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -400,7 +403,7 @@ fn scaled_texture(image: &Image, w: u32, h: u32) -> Option<Arc<sk::Pixmap>> {
|
|||||||
}
|
}
|
||||||
DecodedImage::Svg(tree) => {
|
DecodedImage::Svg(tree) => {
|
||||||
resvg::render(
|
resvg::render(
|
||||||
&tree,
|
tree,
|
||||||
FitTo::Size(w, h),
|
FitTo::Size(w, h),
|
||||||
sk::Transform::identity(),
|
sk::Transform::identity(),
|
||||||
pixmap.as_mut(),
|
pixmap.as_mut(),
|
||||||
|
@ -26,7 +26,7 @@ fn function_tooltip(world: &dyn World, leaf: &LinkedNode) -> Option<String> {
|
|||||||
if let Some(Value::Func(func)) = world.library().scope.get(&ident);
|
if let Some(Value::Func(func)) = world.library().scope.get(&ident);
|
||||||
if let Some(info) = func.info();
|
if let Some(info) = func.info();
|
||||||
then {
|
then {
|
||||||
return Some(plain_docs_sentence(&info.docs));
|
return Some(plain_docs_sentence(info.docs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,8 +140,8 @@ fn determine_size(data: &Buffer, format: ImageFormat) -> StrResult<(u32, u32)> {
|
|||||||
}
|
}
|
||||||
ImageFormat::Vector(VectorFormat::Svg) => {
|
ImageFormat::Vector(VectorFormat::Svg) => {
|
||||||
let opts = usvg::Options::default();
|
let opts = usvg::Options::default();
|
||||||
let tree = usvg::Tree::from_data(&data, &opts.to_ref())
|
let tree =
|
||||||
.map_err(format_usvg_error)?;
|
usvg::Tree::from_data(data, &opts.to_ref()).map_err(format_usvg_error)?;
|
||||||
|
|
||||||
let size = tree.svg_node().size;
|
let size = tree.svg_node().size;
|
||||||
let width = size.width().ceil() as u32;
|
let width = size.width().ceil() as u32;
|
||||||
|
@ -183,7 +183,7 @@ impl Array {
|
|||||||
|
|
||||||
/// Transform each item in the array with a function.
|
/// Transform each item in the array with a function.
|
||||||
pub fn map(&self, vm: &Vm, func: Func) -> SourceResult<Self> {
|
pub fn map(&self, vm: &Vm, func: Func) -> SourceResult<Self> {
|
||||||
if func.argc().map_or(false, |count| count < 1 || count > 2) {
|
if func.argc().map_or(false, |count| !(1..=2).contains(&count)) {
|
||||||
bail!(func.span(), "function must have one or two parameters");
|
bail!(func.span(), "function must have one or two parameters");
|
||||||
}
|
}
|
||||||
let enumerate = func.argc() == Some(2);
|
let enumerate = func.argc() == Some(2);
|
||||||
|
@ -567,7 +567,7 @@ impl Eval for ast::Ident {
|
|||||||
impl ast::Ident {
|
impl ast::Ident {
|
||||||
fn eval_in_math(&self, vm: &mut Vm) -> SourceResult<Content> {
|
fn eval_in_math(&self, vm: &mut Vm) -> SourceResult<Content> {
|
||||||
if self.as_untyped().len() == self.len()
|
if self.as_untyped().len() == self.len()
|
||||||
&& matches!(vm.scopes.get(&self), Ok(Value::Func(_)) | Err(_))
|
&& matches!(vm.scopes.get(self), Ok(Value::Func(_)) | Err(_))
|
||||||
{
|
{
|
||||||
Ok((vm.items.symbol)(EcoString::from(self.get()) + ":op".into()))
|
Ok((vm.items.symbol)(EcoString::from(self.get()) + ":op".into()))
|
||||||
} else {
|
} else {
|
||||||
@ -635,7 +635,7 @@ impl Eval for ast::Str {
|
|||||||
type Output = Value;
|
type Output = Value;
|
||||||
|
|
||||||
fn eval(&self, _: &mut Vm) -> SourceResult<Self::Output> {
|
fn eval(&self, _: &mut Vm) -> SourceResult<Self::Output> {
|
||||||
Ok(Value::Str(self.get().clone().into()))
|
Ok(Value::Str(self.get().into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1245,7 +1245,7 @@ impl Eval for ast::ModuleImport {
|
|||||||
errors.push(error!(ident.span(), "unresolved import"));
|
errors.push(error!(ident.span(), "unresolved import"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if errors.len() > 0 {
|
if !errors.is_empty() {
|
||||||
return Err(Box::new(errors));
|
return Err(Box::new(errors));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ pub fn realize(
|
|||||||
for recipe in styles.recipes() {
|
for recipe in styles.recipes() {
|
||||||
let guard = Guard::Nth(n);
|
let guard = Guard::Nth(n);
|
||||||
if recipe.applicable(target) && !target.is_guarded(guard) {
|
if recipe.applicable(target) && !target.is_guarded(guard) {
|
||||||
if let Some(content) = try_apply(vt, &target, recipe, guard)? {
|
if let Some(content) = try_apply(vt, target, recipe, guard)? {
|
||||||
realized = Some(content);
|
realized = Some(content);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -92,13 +92,13 @@ fn try_apply(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Some(Selector::Regex(regex)) => {
|
Some(Selector::Regex(regex)) => {
|
||||||
let Some(text) = item!(text_str)(&target) else {
|
let Some(text) = item!(text_str)(target) else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
||||||
let make = |s| {
|
let make = |s| {
|
||||||
let mut content = item!(text)(s);
|
let mut content = item!(text)(s);
|
||||||
content.copy_modifiers(&target);
|
content.copy_modifiers(target);
|
||||||
content
|
content
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ pub trait Finalize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Guards content against being affected by the same show rule multiple times.
|
/// Guards content against being affected by the same show rule multiple times.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub enum Guard {
|
pub enum Guard {
|
||||||
/// The nth recipe from the top of the chain.
|
/// The nth recipe from the top of the chain.
|
||||||
Nth(usize),
|
Nth(usize),
|
||||||
|
@ -720,7 +720,7 @@ impl Ident {
|
|||||||
self.0.text().trim_start_matches('#')
|
self.0.text().trim_start_matches('#')
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Take out the container identifier.
|
/// Take out the contained identifier.
|
||||||
pub fn take(self) -> EcoString {
|
pub fn take(self) -> EcoString {
|
||||||
let text = self.0.into_text();
|
let text = self.0.into_text();
|
||||||
match text.strip_prefix('#') {
|
match text.strip_prefix('#') {
|
||||||
|
@ -861,14 +861,12 @@ mod tests {
|
|||||||
// Find "text".
|
// Find "text".
|
||||||
let node = LinkedNode::new(source.root()).leaf_at(7).unwrap();
|
let node = LinkedNode::new(source.root()).leaf_at(7).unwrap();
|
||||||
assert_eq!(node.offset(), 5);
|
assert_eq!(node.offset(), 5);
|
||||||
assert_eq!(node.len(), 4);
|
assert_eq!(node.text(), "text");
|
||||||
assert_eq!(node.kind(), SyntaxKind::Ident);
|
|
||||||
|
|
||||||
// Go back to "#set". Skips the space.
|
// Go back to "#set". Skips the space.
|
||||||
let prev = node.prev_sibling().unwrap();
|
let prev = node.prev_sibling().unwrap();
|
||||||
assert_eq!(prev.offset(), 0);
|
assert_eq!(prev.offset(), 0);
|
||||||
assert_eq!(prev.len(), 4);
|
assert_eq!(prev.text(), "#set");
|
||||||
assert_eq!(prev.kind(), SyntaxKind::Set);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -876,15 +874,15 @@ mod tests {
|
|||||||
let source = Source::detached("#set fun(12pt, red)");
|
let source = Source::detached("#set fun(12pt, red)");
|
||||||
let leaf = LinkedNode::new(source.root()).leaf_at(6).unwrap();
|
let leaf = LinkedNode::new(source.root()).leaf_at(6).unwrap();
|
||||||
let prev = leaf.prev_leaf().unwrap();
|
let prev = leaf.prev_leaf().unwrap();
|
||||||
assert_eq!(leaf.kind(), SyntaxKind::Ident);
|
assert_eq!(leaf.text(), "fun");
|
||||||
assert_eq!(prev.kind(), SyntaxKind::Set);
|
assert_eq!(prev.text(), "#set");
|
||||||
|
|
||||||
let source = Source::detached("#let x = 10");
|
let source = Source::detached("#let x = 10");
|
||||||
let leaf = LinkedNode::new(source.root()).leaf_at(9).unwrap();
|
let leaf = LinkedNode::new(source.root()).leaf_at(9).unwrap();
|
||||||
let prev = leaf.prev_leaf().unwrap();
|
let prev = leaf.prev_leaf().unwrap();
|
||||||
let next = leaf.next_leaf().unwrap();
|
let next = leaf.next_leaf().unwrap();
|
||||||
assert_eq!(prev.kind(), SyntaxKind::Eq);
|
assert_eq!(prev.text(), "=");
|
||||||
assert_eq!(leaf.kind(), SyntaxKind::Space);
|
assert_eq!(leaf.text(), " ");
|
||||||
assert_eq!(next.kind(), SyntaxKind::Int);
|
assert_eq!(next.text(), "10");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ pub(super) fn reparse_markup(
|
|||||||
at_start: &mut bool,
|
at_start: &mut bool,
|
||||||
mut stop: impl FnMut(SyntaxKind) -> bool,
|
mut stop: impl FnMut(SyntaxKind) -> bool,
|
||||||
) -> Option<Vec<SyntaxNode>> {
|
) -> Option<Vec<SyntaxNode>> {
|
||||||
let mut p = Parser::new(&text, range.start, LexMode::Markup);
|
let mut p = Parser::new(text, range.start, LexMode::Markup);
|
||||||
while !p.eof() && !stop(p.current) && p.current_start() < range.end {
|
while !p.eof() && !stop(p.current) && p.current_start() < range.end {
|
||||||
if p.newline() {
|
if p.newline() {
|
||||||
*at_start = true;
|
*at_start = true;
|
||||||
@ -512,7 +512,7 @@ fn block(p: &mut Parser) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn reparse_block(text: &str, range: Range<usize>) -> Option<SyntaxNode> {
|
pub(super) fn reparse_block(text: &str, range: Range<usize>) -> Option<SyntaxNode> {
|
||||||
let mut p = Parser::new(&text, range.start, LexMode::Code);
|
let mut p = Parser::new(text, range.start, LexMode::Code);
|
||||||
assert!(p.at(SyntaxKind::LeftBracket) || p.at(SyntaxKind::LeftBrace));
|
assert!(p.at(SyntaxKind::LeftBracket) || p.at(SyntaxKind::LeftBrace));
|
||||||
block(&mut p);
|
block(&mut p);
|
||||||
(p.balanced && p.prev_end() == range.end)
|
(p.balanced && p.prev_end() == range.end)
|
||||||
@ -630,7 +630,7 @@ fn item(p: &mut Parser, keyed: bool) -> SyntaxKind {
|
|||||||
Some(SyntaxKind::Ident) => SyntaxKind::Named,
|
Some(SyntaxKind::Ident) => SyntaxKind::Named,
|
||||||
Some(SyntaxKind::Str) if keyed => SyntaxKind::Keyed,
|
Some(SyntaxKind::Str) if keyed => SyntaxKind::Keyed,
|
||||||
_ => {
|
_ => {
|
||||||
for child in p.post_process(m).next() {
|
for child in p.post_process(m) {
|
||||||
if child.kind() == SyntaxKind::Colon {
|
if child.kind() == SyntaxKind::Colon {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ fn try_reparse(
|
|||||||
// contained in things like headings or lists because too much can go wrong
|
// contained in things like headings or lists because too much can go wrong
|
||||||
// with indent and line breaks.
|
// with indent and line breaks.
|
||||||
if node.kind() == SyntaxKind::Markup
|
if node.kind() == SyntaxKind::Markup
|
||||||
&& (parent_kind == None || parent_kind == Some(SyntaxKind::ContentBlock))
|
&& (parent_kind.is_none() || parent_kind == Some(SyntaxKind::ContentBlock))
|
||||||
&& !overlap.is_empty()
|
&& !overlap.is_empty()
|
||||||
{
|
{
|
||||||
// Add one node of slack in both directions.
|
// Add one node of slack in both directions.
|
||||||
|
@ -291,7 +291,7 @@ struct Line {
|
|||||||
/// Create a line vector.
|
/// Create a line vector.
|
||||||
fn lines(text: &str) -> Vec<Line> {
|
fn lines(text: &str) -> Vec<Line> {
|
||||||
std::iter::once(Line { byte_idx: 0, utf16_idx: 0 })
|
std::iter::once(Line { byte_idx: 0, utf16_idx: 0 })
|
||||||
.chain(lines_from(0, 0, &text))
|
.chain(lines_from(0, 0, text))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "keyword.other.typst",
|
"name": "keyword.other.typst",
|
||||||
"match": "(#)(as|in|from)\\b",
|
"match": "(#)(as|in)\\b",
|
||||||
"captures": { "1": { "name": "punctuation.definition.keyword.typst" } }
|
"captures": { "1": { "name": "punctuation.definition.keyword.typst" } }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -257,7 +257,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "keyword.other.typst",
|
"name": "keyword.other.typst",
|
||||||
"match": "\\b(let|as|in|from|set|show)\\b"
|
"match": "\\b(let|as|in|set|show)\\b"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "keyword.control.conditional.typst",
|
"name": "keyword.control.conditional.typst",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user