Skip to content

Commit 9fe56ea

Browse files
authored
Format files using DocumentFormat
1 parent 6f576eb commit 9fe56ea

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

src/core.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Base.showerror(io::IO, ex::JSONRPCError)
2525
"UnknownErrorCode"
2626
elseif ex.code == -32800
2727
"RequestCancelled"
28-
elseif ex.code == -32801
28+
elseif ex.code == -32801
2929
"ContentModified"
3030
else
3131
"Unkonwn"
@@ -41,7 +41,7 @@ function Base.showerror(io::IO, ex::JSONRPCError)
4141
end
4242
end
4343

44-
mutable struct JSONRPCEndpoint{IOIn <: IO,IOOut <: IO}
44+
mutable struct JSONRPCEndpoint{IOIn<:IO,IOOut<:IO}
4545
pipe_in::IOIn
4646
pipe_out::IOOut
4747

src/interface_def.jl

+6-7
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ end
2323

2424
function field_allows_missing(field::Expr)
2525
field.head == :(::) && field.args[2] isa Expr &&
26-
field.args[2].head == :curly && field.args[2].args[1] == :Union &&
27-
any(i -> i == :Missing, field.args[2].args)
26+
field.args[2].head == :curly && field.args[2].args[1] == :Union &&
27+
any(i -> i == :Missing, field.args[2].args)
2828
end
2929

3030
function field_type(field::Expr, typename::String)
@@ -55,13 +55,12 @@ macro dict_readable(arg)
5555
$((arg))
5656

5757
$(count_real_fields > 0 ? :(
58-
function $tname(; $((get_kwsignature_for_field(field) for field in arg.args[3].args if !(field isa LineNumberNode))...))
59-
$tname($((field.args[1] for field in arg.args[3].args if !(field isa LineNumberNode))...))
60-
end
58+
function $tname(; $((get_kwsignature_for_field(field) for field in arg.args[3].args if !(field isa LineNumberNode))...))
59+
$tname($((field.args[1] for field in arg.args[3].args if !(field isa LineNumberNode))...))
60+
end
6161
) : nothing)
6262

63-
function $tname(dict::Dict)
64-
end
63+
function $tname(dict::Dict) end
6564
end
6665

6766
fex = :($((tname))())

src/typed.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct RequestType{TPARAM,TR} <: AbstractMessageType
88
method::String
99
end
1010

11-
function NotificationType(method::AbstractString, ::Type{TPARAM}) where TPARAM
11+
function NotificationType(method::AbstractString, ::Type{TPARAM}) where {TPARAM}
1212
return NotificationType{TPARAM}(method)
1313
end
1414

@@ -29,11 +29,11 @@ end
2929
# so that we get an error in the typecast at the end of `send`
3030
# if that is not the case.
3131
typed_res(res, TR::Type{Nothing}) = res
32-
typed_res(res, TR::Type{<:T}) where {T <: AbstractArray{Any}} = T(res)
33-
typed_res(res, TR::Type{<:AbstractArray{T}}) where T = T.(res)
32+
typed_res(res, TR::Type{<:T}) where {T<:AbstractArray{Any}} = T(res)
33+
typed_res(res, TR::Type{<:AbstractArray{T}}) where {T} = T.(res)
3434
typed_res(res, TR::Type) = TR(res)
3535

36-
function send(x::JSONRPCEndpoint, notification::NotificationType{TPARAM}, params::TPARAM) where TPARAM
36+
function send(x::JSONRPCEndpoint, notification::NotificationType{TPARAM}, params::TPARAM) where {TPARAM}
3737
send_notification(x, notification.method, params)
3838
end
3939

@@ -62,7 +62,7 @@ function dispatch_msg(x::JSONRPCEndpoint, dispatcher::MsgDispatcher, msg)
6262
handler = get(dispatcher._handlers, method_name, nothing)
6363
if handler !== nothing
6464
param_type = get_param_type(handler.message_type)
65-
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"])
65+
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"])
6666

