Commit a718c6c
committed
comm: complete migration to JSON.jl v1
This commit completes the migration to JSON.jl v1. As explained in
#300, JSON.jl v1 no longer supports out-of-box
deserialization for custom data types and now requires explicit
tags for each custom data type field (see
https://publish.obsidian.md/jetls/work/JETLS/Switch+JSON3.jl+to+JSON.jl+v1#2025-11-16).
This presents a significant challenge for LSP.jl, which uses the
`@interface` DSL for TypeScript-like type definitions, because
such tag generation must also be done through macro generation.
Without this approach, we would need to scatter `@tags` macros
and their associated `choosetype` definitions throughout the code
base, which should be very very tedious.
This commit further complicates the already complex `@interface`
implementation to implement such automatic tag generation.
While this macro has arguably become one of the most arcane
Julia macros in existence, it does function correctly.
Numerous tests have also been added.
Most importantly, completing the switch to JSON v1 provides the
following JSON communication performance improvements:
```julia
using LSP, JSON
function readlsp_JSON_v1(msg_str::AbstractString)
lazyjson = JSON.lazy(msg_str)
if hasproperty(lazyjson, :method)
method = lazyjson.method[]
if method isa String && haskey(LSP.method_dispatcher, method)
return JSON.parse(lazyjson, LSP.method_dispatcher[method])
end
return JSON.parse(lazyjson, Dict{Symbol,Any})
else # TODO parse to ResponseMessage?
return JSON.parse(lazyjson, Dict{Symbol,Any})
end
end
```
```julia
using JSON3, LSP
const Parsed = @NamedTuple{method::Union{Nothing,String}}
function readlsp_JSON3(msg_str::AbstractString)
parsed = JSON3.read(msg_str, Parsed)
parsed_method = parsed.method
if parsed_method !== nothing
if haskey(LSP.method_dispatcher, parsed_method)
return JSON3.read(msg_str, LSP.method_dispatcher[parsed_method])
end
return JSON3.read(msg_str, Dict{Symbol,Any})
else # TODO parse to ResponseMessage?
return JSON3.read(msg_str, Dict{Symbol,Any})
end
end
```
```julia
uri = LSP.URIs2.filepath2uri(abspath("src/JETLS.jl"))
s = """{
"jsonrpc": "2.0",
"id": 0,
"method": "textDocument/completion",
"params": {
"textDocument": {
"uri": "$uri"
},
"position": {
"line": 0,
"character": 0
},
"workDoneToken": "workDoneToken",
"partialResultToken": "partialResultToken"
}
}""";
```
```julia-repl
julia> @benchmark readlsp_JSON3(s)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
Range (min … max): 363.792 μs … 1.154 ms ┊ GC (min … max): 0.00% … 0.00%
Time (median): 379.958 μs ┊ GC (median): 0.00%
Time (mean ± σ): 385.114 μs ± 16.805 μs ┊ GC (mean ± σ): 0.00% ± 0.00%
▁▁ ▁ ▄▇█▇▆▆▅▅▅▅▄▄▄▄▃▃▃▂▂▂▂▂▁▁ ▁ ▁ ▂
██████████████████████████████████████▇▇▇▇▇▇▇▇▆▅▆▆▆▆▅▆▇▆▅▆▆▅ █
364 μs Histogram: log(frequency) by time 447 μs <
Memory estimate: 5.91 KiB, allocs estimate: 120.
julia> @benchmark readlsp_JSON_v1(s)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
Range (min … max): 11.625 μs … 113.000 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 12.375 μs ┊ GC (median): 0.00%
Time (mean ± σ): 12.658 μs ± 1.933 μs ┊ GC (mean ± σ): 0.00% ± 0.00%
▃▄▅▅▆██▇█▅▅▄▃▂▂ ▂
▇██████████████████▇▇▆▇▆▅▇▅▅▆▆▆▇▆▆▇▇▆▇▆▆▇▇▅▇██▆▇▅▅▆▆▆▅▅▄▄▂▅▆ █
11.6 μs Histogram: log(frequency) by time 17.4 μs <
Memory estimate: 4.53 KiB, allocs estimate: 84.
```
---
- renamed `LSP/src/utils` to `LSP/src/DSL`
- also added precompilation statements for better FTTJ
- added docstrings1 parent eeb2e1e commit a718c6c
File tree
15 files changed
+760
-239
lines changed- JSONRPC/src
- LSP
- src
- DSL
- language-features
- utils
- test
- src
- testrunner
- utils
15 files changed
+760
-239
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
Large diffs are not rendered by default.
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
1 | 43 | | |
2 | 44 | | |
3 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
12 | | - | |
13 | | - | |
| 15 | + | |
14 | 16 | | |
15 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
16 | 31 | | |
| 32 | + | |
17 | 33 | | |
18 | 34 | | |
19 | 35 | | |
| |||
49 | 65 | | |
50 | 66 | | |
51 | 67 | | |
| 68 | + | |
| 69 | + | |
52 | 70 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | 4 | | |
16 | 5 | | |
17 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
238 | 237 | | |
239 | 238 | | |
240 | 239 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
0 commit comments