Skip to content

Commit 54e4100

Browse files
committed
ci: add lua ls server check during PR
1 parent 56399db commit 54e4100

File tree

7 files changed

+160
-3
lines changed

7 files changed

+160
-3
lines changed

.github/workflows/stylua.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ on:
88
- 'main'
99
workflow_dispatch:
1010
jobs:
11+
check:
12+
runs-on: ubuntu-24.04
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Setup Neovim stable
19+
uses: rhysd/action-setup-vim@v1
20+
with:
21+
neovim: true
22+
version: 'stable'
23+
24+
- name: Install dependencies
25+
run: |
26+
# homebrew
27+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
28+
/home/linuxbrew/.linuxbrew/bin/brew install lua-language-server
29+
30+
- name: lua language server check
31+
run: |
32+
make check
33+
1134
style:
1235
runs-on: ubuntu-24.04
1336

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ TIMEOUT_MINS := $(shell echo $$((30 * 60 * 1000)))
77
.PHONY: test-sequential
88
.PHONY: test-all
99
.PHONY: test-all-sequential
10+
.PHONY: check
1011

1112
test:
1213
@nvim \
@@ -36,3 +37,10 @@ test-all-sequential:
3637
-u ${TESTS_INIT} \
3738
-c "lua require([[plenary.test_harness]]).test_directory([[tests]], { minimal_init = '"${TESTS_INIT}"', timeout = "${TIMEOUT_MINS}", sequential = true, })"
3839

40+
check:
41+
@nvim \
42+
--headless \
43+
--noplugin \
44+
-u ${TESTS_INIT} \
45+
-c 'quit'
46+
@LUA_LS_CONFIGPATH=scripts/internal/.luarc.json nvim -l scripts/internal/lua_language_server_check.lua

lua/kitty-scrollback/api.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@ M.generate_command_line_editing = function(shell)
285285
},
286286
}
287287

288-
---@type table|string
289288
local config = configs[shell]
290289
if not config then
291-
config = 'no config found for: ' .. shell
290+
vim.notify('no config found for: ' .. shell, vim.log.levels.ERROR, {})
291+
return
292292
end
293293

294294
local bufid = vim.api.nvim_create_buf(true, true)

lua/kitty-scrollback/backport/init.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ local function backport_version()
1010
-- NOTE: copied __tostring from
1111
-- https://github.com/neovim/neovim/blob/1d4ba8c1edba064421b34c1197c3470a09798218/runtime/lua/vim/version.lua#L125
1212

13+
---@nodoc
14+
---@class vim.Version
15+
---@field [1] number
16+
---@field [2] number
17+
---@field [3] number
18+
---@field major number
19+
---@field minor number
20+
---@field patch number
21+
---@field prerelease? string
22+
---@field build? string
1323
local Version = {}
1424
function Version:__tostring()
1525
local ret = table.concat({ self.major, self.minor, self.patch }, '.')
@@ -59,7 +69,10 @@ local function backport_system()
5969
-- NOTE: copied vim.system from
6070
-- https://github.com/neovim/neovim/blob/1d4ba8c1edba064421b34c1197c3470a09798218/runtime/lua/vim/_editor.lua#L143
6171
-- _editor.lua is not checked by validate-backport due to frequent changes and minimal impact to vim.system
62-
---@diagnostic disable-next-line: duplicate-set-field
72+
73+
--- @param cmd (string[]) Command to execute
74+
--- @param opts vim.SystemOpts? Options
75+
---@return vim.SystemObj Object
6376
vim.system = function(cmd, opts, on_exit)
6477
if type(opts) == 'function' then
6578
on_exit = opts

