Skip to content

Commit 5f158b1

Browse files
authored
Fix incomplete detection for tree with no parents (#122)
1 parent 4132d75 commit 5f158b1

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/hooks.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ function _incomplete_tag(n::SyntaxNode)
4949
end
5050
end
5151
end
52+
if isnothing(c.parent)
53+
return :other
54+
end
5255
kp = kind(c.parent)
5356
if kp == K"string"
5457
return :string

test/hooks.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
@testset "Hooks for Core integration" begin
22
@testset "whitespace parsing" begin
3-
@test JuliaSyntax.core_parser_hook("", "somefile", 0, :statement) == Core.svec(nothing, 0)
4-
@test JuliaSyntax.core_parser_hook("", "somefile", 0, :statement) == Core.svec(nothing, 0)
3+
@test JuliaSyntax._core_parser_hook("", "somefile", 1, 0, :statement) == Core.svec(nothing, 0)
4+
@test JuliaSyntax._core_parser_hook("", "somefile", 1, 0, :statement) == Core.svec(nothing, 0)
55

6-
@test JuliaSyntax.core_parser_hook(" ", "somefile", 2, :statement) == Core.svec(nothing,2)
7-
@test JuliaSyntax.core_parser_hook(" #==# ", "somefile", 6, :statement) == Core.svec(nothing,6)
6+
@test JuliaSyntax._core_parser_hook(" ", "somefile", 1, 2, :statement) == Core.svec(nothing,2)
7+
@test JuliaSyntax._core_parser_hook(" #==# ", "somefile", 1, 6, :statement) == Core.svec(nothing,6)
88

9-
@test JuliaSyntax.core_parser_hook(" x \n", "somefile", 0, :statement) == Core.svec(:x,4)
10-
@test JuliaSyntax.core_parser_hook(" x \n", "somefile", 0, :atom) == Core.svec(:x,2)
9+
@test JuliaSyntax._core_parser_hook(" x \n", "somefile", 1, 0, :statement) == Core.svec(:x,4)
10+
@test JuliaSyntax._core_parser_hook(" x \n", "somefile", 1, 0, :atom) == Core.svec(:x,2)
1111
end
1212

1313
@testset "filename is used" begin
14-
ex = JuliaSyntax.core_parser_hook("@a", "somefile", 0, :statement)[1]
14+
ex = JuliaSyntax._core_parser_hook("@a", "somefile", 1, 0, :statement)[1]
1515
@test Meta.isexpr(ex, :macrocall)
1616
@test ex.args[2] == LineNumberNode(1, "somefile")
1717
end
@@ -95,5 +95,8 @@
9595
end
9696
end
9797
JuliaSyntax.enable_in_core!(false)
98+
99+
# Should not throw
100+
@test JuliaSyntax._core_parser_hook("+=", "somefile", 1, 0, :statement)[1] isa Expr
98101
end
99102
end

0 commit comments

Comments
 (0)