Skip to content

Commit

Permalink
feat(lua): support if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Goose97 committed Nov 21, 2024
1 parent 712fb11 commit 8e5f43d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 20 deletions.
22 changes: 22 additions & 0 deletions queries/lua/neolog-log-container.scm
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,25 @@
parameters: (parameters) @log_container
body: (block) @logable_range
)

(if_statement
condition: (_) @log_container
consequence: (block) @logable_range
)

(if_statement
alternative: (elseif_statement
condition: (_) @log_container
consequence: (block) @logable_range
)
)

(for_statement
clause: (for_generic_clause (variable_list) @log_container)
body: (block) @logable_range
)

(for_statement
clause: (for_numeric_clause) @log_container
body: (block) @logable_range
)
54 changes: 34 additions & 20 deletions tests/neolog/actions/lang/lua_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local neolog = require("neolog")
local helper = require("tests.neolog.helper")
local actions = require("neolog.actions")

describe("lua", function()
before_each(function()
Expand All @@ -11,8 +12,6 @@ describe("lua", function()
end)

it("supports variable declaration", function()
local actions = require("neolog.actions")

local input = [[
local fo|o = "bar"
]]
Expand Down Expand Up @@ -47,8 +46,6 @@ describe("lua", function()
end)

it("supports variable assignment", function()
local actions = require("neolog.actions")

local input = [[
local foo = "bar"
fo|o = "baz"
Expand Down Expand Up @@ -86,8 +83,6 @@ describe("lua", function()
end)

it("supports function parameters", function()
local actions = require("neolog.actions")

helper.assert_scenario({
input = [[
function foo(ba|r)
Expand Down Expand Up @@ -134,10 +129,41 @@ describe("lua", function()
})
end)

it("supports if statement", function()
helper.assert_scenario({
input = [[
if not fo|o > 1 and bar < baz then
return nil
elseif bar then
return nil
elseif baz then
return nil
end
]],
filetype = "lua",
action = function()
vim.cmd("normal! vap")
actions.add_log({ position = "below" })
end,
expected = [[
if not foo > 1 and bar < baz then
print("foo", foo)
print("bar", bar)
print("baz", baz)
return nil
elseif bar then
print("bar", bar)
return nil
elseif baz then
print("baz", baz)
return nil
end
]],
})
end)

describe("supports identifier nested in complex expressions", function()
it("supports ternary operator", function()
local actions = require("neolog.actions")

local input = [[
local foo =
predicate and
Expand Down Expand Up @@ -181,8 +207,6 @@ describe("lua", function()
end)

it("supports table constructor", function()
local actions = require("neolog.actions")

helper.assert_scenario({
input = [[
local foo = { bar = b|ar }
Expand Down Expand Up @@ -212,8 +236,6 @@ describe("lua", function()
end)

it("supports function invocations", function()
local actions = require("neolog.actions")

helper.assert_scenario({
input = [[
foo(ba|r, baz)
Expand Down Expand Up @@ -262,8 +284,6 @@ describe("lua", function()

describe("supports member access expression", function()
it("supports dot member access", function()
local actions = require("neolog.actions")

helper.assert_scenario({
input = [[
local foo = ba|r.bar
Expand Down Expand Up @@ -325,8 +345,6 @@ describe("lua", function()
end)

it("supports bracket member access", function()
local actions = require("neolog.actions")

helper.assert_scenario({
input = [[
local foo = ba|r["bar"]
Expand Down Expand Up @@ -390,8 +408,6 @@ describe("lua", function()

describe("supports visual selection log", function()
it("supports variable declaration", function()
local actions = require("neolog.actions")

helper.assert_scenario({
input = [[
local a = b| + c
Expand Down Expand Up @@ -470,8 +486,6 @@ describe("lua", function()
end)

it("supports function parameters", function()
local actions = require("neolog.actions")

helper.assert_scenario({
input = [[
function foo(a, b|, c)
Expand Down

0 comments on commit 8e5f43d

Please sign in to comment.