Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff authored Oct 17, 2022
1 parent c03664c commit 1f79102
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Base.showerror(io::IO, ex::JSONRPCError)
"UnknownErrorCode"
elseif ex.code == -32800
"RequestCancelled"
elseif ex.code == -32801
elseif ex.code == -32801
"ContentModified"
else
"Unkonwn"
Expand All @@ -41,7 +41,7 @@ function Base.showerror(io::IO, ex::JSONRPCError)
end
end

mutable struct JSONRPCEndpoint{IOIn <: IO,IOOut <: IO}
mutable struct JSONRPCEndpoint{IOIn<:IO,IOOut<:IO}
pipe_in::IOIn
pipe_out::IOOut

Expand All @@ -58,7 +58,7 @@ mutable struct JSONRPCEndpoint{IOIn <: IO,IOOut <: IO}
write_task::Union{Nothing,Task}
end

JSONRPCEndpoint(pipe_in, pipe_out, err_handler = nothing) =
JSONRPCEndpoint(pipe_in, pipe_out, err_handler=nothing) =
JSONRPCEndpoint(pipe_in, pipe_out, Channel{Any}(Inf), Channel{Any}(Inf), Dict{String,Channel{Any}}(), err_handler, :idle, nothing, nothing)

function write_transport_layer(stream, response)
Expand Down Expand Up @@ -204,7 +204,7 @@ function get_next_message(endpoint::JSONRPCEndpoint)
return msg
end

function Base.iterate(endpoint::JSONRPCEndpoint, state = nothing)
function Base.iterate(endpoint::JSONRPCEndpoint, state=nothing)
check_dead_endpoint!(endpoint)

try
Expand Down
10 changes: 5 additions & 5 deletions src/interface_def.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ end

function field_allows_missing(field::Expr)
field.head == :(::) && field.args[2] isa Expr &&
field.args[2].head == :curly && field.args[2].args[1] == :Union &&
any(i -> i == :Missing, field.args[2].args)
field.args[2].head == :curly && field.args[2].args[1] == :Union &&
any(i -> i == :Missing, field.args[2].args)
end

function field_type(field::Expr, typename::String)
Expand Down Expand Up @@ -55,9 +55,9 @@ macro dict_readable(arg)
$((arg))

$(count_real_fields > 0 ? :(
function $tname(; $((get_kwsignature_for_field(field) for field in arg.args[3].args if !(field isa LineNumberNode))...))
$tname($((field.args[1] for field in arg.args[3].args if !(field isa LineNumberNode))...))
end
function $tname(; $((get_kwsignature_for_field(field) for field in arg.args[3].args if !(field isa LineNumberNode))...))
$tname($((field.args[1] for field in arg.args[3].args if !(field isa LineNumberNode))...))
end
) : nothing)

function $tname(dict::Dict)
Expand Down
6 changes: 3 additions & 3 deletions src/typed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end
# so that we get an error in the typecast at the end of `send`
# if that is not the case.
typed_res(res, TR::Type{Nothing}) = res
typed_res(res, TR::Type{<:T}) where {T <: AbstractArray{Any}} = T(res)
typed_res(res, TR::Type{<:T}) where {T<:AbstractArray{Any}} = T(res)
typed_res(res, TR::Type{<:AbstractArray{T}}) where T = T.(res)
typed_res(res, TR::Type) = TR(res)

Expand Down Expand Up @@ -62,7 +62,7 @@ function dispatch_msg(x::JSONRPCEndpoint, dispatcher::MsgDispatcher, msg)
handler = get(dispatcher._handlers, method_name, nothing)
if handler !== nothing
param_type = get_param_type(handler.message_type)
params = param_type === Nothing ? nothing : param_type <: NamedTuple ? convert(param_type,(;(Symbol(i[1])=>i[2] for i in msg["params"])...)) : param_type(msg["params"])
params = param_type === Nothing ? nothing : param_type <: NamedTuple ? convert(param_type, (; (Symbol(i[1]) => i[2] for i in msg["params"])...)) : param_type(msg["params"])

res = handler.func(x, params)

Expand All @@ -73,7 +73,7 @@ function dispatch_msg(x::JSONRPCEndpoint, dispatcher::MsgDispatcher, msg)
send_success_response(x, msg, res)
else
error_msg = "The handler for the '$method_name' request returned a value of type $(typeof(res)), which is not a valid return type according to the request definition."
send_error_response(x, msg, -32603, error_msg, nothing)
send_error_response(x, msg, -32603, error_msg, nothing)
error(error_msg)
end
end
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end
fieldB::Vector{Int}
end

Base.:(==)(a::Foo2,b::Foo2) = a.fieldA == b.fieldA && a.fieldB == b.fieldB
Base.:(==)(a::Foo2, b::Foo2) = a.fieldA == b.fieldA && a.fieldB == b.fieldB

@testset "JSONRPC" begin
include("test_core.jl")
Expand All @@ -25,10 +25,10 @@ Base.:(==)(a::Foo2,b::Foo2) = a.fieldA == b.fieldA && a.fieldB == b.fieldB

@testset "check response type" begin
@test typed_res(nothing, Nothing) isa Nothing
@test typed_res([1,"2",3], Vector{Any}) isa Vector{Any}
@test typed_res([1,2,3], Vector{Int}) isa Vector{Int}
@test typed_res([1,2,3], Vector{Float64}) isa Vector{Float64}
@test typed_res(['f','o','o'], String) isa String
@test typed_res([1, "2", 3], Vector{Any}) isa Vector{Any}
@test typed_res([1, 2, 3], Vector{Int}) isa Vector{Int}
@test typed_res([1, 2, 3], Vector{Float64}) isa Vector{Float64}
@test typed_res(['f', 'o', 'o'], String) isa String
@test typed_res("foo", String) isa String
end
end
8 changes: 4 additions & 4 deletions test/test_interface_def.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
@test Foo(JSON.parse(JSON.json(a))) == a
@test Foo(JSON.parse(JSON.json(b))) == b

c = Foo2(fieldA=nothing, fieldB=[1,2])
c = Foo2(fieldA=nothing, fieldB=[1, 2])

@test c.fieldA === nothing
@test c.fieldB == [1,2]
@test c.fieldB == [1, 2]
@test Foo2(JSON.parse(JSON.json(c))) == c

d = Foo2(fieldA=3, fieldB=[1,2])
d = Foo2(fieldA=3, fieldB=[1, 2])
@test d.fieldA === 3
@test d.fieldB == [1,2]
@test d.fieldB == [1, 2]
@test Foo2(JSON.parse(JSON.json(d))) == d
end
2 changes: 1 addition & 1 deletion test/test_typed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
global conn = JSONRPC.JSONRPCEndpoint(sock, sock)
global msg_dispatcher = JSONRPC.MsgDispatcher()

msg_dispatcher[request2_type] = (conn, params)->34 # The request type requires a `String` return, so this tests whether we get an error.
msg_dispatcher[request2_type] = (conn, params) -> 34 # The request type requires a `String` return, so this tests whether we get an error.

run(conn)

Expand Down

0 comments on commit 1f79102

Please sign in to comment.