From cbfac6cd457d9a3c828d9f0e166444baac9dbb77 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 15 Jul 2022 15:19:04 +0200 Subject: [PATCH] Fix highlighting bugs --- src/syntax/ast.rs | 2 +- src/syntax/highlight.rs | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index b90ecdfff..67f9e0385 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -1067,7 +1067,7 @@ impl ShowExpr { } node! { - /// A wrap expression: wrap body in columns(2, body)`. + /// A wrap expression: `wrap body in columns(2, body)`. WrapExpr } diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs index f6256d2a2..b52234d4e 100644 --- a/src/syntax/highlight.rs +++ b/src/syntax/highlight.rs @@ -119,11 +119,11 @@ pub fn highlight_pre(text: &str, mode: TokenMode, theme: &Theme) -> String { } if style.font_style.contains(FontStyle::BOLD) { - buf.push_str("font-weight:bold"); + buf.push_str("font-weight:bold;"); } if style.font_style.contains(FontStyle::ITALIC) { - buf.push_str("font-style:italic"); + buf.push_str("font-style:italic;"); } if style.font_style.contains(FontStyle::UNDERLINE) { @@ -209,6 +209,7 @@ impl Category { NodeKind::Comma => Some(Category::Punctuation), NodeKind::Semicolon => Some(Category::Punctuation), NodeKind::Colon => Some(Category::Punctuation), + NodeKind::Dot => Some(Category::Punctuation), NodeKind::LineComment => Some(Category::Comment), NodeKind::BlockComment => Some(Category::Comment), NodeKind::Strong => Some(Category::Strong), @@ -253,7 +254,6 @@ impl Category { _ => Some(Category::Operator), }, NodeKind::Slash => Some(Category::Operator), - NodeKind::Dot => Some(Category::Operator), NodeKind::PlusEq => Some(Category::Operator), NodeKind::HyphEq => Some(Category::Operator), NodeKind::StarEq => Some(Category::Operator), @@ -281,10 +281,11 @@ impl Category { NodeKind::ShowExpr if parent .children() - .filter(|c| matches!(c.kind(), NodeKind::Ident(_))) - .map(SyntaxNode::span) - .nth(1) - .map_or(false, |span| span == child.span()) => + .rev() + .skip_while(|child| child.kind() != &NodeKind::As) + .take_while(|child| child.kind() != &NodeKind::Colon) + .find(|c| matches!(c.kind(), NodeKind::Ident(_))) + .map_or(false, |ident| std::ptr::eq(ident, child)) => { Some(Category::Function) }