Skip to content

Commit a8a9691

Browse files
Marc Jakobimrcjkb
authored andcommitted
ci: use lux for type checking
1 parent d50597d commit a8a9691

11 files changed

Lines changed: 203 additions & 71 deletions

File tree

.github/workflows/tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ jobs:
3939
run: |
4040
lx --nvim test
4141
42-
# TODO: Not stable in Lux yet.
43-
# For now, we use Nix for type checking
44-
# - name: Type checks
45-
# run: |
46-
# lx --nvim check
42+
- name: Type checks
43+
run: |
44+
lx --nvim check --warnings-as-errors
45+
env:
46+
VIMRUNTIME: /home/runner/nvim-stable/share/nvim/runtime
4747

.luarc.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
{
2+
"diagnostics": {
3+
"enable": true,
4+
"disable": [
5+
"annotation-usage-error"
6+
]
7+
},
28
"workspace": {
39
"library": [
410
"$VIMRUNTIME",
511
".lux/5.1/test_dependencies/5.1/01a3c364614bddff7370223a5a9c4580f8e62d144384148444c518ec5367a59b-mediator_lua@1.1.2-0/src",
612
".lux/5.1/test_dependencies/5.1/287e827f4a088d41bba04af5f61a13614346c16fe8150eb7c4246e67d6fd163e-lua-term@0.8-1/src",
713
".lux/5.1/test_dependencies/5.1/316ac0b30e04e86a253d64886f3b110bd0508267474e6b58a3b973bd6857dbf4-penlight@1.14.0-3/src",
14+
".lux/5.1/test_dependencies/5.1/36c63cd0c043eb0fbc7d5ecd75907926b7136414cef7703dcd5784a61e6a728e-nvim-dap@0.10.0-1/src",
815
".lux/5.1/test_dependencies/5.1/455cd98d50c6191a9685cffcda4ce783efbb957934625e134c39f43bd5df6818-luassert@1.9.0-1/src",
916
".lux/5.1/test_dependencies/5.1/47b12edcdc032232157ace97bddf34bddd17f6f458095885e62bbd602ad9e9ec-luasystem@0.6.3-1/src",
1017
".lux/5.1/test_dependencies/5.1/4e9592a499c9ced4f8ce366db9db7d9c0dd1424ea8d4c8c16c1550ea3a61a696-say@1.4.1-3/src",
1118
".lux/5.1/test_dependencies/5.1/56b98be57b1a97b869fd8ded0d2c0b9ce0b6b052e2d5abf84d060748617b2c90-busted@2.2.0-1/src",
1219
".lux/5.1/test_dependencies/5.1/6ce29c2c535c40246c386c056f24689344cddb56ec397473931431e6b67694d2-say@1.4.1-3/src",
1320
".lux/5.1/test_dependencies/5.1/832fd9862ce671c0c9777855d4c8b19f9ad9c2679fb5466c3a183785a51b76b0-luafilesystem@1.8.0-1/src",
1421
".lux/5.1/test_dependencies/5.1/a6c5176043cb3de56336b7de119443dbb3d9e024be1d50e06289ad4b4959a2da-lua_cliargs@3.0.2-1/src",
22+
".lux/5.1/test_dependencies/5.1/acdfde00d122aac481c18c906d483478bb536741beb025becc11782a075d125b-luassert@1.9.0-1/src",
23+
".lux/5.1/test_dependencies/5.1/b54df892b93931d9062f7bb8887a2ae7e6ce116e50d9aca0cf690256d7ac05b6-neotest@5.13.1-1/src",
1524
".lux/5.1/test_dependencies/5.1/d85464dc58c62460a1ecb14e6ac773ae615a66a8224b26ceb25d954c6b05ca74-nlua@0.3.2-1/src",
16-
".lux/5.1/test_dependencies/5.1/e4f17b9e67313bbd5e90f425672fc8998dd0bfa43335f7c57ed2de7a799e07a6-dkjson@2.8-1/src"
25+
".lux/5.1/test_dependencies/5.1/de206edd51dbfc1bbe56869d6729cf4a6e6e70e7b2e107093c0f6520c142d79b-nvim-nio@1.10.1-1/src",
26+
".lux/5.1/test_dependencies/5.1/e4f17b9e67313bbd5e90f425672fc8998dd0bfa43335f7c57ed2de7a799e07a6-dkjson@2.8-1/src",
27+
".lux/5.1/test_dependencies/5.1/e6419c49ea30f1be0576a4def3982181470d4f3961a28360a17aa9396db68ff2-plenary.nvim@scm-1/src"
1728
]
1829
}
1930
}

flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@
148148
pkgs.statix
149149
pkgs.nixd
150150
alejandra
151-
lua-language-server
151+
pkgs.emmylua-ls
152+
# lua-language-server
152153
stylua
153154
editorconfig-checker
154155
markdownlint-cli

lua/rustaceanvim/cargo.lua

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ local function get_cargo_metadata(path, callback)
4747
end)
4848
else
4949
local sc = vim
50-
.system(cmd, {
51-
cwd = vim.uv.fs_stat(path) and path or cargo_crate_dir or vim.fn.getcwd(),
52-
})
53-
:wait()
50+
.system(cmd, {
51+
cwd = vim.uv.fs_stat(path) and path or cargo_crate_dir or vim.fn.getcwd(),
52+
})
53+
:wait()
5454
return on_exit(sc)
5555
end
5656
end
@@ -74,11 +74,11 @@ local function default_get_root_dir(file_name, callback)
7474
---@return string | nil root_dir
7575
local function root_dir(cargo_crate_dir, cargo_metadata)
7676
return cargo_metadata and cargo_metadata.workspace_root
77-
or cargo_crate_dir
78-
or vim.fs.dirname(vim.fs.find({ 'rust-project.json' }, {
79-
upward = true,
80-
path = path,
81-
})[1])
77+
or cargo_crate_dir
78+
or vim.fs.dirname(vim.fs.find({ 'rust-project.json' }, {
79+
upward = true,
80+
path = path,
81+
})[1])
8282
end
8383
if callback then
8484
get_cargo_metadata(path, function(cargo_crate_dir, cargo_metadata)
@@ -107,7 +107,8 @@ local function get_mb_active_client_root(file_name)
107107
item = os.normalize_path_on_windows(item)
108108
if file_name:sub(1, #item) == item then
109109
local clients = rust_analyzer.get_active_rustaceanvim_clients()
110-
return clients and #clients > 0 and clients[#clients].config.root_dir or nil
110+
local client = clients[#clients]
111+
return client and client.config.root_dir or nil
111112
end
112113
end
113114
end

lua/rustaceanvim/commands/diagnostic.lua

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,15 @@ function M.explain_error(cycle_diagnostic)
8585
end
8686

8787
local diagnostics = vim
88-
.iter(vim.diagnostic.get(0, {}))
89-
---@param diagnostic vim.Diagnostic
90-
:filter(function(diagnostic)
91-
return diagnostic.code ~= nil
92-
and diagnostic.source == 'rustc'
93-
and diagnostic.severity == vim.diagnostic.severity.ERROR
94-
end)
95-
:totable()
88+
.iter(vim.diagnostic.get(0, {}))
89+
:filter(
90+
---@param diagnostic vim.Diagnostic
91+
function(diagnostic)
92+
return diagnostic.code ~= nil
93+
and diagnostic.source == 'rustc'
94+
and diagnostic.severity == vim.diagnostic.severity.ERROR
95+
end)
96+
:totable()
9697
if #diagnostics == 0 then
9798
vim.notify('No explainable errors found.', vim.log.levels.INFO)
9899
return
@@ -185,15 +186,15 @@ function M.explain_error_current_line()
185186

186187
-- get matching diagnostics from current line
187188
local diagnostics = vim
188-
.iter(vim.diagnostic.get(0, {
189-
lnum = cursor_position[1] - 1,
190-
}))
191-
:filter(function(diagnostic)
192-
return diagnostic.code ~= nil
193-
and diagnostic.source == 'rustc'
194-
and diagnostic.severity == vim.diagnostic.severity.ERROR
195-
end)
196-
:totable()
189+
.iter(vim.diagnostic.get(0, {
190+
lnum = cursor_position[1] - 1,
191+
}))
192+
:filter(function(diagnostic)
193+
return diagnostic.code ~= nil
194+
and diagnostic.source == 'rustc'
195+
and diagnostic.severity == vim.diagnostic.severity.ERROR
196+
end)
197+
:totable()
197198

198199
-- no matching diagnostics on current line
199200
if #diagnostics == 0 then
@@ -246,7 +247,7 @@ end
246247
local function render_ansi_code_diagnostic(rendered_diagnostic)
247248
-- adopted from https://stackoverflow.com/questions/48948630/lua-ansi-escapes-pattern
248249
local lines =
249-
vim.split(rendered_diagnostic:gsub('[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]', ''), '\n', { trimempty = true })
250+
vim.split(rendered_diagnostic:gsub('[\27\155][][()#;?%d]*[A-PRZcf-ntqry=><~]', ''), '\n', { trimempty = true })
250251
local float_preview_lines = vim.deepcopy(lines)
251252
table.insert(float_preview_lines, 1, '---')
252253
table.insert(float_preview_lines, 1, '1. Open in split')
@@ -298,12 +299,12 @@ local function render_ansi_code_diagnostic(rendered_diagnostic)
298299
vim.api.nvim_feedkeys(
299300
vim.api.nvim_replace_termcodes(
300301
'<cmd>lua vim.api.nvim_set_current_win('
301-
.. winnr
302-
.. ')<CR>'
303-
.. [[<c-\><c-n>]]
304-
.. '<cmd>lua vim.api.nvim_win_set_cursor('
305-
.. winnr
306-
.. ',{1,0})<CR>',
302+
.. winnr
303+
.. ')<CR>'
304+
.. [[<c-\><c-n>]]
305+
.. '<cmd>lua vim.api.nvim_win_set_cursor('
306+
.. winnr
307+
.. ',{1,0})<CR>',
307308
true,
308309
false,
309310
true
@@ -318,12 +319,13 @@ end
318319
---@param cycle_diagnostic (fun(opts?: vim.diagnostic.JumpOpts): vim.Diagnostic?)
319320
function M.render_diagnostic(cycle_diagnostic)
320321
local diagnostics = vim
321-
.iter(vim.diagnostic.get(0, {}))
322-
---@param diagnostic vim.Diagnostic
323-
:filter(function(diagnostic)
324-
return get_rendered_diagnostic(diagnostic) ~= nil
325-
end)
326-
:totable()
322+
.iter(vim.diagnostic.get(0, {}))
323+
:filter(
324+
---@param diagnostic vim.Diagnostic
325+
function(diagnostic)
326+
return get_rendered_diagnostic(diagnostic) ~= nil
327+
end)
328+
:totable()
327329
if #diagnostics == 0 then
328330
vim.notify('No renderable diagnostics found.', vim.log.levels.INFO)
329331
return
@@ -401,12 +403,13 @@ function M.render_diagnostic_current_line()
401403
-- get rendered diagnostics from current line
402404
---@type string[]
403405
local rendered_diagnostics = vim
404-
.iter(get_diagnostics_current_line())
405-
---@param diagnostic vim.Diagnostic
406-
:map(function(diagnostic)
407-
return get_rendered_diagnostic(diagnostic)
408-
end)
409-
:totable()
406+
.iter(get_diagnostics_current_line())
407+
:map(
408+
---@param diagnostic vim.Diagnostic
409+
function(diagnostic)
410+
return get_rendered_diagnostic(diagnostic)
411+
end)
412+
:totable()
410413

411414
-- if no renderable diagnostics on current line
412415
if #rendered_diagnostics == 0 then
@@ -430,17 +433,18 @@ function M.related_diagnostics()
430433
end
431434
---@type lsp.Location[]
432435
local locations = vim
433-
.iter(get_diagnostics_at_cursor())
434-
---@param diagnostic vim.Diagnostic
435-
:map(function(diagnostic)
436-
return vim.tbl_get(diagnostic, 'user_data', 'lsp', 'relatedInformation')
437-
end)
438-
:flatten()
439-
---@param related_info rustaceanvim.diagnostic.RelatedInfo
440-
:map(function(related_info)
441-
return related_info.location
442-
end)
443-
:totable()
436+
.iter(get_diagnostics_at_cursor())
437+
:map(
438+
---@param diagnostic vim.Diagnostic
439+
function(diagnostic)
440+
return vim.tbl_get(diagnostic, 'user_data', 'lsp', 'relatedInformation')
441+
end)
442+
:flatten()
443+
---@param related_info rustaceanvim.diagnostic.RelatedInfo
444+
:map(function(related_info)
445+
return related_info.location
446+
end)
447+
:totable()
444448
if #locations == 0 then
445449
vim.notify('No related diagnostics found.', vim.log.levels.INFO)
446450
return

lua/rustaceanvim/commands/external_docs.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ local M = {}
22

33
function M.open_external_docs()
44
local ra = require('rustaceanvim.rust_analyzer')
5-
local clients = ra.get_active_rustaceanvim_clients(0)
6-
if #clients == 0 then
5+
local client = ra.find_active_rustaceanvim_client(0)
6+
if not client then
77
return
88
end
99
ra.buf_request(
1010
0,
1111
'experimental/externalDocs',
12-
vim.lsp.util.make_position_params(0, clients[1].offset_encoding or 'utf-8'),
12+
vim.lsp.util.make_position_params(0, client.offset_encoding or 'utf-8'),
1313
function(_, response)
1414
local url
1515
if response['local'] and vim.uv.fs_stat(vim.uri_to_fname(response['local'])) then

lua/rustaceanvim/commands/hover_range.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ local function get_visual_selected_range()
5656
return make_lsp_position(row1, math.min(col1, col2), row1, math.max(col1, col2))
5757
end
5858

59-
---@type lsp.Handler
60-
local function handler(_, result, _)
59+
---@param _err lsp.ResponseError?
60+
---@param result unknown
61+
---@param _context lsp.HandlerContext
62+
---@diagnostic disable-next-line: unused-local
63+
local function handler(_err, result, _context)
6164
if not (result and result.contents) then
6265
return
6366
end

lua/rustaceanvim/config/check.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ local M = {}
77
---@param name string Argument name
88
---@param value unknown Argument value
99
---@param validator vim.validate.Validator
10-
--- - (`string|string[]`): Any value that can be returned from |lua-type()| in addition to
10+
--- * (`string|string[]`): Any value that can be returned from |lua-type()| in addition to
1111
--- `'callable'`: `'boolean'`, `'callable'`, `'function'`, `'nil'`, `'number'`, `'string'`, `'table'`,
1212
--- `'thread'`, `'userdata'`.
13-
--- - (`fun(val:any): boolean, string?`) A function that returns a boolean and an optional
13+
--- * (`fun(val:any): boolean, string?`) A function that returns a boolean and an optional
1414
--- string message.
1515
---@param optional? boolean Argument is optional (may be omitted)
1616
---@param message? string message when validation fails

lua/rustaceanvim/rust_analyzer.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ M.get_active_rustaceanvim_clients = function(bufnr, filter)
4848
return clients
4949
end
5050

51+
---@param bufnr number | nil 0 for the current buffer, `nil` for no buffer filter
52+
---@param filter? rustaceanvim.lsp.get_clients.Filter
53+
---@return vim.lsp.Client | nil
54+
M.find_active_rustaceanvim_client = function(bufnr, filter)
55+
return M.get_active_rustaceanvim_clients(bufnr, filter)[1]
56+
end
57+
5158
---@param method string LSP method name
5259
---@param params table|nil Parameters to send to the server
5360
---@param handler? lsp.Handler See |lsp-handler|

0 commit comments

Comments
 (0)