From 5f158b153ec75f7ff3c9ea738b1dcd328bc564e3 Mon Sep 17 00:00:00 2001 From: c42f Date: Wed, 12 Oct 2022 11:28:42 +1000 Subject: [PATCH] Fix incomplete detection for tree with no parents (#122) --- src/hooks.jl | 3 +++ test/hooks.jl | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/hooks.jl b/src/hooks.jl index 6f0ecfe8..ca4c9974 100644 --- a/src/hooks.jl +++ b/src/hooks.jl @@ -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 diff --git a/test/hooks.jl b/test/hooks.jl index 2604e9f2..953df0ae 100644 --- a/test/hooks.jl +++ b/test/hooks.jl @@ -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 @@ -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