Skip to content

Commit 316f868

Browse files
committed
Store last byte in SourceRef and allow removing green_tree
Exactly what information we want to prune in the final implementation is not determined, but `green_tree` is probably part of it.
1 parent fc02d07 commit 316f868

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/syntax_graph.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,17 @@ end
325325
struct SourceRef
326326
file::SourceFile
327327
first_byte::Int
328-
# TODO: Do we need the green node, or would last_byte suffice?
329-
green_tree::JuliaSyntax.GreenNode
328+
last_byte::Int
329+
# TODO: `nothing` is only used when we `prune` a tree, but we may not need
330+
# this field at all.
331+
green_tree::Union{Nothing, JuliaSyntax.GreenNode}
330332
end
331333

334+
SourceRef(file::SourceFile, first_byte::Int, green_tree::Union{Nothing, JuliaSyntax.GreenNode}) =
335+
SourceRef(file, first_byte, first_byte + span(green_tree) - 1, green_tree)
336+
332337
JuliaSyntax.sourcefile(src::SourceRef) = src.file
333-
JuliaSyntax.byte_range(src::SourceRef) = src.first_byte:(src.first_byte + span(src.green_tree) - 1)
338+
JuliaSyntax.byte_range(src::SourceRef) = src.first_byte:src.last_byte
334339

335340
# TODO: Adding these methods to support LineNumberNode is kind of hacky but we
336341
# can remove these after JuliaLowering becomes self-bootstrapping for macros

0 commit comments

Comments
 (0)