scripts/internal/.luarc.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"diagnostics": {
3+
"globals": [
4+
"vim"
5+
],
6+
},
7+
"workspace": {
8+
"library": [
9+
"../tmp/plenary.nvim/lua",
10+
],
11+
"checkThirdParty": false
12+
},
13+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
local severity_map = {
2+
'\27[31merror:\27[0m',
3+
'\27[33mwarning:\27[0m',
4+
'\27[90minfo:\27[0m',
5+
'\27[36mhint:\27[0m',
6+
}
7+
8+
local lua_language_server = vim.fn.stdpath('data')
9+
.. '/mason/packages/lua-language-server/lua-language-server'
10+
11+
if vim.env.LUA_LS_SERVER then
12+
lua_language_server = vim.env.LUA_LS_SERVER
13+
elseif vim.env.GITHUB_ACTIONS == 'true' then
14+
lua_language_server = [[/home/linuxbrew/.linuxbrew/bin/lua-language-server]]
15+
end
16+
17+
local tmp_dir = (vim.env.TMPDIR or '/tmp/') .. 'lua_ls_report/'
18+
vim.fn.mkdir(tmp_dir, '-p')
19+
local template = tmp_dir .. 'lua_ls_report.XXXXXX'
20+
local _, path_or_errname, err_msg = vim.uv.fs_mkstemp(template)
21+
if err_msg ~= nil or path_or_errname == nil then
22+
vim.print(err_msg or 'mkstemp failed')
23+
os.exit(1)
24+
end
25+
local tmp_path = path_or_errname
26+
27+
local check_command = {
28+
lua_language_server,
29+
'--check',
30+
'.',
31+
'--check_out_path',
32+
tmp_path,
33+
}
34+
35+
if vim.env.LUA_LS_LOGLEVEL then
36+
table.insert(check_command, '--loglevel')
37+
table.insert(check_command, vim.env.LUA_LS_LOGLEVEL)
38+
end
39+
40+
if vim.env.LUA_LS_LOGPATH then
41+
table.insert(check_command, '--logpath')
42+
table.insert(check_command, vim.env.LUA_LS_LOGPATH)
43+
end
44+
45+
if vim.env.LUA_LS_CONFIGPATH then
46+
table.insert(check_command, '--configpath')
47+
table.insert(check_command, vim.env.LUA_LS_CONFIGPATH)
48+
end
49+
50+
local check_command_result = vim.system(check_command):wait()
51+
local ok = check_command_result.code == 0
52+
if not ok then
53+
vim.print(check_command_result)
54+
os.exit(check_command_result.code)
55+
end
56+
57+
local input = vim.fn.readfile(tmp_path)
58+
local diagnostics = vim.json.decode(table.concat(input))
59+
local formatted_diagnostics = {}
60+
for filepath, file_diagnostics in pairs(diagnostics) do
61+
vim.validate('diagnostics', file_diagnostics, vim.islist, 'a list of diagnostics')
62+
local path = filepath:gsub('^file://', ''):gsub('/%./', '/')
63+
for _, v in ipairs(file_diagnostics) do
64+
local item = {
65+
file = path,
66+
message = v.message,
67+
severity = severity_map[v.severity or 1],
68+
line = v.range.start.line + 1,
69+
col = v.range.start.character + 1,
70+
}
71+
table.insert(formatted_diagnostics, item)
72+
end
73+
end
74+
75+
if vim.tbl_isempty(formatted_diagnostics) then
76+
io.write('\27[32m')
77+
io.write(check_command_result.stdout)
78+
io.write('\27[0m')
79+
os.exit(0)
80+
else
81+
io.write('\27[31m')
82+
io.write(check_command_result.stdout)
83+
io.write('\27[0m\n')
84+
for _, v in ipairs(formatted_diagnostics) do
85+
io.write(
86+
('\x1b]8;;file://%s\x1b\\%s\x1b]8;;\x1b\\:%s:%s: %s %s\n'):format(
87+
v.file,
88+
vim.fn.fnamemodify(v.file, ':.'),
89+
v.line,
90+
v.col,
91+
v.severity,
92+
v.message
93+
)
94+
)
95+
end
96+
os.exit(1)
97+
end

tests/minimal_init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local harness = require('plenary.test_harness')
1616

1717
-- HACK: overwrite plenary _find_files_to_run to pass additional arguments to find
1818
-- originally this uses directory as the parameter
19+
---@diagnostic disable-next-line: duplicate-set-field
1920
harness._find_files_to_run = function(directory_and_find_args)
2021
local find_args = {}
2122
local directory
@@ -28,10 +29,12 @@ harness._find_files_to_run = function(directory_and_find_args)
2829
end)
2930

3031
local finder
32+
---@diagnostic disable-next-line: missing-fields
3133
finder = Job:new({
3234
command = 'find',
3335
args = vim.list_extend({ directory, '-type', 'f', '-name', '*_spec.lua' }, find_args),
3436
})
3537

38+
---@diagnostic disable-next-line: param-type-mismatch
3639
return vim.tbl_map(Path.new, finder:sync(vim.env.PLENARY_TEST_TIMEOUT))
3740
end

0 commit comments

Comments
 (0)