Skip to content

Commit 6890ca3

Browse files
committed
Use span()
- `node.span` => `span(node)`
1 parent 5a72d92 commit 6890ca3

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/JuliaSyntaxHighlighting.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
182182
lineage::GreenLineage, ctx::HighlightContext; syntax_errors::Bool = false)
183183
(; node, parent) = lineage
184184
(; content, offset, lnode, pdepths) = ctx
185-
region = firstindex(content)+offset:node.span+offset
186-
regionstr = view(content, firstindex(content)+offset:prevind(content, node.span+offset+1))
185+
region = firstindex(content)+offset:span(node)+offset
186+
regionstr = view(content, firstindex(content)+offset:prevind(content, span(node)+offset+1))
187187
nkind = node.head.kind
188188
pnode = if !isnothing(parent) parent.node end
189189
pkind = if !isnothing(parent) kind(parent.node) end
@@ -211,7 +211,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
211211
end
212212
elseif nkind == K"macrocall" && numchildren(node) >= 2 &&
213213
kind(node[1]) == K"@" && kind(node[2]) == K"MacroName"
214-
region = first(region):first(region)+node[2].span
214+
region = first(region):first(region)+span(node[2])
215215
:julia_macro
216216
elseif nkind == K"StringMacroName"; :julia_macro
217217
elseif nkind == K"CmdMacroName"; :julia_macro
@@ -223,7 +223,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
223223
c ->kind(c) == K"::" && JuliaSyntax.is_trivia(c),
224224
children(node))
225225
if !isnothing(literal_typedecl)
226-
shift = sum(c ->Int(c.span), node[1:literal_typedecl])
226+
shift = sum(c ->Int(span(c)), node[1:literal_typedecl])
227227
region = first(region)+shift:last(region)
228228
:julia_type
229229
end
@@ -247,8 +247,8 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
247247
if nkind == K"="
248248
ifelse(ppkind == K"for", :julia_keyword, :julia_assignment)
249249
else # updating for <op>=
250-
push!(highlights, (firstindex(content)+offset:node.span+offset-1, :face, :julia_operator))
251-
push!(highlights, (node.span+offset:node.span+offset, :face, :julia_assignment))
250+
push!(highlights, (firstindex(content)+offset:span(node)+offset-1, :face, :julia_operator))
251+
push!(highlights, (span(node)+offset:span(node)+offset, :face, :julia_assignment))
252252
nothing
253253
end
254254
elseif nkind == K";" && pkind == K"parameters" && pnode == lnode
@@ -263,7 +263,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
263263
c ->kind(c) == K"where" && JuliaSyntax.is_trivia(c),
264264
children(node))
265265
if !isnothing(literal_where)
266-
shift = sum(c ->Int(c.span), node[1:literal_where])
266+
shift = sum(c ->Int(span(c)), node[1:literal_where])
267267
region = first(region)+shift:last(region)
268268
:julia_type
269269
end
@@ -282,7 +282,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
282282
elseif nkind in (K"call", K"dotcall") && JuliaSyntax.is_prefix_call(node)
283283
argoffset, arg1 = 0, nothing
284284
for arg in children(node)
285-
argoffset += arg.span
285+
argoffset += span(arg)
286286
if !JuliaSyntax.is_trivia(arg)
287287
arg1 = arg
288288
break
@@ -297,7 +297,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
297297
kind(arg1[end]) == K"quote" &&
298298
numchildren(arg1[end]) == 1 &&
299299
kind(arg1[end][1]) == K"Identifier"
300-
region = first(region)+argoffset-arg1[end][1].span:first(region)+argoffset-1
300+
region = first(region)+argoffset-span(arg1[end][1]):first(region)+argoffset-1
301301
name = Symbol(regionstr)
302302
ifelse(name in BUILTIN_FUNCTIONS, :julia_builtin, :julia_funcall)
303303
end
@@ -342,7 +342,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
342342
cctx = HighlightContext(content, offset, lnode, pdepths)
343343
_hl_annotations!(highlights, GreenLineage(child, lineage), cctx)
344344
lnode = child
345-
offset += child.span
345+
offset += span(child)
346346
end
347347
end
348348

0 commit comments

Comments
 (0)