Skip to content

Commit 75d937d

Browse files
Kenocodex
andauthored
highlighting: Handle generic operators after refactor (#26)
Pass syntax nodes to JuliaSyntax precedence predicates so generic K"Operator" tokens retain their SyntaxHead flags while highlighting parse-error subtrees. Also include all multi-character lexer operators that no longer have dedicated kinds in the operator-name fallback used for identifier-like operator leaves. Fixes JuliaLang/julia#62103 Co-authored-by: Keno Fischer <Keno@users.noreply.github.com> Co-authored-by: OpenAI Codex <codex@openai.com>
1 parent 52924c1 commit 75d937d

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/JuliaSyntaxHighlighting.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ if isdefined(JuliaSyntax, :generic_operators_by_level)
6767
end
6868
end
6969
union!(OPERATOR_KINDS, ("==", "===", "!=", "!==", "<=", ">=",
70-
"<<", ">>", ">>>", "//", "|>", "<|", "=>"))
70+
"<<", ">>", ">>>", "//", "|>", "<|", "=>",
71+
"<--", "<-->"))
7172

7273
"""
7374
BUILTIN_FUNCTIONS
@@ -333,7 +334,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
333334
:julia_builtin
334335
elseif (nkind in (K"&&", K"||", K"<:") || regionstr == "===") && JuliaSyntax.is_trivia(node)
335336
:julia_builtin
336-
elseif JuliaSyntax.is_prec_comparison(nkind) && JuliaSyntax.is_trivia(node);
337+
elseif JuliaSyntax.is_prec_comparison(node) && JuliaSyntax.is_trivia(node);
337338
:julia_comparator
338339
elseif isplainoperator(node, pnode)
339340
:julia_operator

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ astr_sum1to8 = Base.AnnotatedString("sum(1:8)")
2727
@test highlight!(astr_sum1to8) == sum1to8_highlighted
2828
@test astr_sum1to8 == sum1to8_highlighted
2929

30+
# Ensure generic operators inside parse error nodes do not crash highlighting.
31+
@test any(a -> a.region == 5:5 && a.value == :julia_operator,
32+
Base.annotations(highlight("1 2 / 3")))
33+
@test any(a -> a.region == 5:6 && a.value == :julia_operator,
34+
Base.annotations(highlight("1 2 == 3")))
35+
@test any(a -> a.region == 3:5 && a.value == :julia_operator,
36+
Base.annotations(highlight("1 <-- 2")))
37+
@test any(a -> a.region == 3:6 && a.value == :julia_operator,
38+
Base.annotations(highlight("1 <--> 2")))
39+
3040
# Check for string indexing issues
3141
@test Base.annotations(highlight("")) |> first |> first == 1:3
3242

0 commit comments

Comments
 (0)