From 099784ef4d53021c5975845ffe385c01269ed45e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 17 Apr 2024 10:22:45 +0100 Subject: [PATCH] test: add luals checking --- .gitignore | 2 ++ .luarc.json | 1 + Makefile | 17 +++++++++++++++++ lua/gitsigns/actions.lua | 4 ++++ lua/gitsigns/cli/argparse.lua | 1 + lua/gitsigns/debug.lua | 1 + lua/gitsigns/hunks.lua | 4 ++-- lua/gitsigns/system.lua | 2 +- 8 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 17729fb..ce49175 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ doc/tags scratch/dummy_ignored.txt +luals + nvim-test stylua diff --git a/.luarc.json b/.luarc.json index 579e521..7f3dbf1 100644 --- a/.luarc.json +++ b/.luarc.json @@ -15,6 +15,7 @@ "checkThirdParty": false }, "diagnostics": { + "libraryFiles": "Disable", "groupFileStatus": { "strict": "Opened", "strong": "Opened", diff --git a/Makefile b/Makefile index d07880c..f3a39cd 100644 --- a/Makefile +++ b/Makefile @@ -75,3 +75,20 @@ build: gen_help stylua-run doc-check: gen_help git diff --exit-code -- doc +LUALS_VERSION := 3.7.4 +LUALS_TARBALL := lua-language-server-$(LUALS_VERSION)-$(shell uname -s)-$(shell uname -m).tar.gz +LUALS_URL := https://github.com/LuaLS/lua-language-server/releases/download/$(LUALS_VERSION)/$(LUALS_TARBALL) + +luals: + wget $(LUALS_URL) + mkdir luals + tar -xf $(LUALS_TARBALL) -C luals + rm -rf $(LUALS_TARBALL) + +.PHONY: luals-check +luals-check: luals nvim-test + VIMRUNTIME=$(XDG_DATA_HOME)/nvim-test/nvim-test-$(NVIM_TEST_VERSION)/share/nvim/runtime \ + lua-language-server \ + --logpath=. \ + --configpath=../.luarc.json \ + --check=lua diff --git a/lua/gitsigns/actions.lua b/lua/gitsigns/actions.lua index 7f5c33b..2dedae0 100644 --- a/lua/gitsigns/actions.lua +++ b/lua/gitsigns/actions.lua @@ -268,6 +268,8 @@ end --- Stage all contiguous hunks. Only useful if 'diff_opts' --- contains `linematch`. Defaults to `true`. M.stage_hunk = mk_repeatable(async.create(2, function(range, opts) + --- @cast range {[1]: integer, [2]: integer}? + opts = opts or {} local bufnr = current_buf() local bcache = cache[bufnr] @@ -334,6 +336,8 @@ end --- Stage all contiguous hunks. Only useful if 'diff_opts' --- contains `linematch`. Defaults to `true`. M.reset_hunk = mk_repeatable(async.create(2, function(range, opts) + --- @cast range {[1]: integer, [2]: integer}? + opts = opts or {} local bufnr = current_buf() local bcache = cache[bufnr] diff --git a/lua/gitsigns/cli/argparse.lua b/lua/gitsigns/cli/argparse.lua index a8d2600..ad52e72 100644 --- a/lua/gitsigns/cli/argparse.lua +++ b/lua/gitsigns/cli/argparse.lua @@ -6,6 +6,7 @@ end -- Return positional arguments and named arguments --- @param x string +--- @return string[], table function M.parse_args(x) --- @type string[], table local pos_args, named_args = {}, {} diff --git a/lua/gitsigns/debug.lua b/lua/gitsigns/debug.lua index a6d6598..05eb5ed 100644 --- a/lua/gitsigns/debug.lua +++ b/lua/gitsigns/debug.lua @@ -6,6 +6,7 @@ local M = {} --- @param path string[] --- @return any local function process(raw_item, path) + --- @diagnostic disable-next-line:undefined-field if path[#path] == vim.inspect.METATABLE then return nil elseif type(raw_item) == 'function' then diff --git a/lua/gitsigns/hunks.lua b/lua/gitsigns/hunks.lua index 3293873..a9b9d19 100644 --- a/lua/gitsigns/hunks.lua +++ b/lua/gitsigns/hunks.lua @@ -255,8 +255,8 @@ function M.create_patch(relpath, hunks, mode_bits, invert) local now_lines = process_hunk.added.lines if invert then - pre_count, now_count = now_count, pre_count - pre_lines, now_lines = now_lines, pre_lines + pre_count, now_count = now_count, pre_count --- @type integer, integer + pre_lines, now_lines = now_lines, pre_lines --- @type string[], string[] end table.insert( diff --git a/lua/gitsigns/system.lua b/lua/gitsigns/system.lua index 8851cf5..e7f47ad 100644 --- a/lua/gitsigns/system.lua +++ b/lua/gitsigns/system.lua @@ -5,7 +5,7 @@ local M = {} local system = vim.system or require('gitsigns.system.compat') --- @param cmd string[] ---- @param opts SystemOpts +--- @param opts vim.SystemOpts --- @param on_exit fun(obj: vim.SystemCompleted) --- @return vim.SystemObj function M.system(cmd, opts, on_exit)