Skip to content

Commit

Permalink
ci: add luals check
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Dec 11, 2024
1 parent 9b5bc54 commit eb06aa6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 13 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ jobs:
- name: Lint
run: make stylua-check

luals:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: leafo/gh-actions-lua@v9
with:
luaVersion: "5.1.5"

- uses: leafo/gh-actions-luarocks@v4

- name: Download nvim-test
run: make nvim-test

- name: LuaLS
run: make luals-check

test:
runs-on: ubuntu-latest

Expand All @@ -37,7 +55,7 @@ jobs:
# - 'v0.10.0'

env:
NEOVIM_VERSION: ${{ matrix.neovim_version }}
NVIM_TEST_VERSION: ${{ matrix.neovim_version }}

steps:
- name: Checkout
Expand Down
47 changes: 40 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DEFAULT_GOAL := test

NEOVIM_VERSION ?= v0.9.5
NEOVIM_RUNNER_VERSION ?= v0.10.0
NVIM_TEST_VERSION ?= v0.10.2
NVIM_RUNNER_VERSION ?= v0.10.2

NVIM_TS_SHA ?= 894cb3c

Expand All @@ -18,26 +18,59 @@ nvim-treesitter:
nvim-test:
git clone https://github.com/lewis6991/nvim-test
nvim-test/bin/nvim-test --init \
--runner_version $(NEOVIM_RUNNER_VERSION) \
--target_version $(NEOVIM_VERSION)
--runner_version $(NVIM_RUNNER_VERSION) \
--target_version $(NVIM_TEST_VERSION)

.PHONY: test
test: nvim-test nvim-treesitter
nvim-test/bin/nvim-test test \
--runner_version $(NEOVIM_RUNNER_VERSION) \
--target_version $(NEOVIM_VERSION) \
--runner_version $(NVIM_RUNNER_VERSION) \
--target_version $(NVIM_TEST_VERSION) \
--lpath=$(PWD)/lua/?.lua \
--filter="$(FILTER)" \
--verbose

.PHONY: parsers
parsers: nvim-test nvim-treesitter
$(XDG_DATA_HOME)/nvim-test/nvim-runner-$(NEOVIM_RUNNER_VERSION)/bin/nvim \
$(XDG_DATA_HOME)/nvim-test/nvim-runner-$(NVIM_RUNNER_VERSION)/bin/nvim \
--clean -u NONE -c 'source install_parsers.lua'

lint:
luacheck lua

# ------------------------------------------------------------------------------
# LuaLS
# ------------------------------------------------------------------------------

ifeq ($(shell uname -m),arm64)
LUALS_ARCH ?= arm64
else
LUALS_ARCH ?= x64
endif

LUALS_VERSION := 3.13.2
LUALS_TARBALL := lua-language-server-$(LUALS_VERSION)-$(shell uname -s)-$(LUALS_ARCH).tar.gz
LUALS_URL := https://github.com/LuaLS/lua-language-server/releases/download/$(LUALS_VERSION)/$(LUALS_TARBALL)

.INTERMEDIATE: $(LUALS_TARBALL)
$(LUALS_TARBALL):
wget $(LUALS_URL)

luals: $(LUALS_TARBALL)
mkdir luals
tar -xf $< -C luals

export VIMRUNTIME=$(XDG_DATA_HOME)/nvim-test/nvim-test-$(NVIM_TEST_VERSION)/share/nvim/runtime
.PHONY: luals-check
luals-check: luals nvim-test
ls $(VIMRUNTIME)
VIMRUNTIME=$(XDG_DATA_HOME)/nvim-test/nvim-test-$(NVIM_TEST_VERSION)/share/nvim/runtime \
luals/bin/lua-language-server \
--logpath=luals_check \
--configpath=../.luarc.json \
--check=lua
@grep '^\[\]$$' luals_check/check.json

# ------------------------------------------------------------------------------
# Stylua
# ------------------------------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions lua/treesitter-context/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ local function get_parent_nodes(langtree, range)

