Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/source/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ccjmne committed Dec 16, 2024
2 parents ecc9d7f + 3af10f9 commit 6cd407b
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 42 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Run Tests

on:
push:
branches: [ "*" ]
pull_request:
branches: [ main ]

jobs:
test:

runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Install Make Dependencies
run: |
sudo apt-get update
sudo apt-get install libtool-bin autoconf automake cmake g++ pkg-config unzip gettext curl -y
- name: Install Neovim
run: |
sudo snap install nvim --classic
- name: Install Plenary
run: |
git clone https://github.com/nvim-lua/plenary.nvim.git
mkdir -p .local/share/nvim/lazy/
mv plenary.nvim .local/share/nvim/lazy/
- name: Run Tests
env:
XDG_CONFIG_HOME: ${{ github.workspace }}/.config
XDG_DATA_HOME: ${{ github.workspace }}/.local/share
XDG_STATE_HOME: ${{ github.workspace }}/.local/state
XDG_CACHE_HOME: ${{ github.workspace }}/.cache
run: make test
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ TESTS_DIR=tests

.PHONY: test

# TODO I want test to contain a lua-language-server pass

test_nvim:
@nvim \
--headless \
Expand All @@ -13,7 +11,7 @@ test_nvim:
-c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${TESTS_INIT}' }"

test:
-$(MAKE) test_nvim || exit 1
$(MAKE) test_nvim

test-watch:
nodemon -e lua -x "$(MAKE) test"
nodemon -e lua -x "$(MAKE) test || exit 1"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Moving slowly, showing each command
{
"aaronik/treewalker.nvim",
opts = {
highlight = true -- default is false; can also be a duration
highlight = true -- briefly highlight the node after jumping to it
-- can be numeric to specify highlight duration instead
}
}
```
Expand Down
5 changes: 4 additions & 1 deletion lua/treewalker/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ local Treewalker = {}

---@alias Opts { highlight: boolean | integer }

-- Default setup() options
---@type Opts
Treewalker.opts = {}
Treewalker.opts = {
highlight = true
}

---@param opts Opts | nil
function Treewalker.setup(opts)
Expand Down
21 changes: 21 additions & 0 deletions lua/treewalker/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ function M.get_descendants(node)
return descendants
end

---@param node TSNode
---@return TSNode
function M.get_farthest_ancestor_with_same_srow(node)
local node_row = node:range()
local farthest_ancestor = node
local iter_row = node:range()
local iter = node:parent()


while iter do
iter_row = iter:range()
if iter_row ~= node_row then
break
end
farthest_ancestor = iter
iter = iter:parent()
end

return farthest_ancestor
end

--- Take a list of nodes and unique them based on line start
---@param nodes TSNode[]
---@return TSNode[]
Expand Down
6 changes: 0 additions & 6 deletions lua/treewalker/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ M.guid = function()
end)
end

---@param env_key string
---@return boolean
M.has_env_var = function(env_key)
return type(os.getenv(env_key)) ~= type(nil)
end

---reverse an array table
---@param t table
M.reverse = function (t)
Expand Down
3 changes: 1 addition & 2 deletions plugin/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local util = require "treewalker.util"

local function tw()
-- local util = require "treewalker.util"
-- return util.R('treewalker')
return require('treewalker')
end
Expand Down
7 changes: 0 additions & 7 deletions tests/minimal_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ local lazypath = vim.fn.stdpath("data") .. "/lazy"
vim.notify = print
vim.opt.rtp:append(".")
vim.opt.rtp:append(lazypath .. "/plenary.nvim")
vim.opt.rtp:append(lazypath .. "/nui.nvim")
vim.opt.rtp:append(lazypath .. "/telescope.nvim")
-- vim.opt.rtp:append(lazypath .. "/nvim-nio")

-- -- Get all our normal plugins into the test env
-- local suite = os.getenv("SUITE")
-- vim.opt.rtp:append(suite .. "nvim")

vim.opt.swapfile = false

Expand Down
24 changes: 16 additions & 8 deletions tests/treewalker/acceptance_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ describe("Treewalker", function()
end)

it("respects highlight config option", function()
spy.on(ops, "highlight")
vim.wait(250 + 5) -- wait out potential "buf_clear" calls queue up from previous tests
local highlight = spy.on(ops, "highlight")
local bufclear = spy.on(vim.api, "nvim_buf_clear_namespace")

-- 'nvim_buf_clear_namespace' should be called <calls> times
Expand All @@ -92,55 +93,62 @@ describe("Treewalker", function()
assert.spy(bufclear).was.called(calls)
end

treewalker.setup()
highlight:clear()
treewalker.setup() -- highlight defaults to true, doesn't blow up with empty setup
vim.fn.cursor(23, 5)
treewalker.move_out()
treewalker.move_down()
treewalker.move_up()
treewalker.move_in()
assert.spy(ops.highlight).was.not_called()
assert.spy(highlight).was.called(4)
assert_bufclears_after(250, 4)

highlight:clear()
treewalker.setup({ highlight = 0 })
vim.fn.cursor(23, 5)
treewalker.move_out()
treewalker.move_down()
treewalker.move_up()
treewalker.move_in()
assert.spy(ops.highlight).was.not_called()
assert.spy(highlight).was.not_called()

highlight:clear()
treewalker.setup({ highlight = false })
vim.fn.cursor(23, 5)
treewalker.move_out()
treewalker.move_down()
treewalker.move_up()
treewalker.move_in()
assert.spy(ops.highlight).was.not_called()
assert.spy(highlight).was.not_called()

highlight:clear()
treewalker.setup({ highlight = true })
vim.fn.cursor(23, 5)
treewalker.move_out()
treewalker.move_down()
treewalker.move_up()
treewalker.move_in()
assert.spy(ops.highlight).was.called(4)
assert.spy(highlight).was.called(4)
assert_bufclears_after(250, 4)

highlight:clear()
treewalker.setup({ highlight = 50 })
vim.fn.cursor(23, 5)
treewalker.move_out()
treewalker.move_down()
treewalker.move_up()
treewalker.move_in()
assert.spy(ops.highlight).was.called(8)
assert.spy(highlight).was.called(4)
assert_bufclears_after(50, 4)

highlight:clear()
treewalker.setup({ highlight = 500 })
vim.fn.cursor(23, 5)
treewalker.move_out()
treewalker.move_down()
treewalker.move_up()
treewalker.move_in()
assert.spy(ops.highlight).was.called(12)
assert.spy(highlight).was.called(4)
assert_bufclears_after(500, 4)
end)
end)
Expand Down
13 changes: 0 additions & 13 deletions tests/treewalker/util_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,6 @@ describe("util", function()
end)
end)

describe("ensure_env_var", function()
it("returns true", function()
-- always set
local res = util.has_env_var("SHELL")
assert.is_true(res)
end)

it("returns false", function()
local res = util.has_env_var("IM_SUPER_SURE_THIS_ENV_VAR_WONT_BE_SET_FR_FR")
assert.is_false(res)
end)
end)

describe("reverse", function()
it("reverses an array table", function()
local t = { 1, 2, 3, 4, 5 }
Expand Down

0 comments on commit 6cd407b

Please sign in to comment.