Skip to content

Commit f6b982e

Browse files
authored
ci: add lua ls server check during PR (#304)
* ci: add lua ls server check during PR * chore: add more descriptive message for jobstart nightly error
1 parent 56399db commit f6b982e

File tree

9 files changed

+248
-9
lines changed

9 files changed

+248
-9
lines changed
Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: stylua
1+
name: static
22
on:
33
push:
44
branches:
@@ -8,28 +8,53 @@ on:
88
- 'main'
99
workflow_dispatch:
1010
jobs:
11-
style:
11+
lua_language_server_check:
1212
runs-on: ubuntu-24.04
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Setup Neovim stable
17+
uses: rhysd/action-setup-vim@v1
18+
with:
19+
neovim: true
20+
version: 'stable'
21+
22+
- name: Install dependencies
23+
run: |
24+
mkdir -p "$GITHUB_WORKSPACE/tmp/lua_language_server"
25+
version=$(curl -sI 'https://github.com/LuaLS/lua-language-server/releases/latest' | grep 'location: https://github.com/LuaLS/lua-language-server/releases/tag/' | awk -F/ '{print $NF}' | tr -d '\r\n')
26+
curl -sL -o "$GITHUB_WORKSPACE/tmp/lua_language_server/lua-language-server.tar.gz" "https://github.com/LuaLS/lua-language-server/releases/download/$version/lua-language-server-$version-linux-x64.tar.gz"
27+
cd "$GITHUB_WORKSPACE/tmp/lua_language_server"
28+
tar -xvf lua-language-server.tar.gz
29+
30+
- name: lua language server check
31+
run: |
32+
make check
1333
34+
style:
35+
needs: lua_language_server_check
36+
runs-on: ubuntu-24.04
1437
permissions:
1538
contents: write
16-
1739
steps:
1840
- uses: actions/checkout@v3
41+
1942
- name: checkstylua
2043
uses: JohnnyMorganz/stylua-action@v3
2144
continue-on-error: true
2245
with:
2346
token: ${{ secrets.GITHUB_TOKEN }}
2447
version: latest
2548
args: --check .
49+
2650
- name: formatstylua
2751
if: ${{ steps.checkstylua.outcome != 'success' }}
2852
uses: JohnnyMorganz/stylua-action@v2
2953
with:
3054
token: ${{ secrets.GITHUB_TOKEN }}
3155
version: latest
3256
args: .
57+
3358
- uses: stefanzweifel/git-auto-commit-action@v4
3459
if: ${{ steps.checkstylua.outcome != 'success' }}
3560
with:
@@ -39,4 +64,3 @@ jobs:
3964
commit_user_email: "github-actions[bot]@users.noreply.github.com"
4065
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
4166

42-

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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---@diagnostic disable: duplicate-set-field, duplicate-doc-field
12
---@mod kitty-scrollback.backport
23
-- NOTE(#58): nvim v0.9 support
34

@@ -10,6 +11,16 @@ local function backport_version()
1011
-- NOTE: copied __tostring from
1112
-- https://github.com/neovim/neovim/blob/1d4ba8c1edba064421b34c1197c3470a09798218/runtime/lua/vim/version.lua#L125
1213

14+
---@nodoc
15+
---@class vim.Version
16+
---@field [1] number
17+
---@field [2] number
18+
---@field [3] number
19+
---@field major number
20+
---@field minor number
21+
---@field patch number
22+
---@field prerelease? string
23+
---@field build? string
1324
local Version = {}
1425
function Version:__tostring()
1526
local ret = table.concat({ self.major, self.minor, self.patch }, '.')
@@ -59,7 +70,10 @@ local function backport_system()
5970
-- NOTE: copied vim.system from
6071
-- https://github.com/neovim/neovim/blob/1d4ba8c1edba064421b34c1197c3470a09798218/runtime/lua/vim/_editor.lua#L143
6172
-- _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
73+
74+
---@param cmd (string[]) Command to execute
75+
---@param opts vim.SystemOpts? Options
76+
---@return vim.SystemObj Object
6377
vim.system = function(cmd, opts, on_exit)
6478
if type(opts) == 'function' then
6579
on_exit = opts

lua/kitty-scrollback/launch.lua

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,36 @@ M.launch = function()
421421
.. [[. Most likely `]]
422422
.. ksb_kitty_cmds.open_term_command
423423
.. [[` failed. ]],
424-
[[ Please report the issue at https://github.com/mikesmithgh/kitty-scrollback.nvim/issues]],
425-
[[ and provide the `KittyScrollbackCheckHealth` report.]],
424+
[[]],
425+
[[ If you are using Neovim nightly (NVIM v0.11), then you may need to update to the latest]],
426+
[[ version of nightly. Please try updating Neovim to the latest version of nightly. If]],
427+
[[ this error still occurs, then see if any additional help has been provided on the issue]],
428+
[[ https://github.com/mikesmithgh/kitty-scrollback.nvim/issues/303.]],
429+
[[]],
430+
[[ If you are unable to update to a newer version of Neovim nightly, you can workaround ]],
431+
[[ the problem by pinning kitty-scrollback.nvim to `v6.1.2`.]],
432+
[[ ]],
433+
[[ For example, if you are using lazy.nvim]],
434+
[[>lua]],
435+
[[ return {]],
436+
[[ {]],
437+
[[ 'mikesmithgh/kitty-scrollback.nvim',]],
438+
[[ tag = 'v6.1.2',]],
439+
[[ enabled = true,]],
440+
[[ lazy = true,]],
441+
[[ cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth', 'KittyScrollbackGenerateCommandLineEditing' },]],
442+
[[ event = { 'User KittyScrollbackLaunch' },]],
443+
[[ -- version = '*', -- latest stable version, may have breaking changes if major version changed]],
444+
[[ -- version = '^6.0.0', -- pin major version, include fixes and features that do not have breaking changes]],
445+
[[ config = function()]],
446+
[[ require('kitty-scrollback').setup()]],
447+
[[ end,]],
448+
[[ },]],
449+
[[ }]],
450+
[[<]],
451+
[[ If this is unrelated to issue #303, then create a new issue at ]],
452+
[[ https://github.com/mikesmithgh/kitty-scrollback.nvim/issues and provide the ]],
453+
[[ `KittyScrollbackCheckHealth` report.]],
426454
})
427455
ksb_api.close_kitty_loading_window()
428456
if block_input_timer then

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+
}

scripts/internal/__branch-protection-rules.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"required_status_checks": {
33
"strict": true,
44
"contexts": [
5+
"lua_language_server_check",
56
"style",
67
"codespell",
78
"plenary (stable, stable)",
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
local uv = vim.uv
2+
local ci_build = vim.env.CI == 'true' or vim.env.GITHUB_ACTIONS == 'true'
3+
4+
local severity_type = {
5+
{ color = 31, text = 'error' },
6+
{ color = 33, text = 'warning' },
7+
{ color = 90, text = 'info' },
8+
{ color = 36, text = 'hint' },
9+
}
10+
11+
local function lua_language_server_executable()
12+
local lua_language_server
13+
if vim.env.LUA_LS_SERVER then
14+
lua_language_server = vim.env.LUA_LS_SERVER
15+
if vim.fn.executable(lua_language_server) == 0 then
16+
io.write(('LUS_LS_SERVER %s not found or not executable\n'):format(lua_language_server))
17+
os.exit(1)
18+
end
19+
else
20+
lua_language_server = vim.fn.exepath('lua-language-server')
21+
end
22+
23+
if lua_language_server == '' or vim.fn.executable(lua_language_server) == 0 then
24+
if ci_build then
25+
lua_language_server = vim.env.GITHUB_WORKSPACE
26+
.. [[/tmp/lua_language_server/bin/lua-language-server]]
27+
io.write(
28+
('lua-language-server not found or not executable. CI build detected, falling back to %s\n'):format(
29+
lua_language_server
30+
)
31+
)
32+
elseif lua_language_server == '' then
33+
lua_language_server = vim.fn.stdpath('data')
34+
.. '/mason/packages/lua-language-server/lua-language-server'
35+
io.write(
36+
('lua-language-server not found or not executable. falling back to %s\n'):format(
37+
lua_language_server
38+
)
39+
)
40+
end
41+
end
42+
43+
if vim.fn.executable(lua_language_server) == 0 then
44+
io.write(('%s not found or not executable\n'):format(lua_language_server))
45+
os.exit(1)
46+
end
47+
return lua_language_server
48+
end
49+
50+
local function tmpfile()
51+
local tmp_dir = (vim.env.TMPDIR or '/tmp/') .. 'lua_ls_report/'
52+
vim.fn.mkdir(tmp_dir, '-p')
53+
local template = tmp_dir .. 'lua_ls_report.XXXXXX'
54+
local _, path_or_errname, err_msg = uv.fs_mkstemp(template)
55+
if err_msg ~= nil or path_or_errname == nil then
56+
io.write(('%s\n'):format(err_msg or 'mkstemp failed'))
57+
os.exit(1)
58+
end
59+
return path_or_errname
60+
end
61+
62+
local function check_command(lua_language_server, tmp_path)
63+
local command = {
64+
lua_language_server,
65+
'--check',
66+
'.',
67+
'--check_out_path',
68+
tmp_path,
69+
}
70+
71+
if vim.env.LUA_LS_LOGLEVEL then
72+
table.insert(command, '--loglevel')
73+
table.insert(command, vim.env.LUA_LS_LOGLEVEL)
74+
end
75+
76+
if vim.env.LUA_LS_LOGPATH then
77+
table.insert(command, '--logpath')
78+
table.insert(command, vim.env.LUA_LS_LOGPATH)
79+
end
80+
81+
if vim.env.LUA_LS_CONFIGPATH then
82+
table.insert(command, '--configpath')
83+
table.insert(command, vim.env.LUA_LS_CONFIGPATH)
84+
end
85+
return command
86+
end
87+
88+
local lua_language_server = lua_language_server_executable()
89+
local tmp_path = tmpfile()
90+
local command = check_command(lua_language_server, tmp_path)
91+
local check_command_result = vim.system(command):wait()
92+
local ok = check_command_result.code == 0
93+
if not ok then
94+
io.write(('%s\n'):format(vim.inspect(check_command_result)))
95+
os.exit(check_command_result.code)
96+
end
97+
98+
local input = vim.fn.readfile(tmp_path)
99+
local diagnostics = vim.json.decode(table.concat(input))
100+
local formatted_diagnostics = {}
101+
for filepath, file_diagnostics in pairs(diagnostics) do
102+
local path = filepath:gsub('^file://', ''):gsub('/%./', '/')
103+
for _, v in ipairs(file_diagnostics) do
104+
local item = {
105+
file = path,
106+
message = v.message,
107+
severity = v.severity or 1,
108+
line = v.range.start.line + 1,
109+
col = v.range.start.character + 1,
110+
}
111+
table.insert(formatted_diagnostics, item)
112+
end
113+
end
114+
115+
if vim.tbl_isempty(formatted_diagnostics) then
116+
io.write(('%s'):format(check_command_result.stdout))
117+
os.exit(0)
118+
else
119+
for _, v in ipairs(formatted_diagnostics) do
120+
if ci_build then
121+
io.write(
122+
('%s:%s:%s %s %s\n'):format(
123+
vim.fn.fnamemodify(v.file, ':.'),
124+
v.line,
125+
v.col,
126+
('%s:'):format(severity_type[v.severity].text),
127+
v.message
128+
)
129+
)
130+
else
131+
io.write(
132+
('\x1b]8;;file://%s\x1b\\%s\x1b]8;;\x1b\\:%s:%s %s %s\n'):format(
133+
v.file,
134+
vim.fn.fnamemodify(v.file, ':.'),
135+
v.line,
136+
v.col,
137+
('\x1b[%sm%s:\x1b[0m'):format(
138+
severity_type[v.severity].color,
139+
severity_type[v.severity].text
140+
),
141+
v.message
142+
)
143+
)
144+
end
145+
end
146+
io.write(('%s'):format(check_command_result.stdout))
147+
os.exit(1)
148+
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)