local ret = {} --- @type TSNode[]

--- @diagnostic disable-next-line:undefined-field added in 0.11
if root.child_containing_descendant ~= nil then
local p = root --- @type TSNode?
while p do
ret[#ret + 1] = p
p = p:child_containing_descendant(n)
--- @diagnostic disable-next-line:undefined-field added in 0.11
p = p:child_containing_descendant(n) --- @type TSNode?
end
ret[#ret + 1] = n
else
while n do
table.insert(ret, 1, n)
n = n:parent()
n = n:parent() --- @type TSNode?
end
end

Expand Down Expand Up @@ -86,6 +88,7 @@ end
--- @param query vim.treesitter.Query
--- @return Range4?
local context_range = cache.memoize(function(node, bufnr, query)
--- @diagnostic disable-next-line:missing-fields
local range = { node:range() } --- @type Range4
range[3] = range[1] + 1
range[4] = 0
Expand Down
16 changes: 13 additions & 3 deletions lua/treesitter-context/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ local function highlight_contexts(bufnr, ctx_bufnr, contexts)
local parser = buf_highlighter.tree

parser:for_each_tree(function(tstree, ltree)
--- @diagnostic disable-next-line:invisible
local buf_query = buf_highlighter:get_query(ltree:lang())
--- @diagnostic disable-next-line:invisible
local query = buf_query:query()
if not query then
return
Expand All @@ -164,10 +166,13 @@ local function highlight_contexts(bufnr, ctx_bufnr, contexts)
if nsrow >= start_row then
local msrow = offset + (nsrow - start_row)
local merow = offset + (nerow - start_row)
local hl --- @type integer
local hl --- @type integer?
--- @diagnostic disable-next-line: invisible naughty
if buf_query.get_hl_from_capture then
--- @diagnostic disable-next-line: invisible naughty
hl = buf_query:get_hl_from_capture(capture)
else
--- @diagnostic disable-next-line: invisible naughty
hl = buf_query.hl_cache[capture]
end
local priority = tonumber(metadata.priority)
Expand Down Expand Up @@ -341,6 +346,7 @@ end
--- @param context_winid integer
local function horizontal_scroll_contexts(winid, context_winid)
local active_win_view = api.nvim_win_call(winid, fn.winsaveview)
--- @type vim.fn.winsaveview.ret
local context_win_view = api.nvim_win_call(context_winid, fn.winsaveview)
if active_win_view.leftcol ~= context_win_view.leftcol then
context_win_view.leftcol = active_win_view.leftcol
Expand All @@ -366,8 +372,10 @@ local function copy_extmarks(bufnr, ctx_bufnr, contexts)
)

for _, m in ipairs(extmarks) do
--- @type integer, integer, integer, vim.api.keyset.extmark_details
local id, row, col, opts = m[1], m[2], m[3], m[4]
local id = m[1]
local row = m[2]
local col = m[3] --[[@as integer]]
local opts = m[4] --[[@as vim.api.keyset.extmark_details]]

local start_row = offset + (row - ctx_srow)

Expand All @@ -384,6 +392,7 @@ local function copy_extmarks(bufnr, ctx_bufnr, contexts)
end_col = opts.end_col,
priority = opts.priority,
hl_group = opts.hl_group,
--- @diagnostic disable-next-line:assign-type-mismatch bug in core
end_right_gravity = opts.end_right_gravity,
right_gravity = opts.right_gravity,
hl_eol = opts.hl_eol,
Expand All @@ -393,6 +402,7 @@ local function copy_extmarks(bufnr, ctx_bufnr, contexts)
hl_mode = opts.hl_mode,
line_hl_group = opts.line_hl_group,
spell = opts.spell,
--- @diagnostic disable-next-line:assign-type-mismatch fixed in 0.11
url = opts.url,
}, opts.ns_id)
end
Expand Down

0 comments on commit eb06aa6

Please sign in to comment.