6767
res = handler.func(x, params)
6868

@@ -73,7 +73,7 @@ function dispatch_msg(x::JSONRPCEndpoint, dispatcher::MsgDispatcher, msg)
7373
send_success_response(x, msg, res)
7474
else
7575
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."
76-
send_error_response(x, msg, -32603, error_msg, nothing)
76+
send_error_response(x, msg, -32603, error_msg, nothing)
7777
error(error_msg)
7878
end
7979
end

test/runtests.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ end
1616
fieldB::Vector{Int}
1717
end
1818

19-
Base.:(==)(a::Foo2,b::Foo2) = a.fieldA == b.fieldA && a.fieldB == b.fieldB
19+
Base.:(==)(a::Foo2, b::Foo2) = a.fieldA == b.fieldA && a.fieldB == b.fieldB
2020

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

2626
@testset "check response type" begin
2727
@test typed_res(nothing, Nothing) isa Nothing
28-
@test typed_res([1,"2",3], Vector{Any}) isa Vector{Any}
29-
@test typed_res([1,2,3], Vector{Int}) isa Vector{Int}
30-
@test typed_res([1,2,3], Vector{Float64}) isa Vector{Float64}
31-
@test typed_res(['f','o','o'], String) isa String
28+
@test typed_res([1, "2", 3], Vector{Any}) isa Vector{Any}
29+
@test typed_res([1, 2, 3], Vector{Int}) isa Vector{Int}
30+
@test typed_res([1, 2, 3], Vector{Float64}) isa Vector{Float64}
31+
@test typed_res(['f', 'o', 'o'], String) isa String
3232
@test typed_res("foo", String) isa String
3333
end
3434
end

test/test_interface_def.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
@test_throws ErrorException Foo()
44

5-
a = Foo(fieldA=1, fieldB="A")
5+
a = Foo(fieldA = 1, fieldB = "A")
66

77
@test a.fieldA == 1
88
@test a.fieldB == "A"
99
@test a.fieldC === missing
1010
@test a.fieldD === missing
1111

12-
b = Foo(fieldA=1, fieldB="A", fieldC="B", fieldD="C")
12+
b = Foo(fieldA = 1, fieldB = "A", fieldC = "B", fieldD = "C")
1313

1414
@test b.fieldA == 1
1515
@test b.fieldB == "A"
@@ -19,14 +19,14 @@
1919
@test Foo(JSON.parse(JSON.json(a))) == a
2020
@test Foo(JSON.parse(JSON.json(b))) == b
2121

22-
c = Foo2(fieldA=nothing, fieldB=[1,2])
22+
c = Foo2(fieldA = nothing, fieldB = [1, 2])
2323

2424
@test c.fieldA === nothing
25-
@test c.fieldB == [1,2]
25+
@test c.fieldB == [1, 2]
2626
@test Foo2(JSON.parse(JSON.json(c))) == c
2727

28-
d = Foo2(fieldA=3, fieldB=[1,2])
28+
d = Foo2(fieldA = 3, fieldB = [1, 2])
2929
@test d.fieldA === 3
30-
@test d.fieldB == [1,2]
30+
@test d.fieldB == [1, 2]
3131
@test Foo2(JSON.parse(JSON.json(d))) == d
3232
end

test/test_typed.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
JSONRPC.send(conn2, notify1_type, "TEST")
5050

51-
res = JSONRPC.send(conn2, request1_type, Foo(fieldA=1, fieldB="FOO"))
51+
res = JSONRPC.send(conn2, request1_type, Foo(fieldA = 1, fieldB = "FOO"))
5252

5353
@test res == "YES"
5454
@test g_var == "TEST"
@@ -80,7 +80,7 @@
8080
global conn = JSONRPC.JSONRPCEndpoint(sock, sock)
8181
global msg_dispatcher = JSONRPC.MsgDispatcher()
8282

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

8585
run(conn)
8686

0 commit comments

Comments
 (0)