Skip to content

Commit

Permalink
fix more issues
Browse files Browse the repository at this point in the history
  • Loading branch information
domluna committed Oct 24, 2024
1 parent ff7bcb4 commit ca2e74d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/fst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ function is_unary(x::JuliaSyntax.GreenNode)
if JuliaSyntax.is_unary_op(x)
return true
end
if kind(x) === K"call" || (JuliaSyntax.is_operator(x) && haschildren(x))
if kind(x) in KSet"call dotcall" || (JuliaSyntax.is_operator(x) && haschildren(x))
nops, nargs = _callinfo(x)
return nops == 1 && nargs == 1
end
Expand All @@ -583,7 +583,7 @@ function is_binary(x)
end

function is_chain(x::JuliaSyntax.GreenNode)
if !(kind(x) === K"call")
if !(kind(x) in KSet"call dotcall")
return false
end
nops, nargs = _callinfo(x)
Expand Down Expand Up @@ -647,7 +647,7 @@ end

function is_function_like_lhs(node::JuliaSyntax.GreenNode)
k = kind(node)
if k == K"call"
if k in KSet"call dotcall"
return true
elseif k == K"where" || k == K"::"
return haschildren(node) && is_function_like_lhs(node[1])
Expand Down Expand Up @@ -709,7 +709,7 @@ function get_op(cst::JuliaSyntax.GreenNode)::Union{JuliaSyntax.GreenNode,Nothing
for c in children(cst)
if kind(cst) === K"dotcall" && kind(c) === K"."
continue
elseif JuliaSyntax.is_operator(c)
elseif JuliaSyntax.is_operator(c) && !haschildren(c)
return c
end
end
Expand Down
8 changes: 6 additions & 2 deletions src/styles/default/pretty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,8 @@ function p_binaryopcall(
if opkind === K":"
nospace = true
from_colon = true
elseif opkind in KSet"::"
nospace = true
elseif opkind in KSet"in ∈ isa ."
nospace = false
elseif ctx.from_typedef && opkind in KSet"<: >:"
Expand Down Expand Up @@ -1854,8 +1856,10 @@ function p_binaryopcall(
ns = is_dot ? 1 : nws

# Add whitespace before the operator, unless it's a dot in a dotted operator
if ns > 0
if i > 1 && !(kind(childs[i-1]) === K".") # Don't add space if previous was a dot
if ns > 0 && i > 1
if kind(childs[i-1]) !== K"." # Don't add space if previous was a dot
add_node!(t, Whitespace(ns), s)
elseif kind(childs[i-1]) === K"." && haschildren(childs[i-1]) # Don't add space if previous was a dot
add_node!(t, Whitespace(ns), s)
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/default_style.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@
@test fmt("a :b") == "a:b"
@test fmt("a +1 :b -1") == "(a+1):(b-1)"

@test fmt("a::b:: c") == "a::b :: c"
@test fmt("a :: b::c") == "a :: b::c"
@test fmt("a :: b :: c") == "a :: b :: c"
@test fmt("a::b:: c") == "a::b::c"
@test fmt("a :: b::c") == "a::b::c"
@test fmt("a :: b :: c") == "a::b::c"
# issue 74
@test fmt("0:1/3:2") == "0:(1/3):2"
@test fmt("2a") == "2a"
Expand Down
13 changes: 13 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1897,4 +1897,17 @@
@test f1 == str
end
end

@testset "880" begin
s1 = "constant_list[node_index.val:: UInt16]"
s2 = "constant_list[node_index.val::UInt16]"
@test s1 = fmt(s1, 4, 100, whitespace_ops_in_indices=true) == s2

s1 = "constant_list[node_index.val+ UInt16]"
s2 = "constant_list[node_index.val + UInt16]"
@test s1 = fmt(s1, 4, 100, whitespace_ops_in_indices=true) == s2

s = ".!purge"
@test s = fmt(s, 4, 100) == s
end
end
4 changes: 2 additions & 2 deletions test/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -997,8 +997,8 @@
end"""
str_ = """
struct Foo
a :: T
longfieldname :: B
a::T
longfieldname::B
end"""
@test fmt(str; align_struct_field = true) == str
@test fmt(str; align_struct_field = false) == str_
Expand Down

0 comments on commit ca2e74d

Please sign in to comment.