From 0840bf44e7d066cc3f210c6fa60895de7e09b88a Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Mon, 28 Oct 2024 00:00:34 +0100 Subject: [PATCH] Allow no space before comment after `(`, `[`, `{`, fixes #81. --- src/runestone.jl | 4 +++- test/runtests.jl | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/runestone.jl b/src/runestone.jl index c25088c..dcb57ea 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -3451,7 +3451,9 @@ function spaces_around_comments(ctx::Context, node::Node) push!(kids′, kid′) end accept_node!(ctx, kid′) - prev_kid_ends_with_ws = kind(kid′) in KSet"Whitespace NewlineWs" || + # Note: This allows (but doesn't require) no space after opening brackets, see + # https://github.com/fredrikekre/Runic.jl/issues/81 + prev_kid_ends_with_ws = kind(kid′) in KSet"Whitespace NewlineWs ( { [" || (ll = last_leaf(kid′); ll !== nothing && kind(ll) in KSet"Whitespace NewlineWs") end # Reset the stream and return diff --git a/test/runtests.jl b/test/runtests.jl index 0d44ce6..ce2c4c1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -87,6 +87,11 @@ end @test format_string("(a,$(sp)# comment\nb + b)") == "(\n a,$(csp)# comment\n b + b,\n)" @test format_string("if c$(sp)# a\n b\nend") == "if c$(csp)# a\n b\nend" + # Allow no space after opening brackets + # (https://github.com/fredrikekre/Runic.jl/issues/81) + for (o, c) in (("(", ")"), ("[", "]"), ("{", "}")) + @test format_string("$(o)$(sp)#= a =#$(sp)$(c)") == "$(o)$(sp)#= a =#$(c)" + end end let str = "a = 1 # a comment\nab = 2 # ab comment\n" @test format_string(str) == str