Skip to content

Commit e6e9ae1

Browse files
committed
Move overload of Base.range() to JuliaSyntax.byte_range()
The Base overload was a mistake - it doesn't really have the same semantics as compared to `Base.range()`. It's also not got the clearest name!
1 parent f99b76f commit e6e9ae1

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

src/diagnostics.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ end
4040
first_byte(d::Diagnostic) = d.first_byte
4141
last_byte(d::Diagnostic) = d.last_byte
4242
is_error(d::Diagnostic) = d.level === :error
43-
Base.range(d::Diagnostic) = first_byte(d):last_byte(d)
4443

4544
# Make relative path into a file URL
4645
function _file_url(filename)
@@ -89,7 +88,7 @@ function show_diagnostic(io::IO, diagnostic::Diagnostic, source::SourceFile)
8988
_printstyled(io, "# $prefix @ ", fgcolor=:light_black)
9089
_printstyled(io, "$locstr", fgcolor=:light_black, href=file_href)
9190
print(io, "\n")
92-
highlight(io, source, range(diagnostic),
91+
highlight(io, source, byte_range(diagnostic),
9392
note=diagnostic.message, notecolor=color,
9493
context_lines_before=1, context_lines_after=0)
9594
end

src/syntax_tree.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,15 @@ span(node::AbstractSyntaxNode) = span(node.raw)
123123

124124
first_byte(node::AbstractSyntaxNode) = node.position
125125
last_byte(node::AbstractSyntaxNode) = node.position + span(node) - 1
126+
byte_range(node) = first_byte(node):last_byte(node)
126127

127128
"""
128129
sourcetext(node)
129130
130131
Get the full source text of a node.
131132
"""
132133
function sourcetext(node::AbstractSyntaxNode)
133-
view(node.source, range(node))
134-
end
135-
136-
function Base.range(node::AbstractSyntaxNode)
137-
(node.position-1) .+ (1:span(node))
134+
view(node.source, byte_range(node))
138135
end
139136

140137
source_line(node::AbstractSyntaxNode) = source_line(node.source, node.position)

tools/check_all_packages.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Logging.with_logger(TerminalLogger()) do
3939
mismatch_count += 1
4040
failing_source = sprint(context=:color=>true) do io
4141
for c in reduce_tree(parseall(SyntaxNode, text))
42-
JuliaSyntax.highlight(io, c.source, range(c), context_lines_inner=5)
42+
JuliaSyntax.highlight(io, c.source, JuliaSyntax.byte_range(c), context_lines_inner=5)
4343
println(io, "\n")
4444
end
4545
end

0 commit comments

Comments
 (0)