Skip to content

Commit

Permalink
Fix incomplete detection for tree with no parents (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
c42f authored Oct 12, 2022
1 parent 4132d75 commit 5f158b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/hooks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function _incomplete_tag(n::SyntaxNode)
end
end
end
if isnothing(c.parent)
return :other
end
kp = kind(c.parent)
if kp == K"string"
return :string
Expand Down
17 changes: 10 additions & 7 deletions test/hooks.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
@testset "Hooks for Core integration" begin
@testset "whitespace parsing" begin
@test JuliaSyntax.core_parser_hook("", "somefile", 0, :statement) == Core.svec(nothing, 0)
@test JuliaSyntax.core_parser_hook("", "somefile", 0, :statement) == Core.svec(nothing, 0)
@test JuliaSyntax._core_parser_hook("", "somefile", 1, 0, :statement) == Core.svec(nothing, 0)
@test JuliaSyntax._core_parser_hook("", "somefile", 1, 0, :statement) == Core.svec(nothing, 0)

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

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

@testset "filename is used" begin
ex = JuliaSyntax.core_parser_hook("@a", "somefile", 0, :statement)[1]
ex = JuliaSyntax._core_parser_hook("@a", "somefile", 1, 0, :statement)[1]
@test Meta.isexpr(ex, :macrocall)
@test ex.args[2] == LineNumberNode(1, "somefile")
end
Expand Down Expand Up @@ -95,5 +95,8 @@
end
end
JuliaSyntax.enable_in_core!(false)

# Should not throw
@test JuliaSyntax._core_parser_hook("+=", "somefile", 1, 0, :statement)[1] isa Expr
end
end

0 comments on commit 5f158b1

Please sign in to comment.