Skip to content

Commit a9acdae

Browse files
authored
Change annotations to use a NamedTuple (#55741)
Due to popular demand, the type of annotations is to be changed from a `Tuple{UnitRange{Int}, Pair{Symbol, Any}}` to a `NamedTuple{(:region, :label, :value), Tuple{UnitRange{Int}, Symbol, Any}}`. This requires the expected code churn to `strings/annotated.jl`, and some changes to the StyledStrings and JuliaSyntaxHighlighting libraries. Closes #55249 and closes #55245.
1 parent a7521ea commit a9acdae

File tree

15 files changed

+226
-204
lines changed

15 files changed

+226
-204
lines changed

base/strings/annotated.jl

Lines changed: 123 additions & 103 deletions
Large diffs are not rendered by default.

base/strings/io.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,12 @@ function AnnotatedString(chars::AbstractVector{C}) where {C<:AbstractChar}
816816
end
817817
end
818818
end
819-
annots = Tuple{UnitRange{Int}, Pair{Symbol, Any}}[]
819+
annots = RegionAnnotation[]
820820
point = 1
821821
for c in chars
822822
if c isa AnnotatedChar
823823
for annot in c.annotations
824-
push!(annots, (point:point, annot))
824+
push!(annots, (point:point, annot...))
825825
end
826826
end
827827
point += ncodeunits(c)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
401bb32ca43a8460d6790ee80e695bb5
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
db2c732d3343f5a8770b3516cdd900587d497feab2259a937d354fac436ab3cb099b0401fb4e05817e75744fb9877ab69b1e4879d8a710b33b69c95b7e58d961

deps/checksums/JuliaSyntaxHighlighting-b89dd99db56700c47434df6106b6c6afd1c9ed01.tar.gz/md5

Lines changed: 0 additions & 1 deletion
This file was deleted.

deps/checksums/JuliaSyntaxHighlighting-b89dd99db56700c47434df6106b6c6afd1c9ed01.tar.gz/sha512

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f053c84279a8920f355f202e605842af
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b6f4c1d6c0dc73a520472746c96adff506e5405154e4b93d419e07b577b01804d2fc87d4a6cac48a136777579bebf8388c2c1e54f849b51e233138d482146b4f

deps/checksums/StyledStrings-f6035eb97b516862b16e36cab2ecc6ea8adc3d7c.tar.gz/md5

Lines changed: 0 additions & 1 deletion
This file was deleted.

deps/checksums/StyledStrings-f6035eb97b516862b16e36cab2ecc6ea8adc3d7c.tar.gz/sha512

Lines changed: 0 additions & 1 deletion
This file was deleted.

doc/src/manual/strings.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ to keep the string annotations.
12301230

12311231
```jldoctest
12321232
julia> str = Base.AnnotatedString("hello there",
1233-
[(1:5, :word => :greeting), (7:11, :label => 1)])
1233+
[(1:5, :word, :greeting), (7:11, :label, 1)])
12341234
"hello there"
12351235
12361236
julia> length(str)
@@ -1242,7 +1242,7 @@ julia> lpad(str, 14)
12421242
julia> typeof(lpad(str, 7))
12431243
Base.AnnotatedString{String}
12441244
1245-
julia> str2 = Base.AnnotatedString(" julia", [(2:6, :face => :magenta)])
1245+
julia> str2 = Base.AnnotatedString(" julia", [(2:6, :face, :magenta)])
12461246
" julia"
12471247
12481248
julia> Base.annotatedstring(str, str2)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
JULIASYNTAXHIGHLIGHTING_BRANCH = main
2-
JULIASYNTAXHIGHLIGHTING_SHA1 = b89dd99db56700c47434df6106b6c6afd1c9ed01
2+
JULIASYNTAXHIGHLIGHTING_SHA1 = 19bd57b89c648592155156049addf67e0638eab1
33
JULIASYNTAXHIGHLIGHTING_GIT_URL := https://github.com/julialang/JuliaSyntaxHighlighting.jl.git
44
JULIASYNTAXHIGHLIGHTING_TAR_URL = https://api.github.com/repos/julialang/JuliaSyntaxHighlighting.jl/tarball/$1

stdlib/Markdown/src/render/terminal/formatting.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ function with_output_annotations(f::Function, io::AnnotIO, annots::Pair{Symbol,
1919
start = position(aio) + 1
2020
f(io)
2121
stop = position(aio)
22-
sortedindex = searchsortedlast(aio.annotations, (start:stop,), by=first)
22+
sortedindex = searchsortedlast(aio.annotations, (region=start:stop,), by=a -> a.region)
2323
for (i, annot) in enumerate(annots)
24-
insert!(aio.annotations, sortedindex + i, (start:stop, annot))
24+
insert!(aio.annotations, sortedindex + i, (start:stop, annot...))
2525
end
2626
end
2727

stdlib/StyledStrings.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
STYLEDSTRINGS_BRANCH = main
2-
STYLEDSTRINGS_SHA1 = f6035eb97b516862b16e36cab2ecc6ea8adc3d7c
2+
STYLEDSTRINGS_SHA1 = 056e843b2d428bb9735b03af0cff97e738ac7e14
33
STYLEDSTRINGS_GIT_URL := https://github.com/JuliaLang/StyledStrings.jl.git
44
STYLEDSTRINGS_TAR_URL = https://api.github.com/repos/JuliaLang/StyledStrings.jl/tarball/$1

test/strings/annotated.jl

Lines changed: 91 additions & 89 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)