Skip to content

Commit 143cea9

Browse files
author
Marc Jakobi
committed
fix: type safety improvements
1 parent e073982 commit 143cea9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+467
-423
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ jobs:
4343
run: |
4444
lx --nvim check --warnings-as-errors
4545
env:
46-
VIMRUNTIME: /home/runner/nvim-stable/share/nvim/runtime
46+
VIMRUNTIME: /home/runner/nvim-${{ matrix.nvim-version }}/share/nvim/runtime
4747

.luarc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"annotation-usage-error"
66
]
77
},
8+
"runtime": {
9+
"version": "Lua 5.1"
10+
},
811
"workspace": {
912
"library": [
1013
"$VIMRUNTIME",

flake.lock

Lines changed: 0 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313

1414
neovim-nightly-overlay.url = "github:nix-community/neovim-nightly-overlay";
1515

16-
gen-luarc = {
17-
url = "github:mrcjkb/nix-gen-luarc-json";
18-
inputs = {
19-
nixpkgs.follows = "nixpkgs";
20-
flake-parts.follows = "flake-parts";
21-
git-hooks.follows = "git-hooks";
22-
};
23-
};
24-
2516
vimcats = {
2617
url = "github:mrcjkb/vimcats";
2718
inputs = {
@@ -37,7 +28,6 @@
3728
nixpkgs,
3829
flake-parts,
3930
git-hooks,
40-
gen-luarc,
4131
vimcats,
4232
...
4333
}: let
@@ -65,53 +55,6 @@
6555

6656
ci-overlay = import ./nix/ci-overlay.nix {inherit neovim-nightly;};
6757

68-
luarc-plugins = with pkgs.lua51Packages;
69-
[
70-
nvim-nio
71-
]
72-
++ (with pkgs.vimPlugins; [
73-
neotest
74-
nvim-dap
75-
]);
76-
77-
luarc-nightly = pkgs.mk-luarc {
78-
nvim = neovim-nightly;
79-
plugins = luarc-plugins;
80-
};
81-
82-
luarc-stable = pkgs.mk-luarc {
83-
nvim = pkgs.neovim-unwrapped;
84-
plugins = luarc-plugins;
85-
disabled-diagnostics = [
86-
"undefined-doc-name"
87-
"undefined-doc-class"
88-
"redundant-parameter"
89-
"invisible"
90-
];
91-
};
92-
93-
type-check-nightly = git-hooks.lib.${system}.run {
94-
src = self;
95-
hooks = {
96-
lua-ls = {
97-
enable = true;
98-
settings.configuration = luarc-nightly;
99-
};
100-
};
101-
};
102-
103-
type-check-stable = git-hooks.lib.${system}.run {
104-
src = self;
105-
hooks = {
106-
lua-ls = {
107-
enable = true;
108-
settings = {
109-
configuration = luarc-stable;
110-
};
111-
};
112-
};
113-
};
114-
11558
pre-commit-check = git-hooks.lib.${system}.run {
11659
src = self;
11760
hooks = {
@@ -143,13 +86,15 @@
14386
shellHook = ''
14487
${pre-commit-check.shellHook}
14588
'';
89+
env = {
90+
EMMYLUALS_CONFIG = ".luarc.json";
91+
};
14692
buildInputs = with git-hooks.packages.${system}; [
14793
pkgs.lux-cli
14894
pkgs.statix
14995
pkgs.nixd
150-
alejandra
15196
pkgs.emmylua-ls
152-
# lua-language-server
97+
alejandra
15398
stylua
15499
editorconfig-checker
155100
markdownlint-cli
@@ -163,7 +108,6 @@
163108
inherit system;
164109
overlays = [
165110
ci-overlay
166-
gen-luarc.overlays.default
167111
plugin-overlay
168112
];
169113
};
@@ -186,10 +130,6 @@
186130

187131
checks = {
188132
formatting = pre-commit-check;
189-
inherit
190-
type-check-stable
191-
type-check-nightly
192-
;
193133
};
194134
};
195135
flake = {

lua/rustaceanvim/cache.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ store-success-output = true
1111

1212
---@return string path to nextest.toml file
1313
function M.nextest_config_path()
14-
local cache_dir = vim.fs.joinpath(vim.fn.stdpath('cache'), 'rustaceanvim')
15-
local config_path = vim.fs.joinpath(cache_dir, 'nextest_1.toml')
14+
local nvim_cache_dir = vim.fn.stdpath('cache') ---@as string
15+
local rustaceanvim_cache_dir = vim.fs.joinpath(nvim_cache_dir, 'rustaceanvim')
16+
local config_path = vim.fs.joinpath(rustaceanvim_cache_dir, 'nextest_1.toml')
1617

1718
-- Check if file already exists
1819
local stat = vim.uv.fs_stat(config_path)
@@ -21,7 +22,7 @@ function M.nextest_config_path()
2122
end
2223

2324
-- Create cache directory if it doesn't exist
24-
vim.fn.mkdir(cache_dir, 'p')
25+
vim.fn.mkdir(rustaceanvim_cache_dir, 'p')
2526

2627
-- Write the config file
2728
local file = io.open(config_path, 'w')

lua/rustaceanvim/cached_commands.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ local M = {}
66
local cache = {
77
---@type rustaceanvim.RARunnableArgs | nil
88
last_debuggable = nil,
9-
---@type rustaceanvim.RARunnablesChoice
9+
---@type rustaceanvim.RARunnablesChoice | nil
1010
last_runnable = nil,
11-
---@type rustaceanvim.RARunnablesChoice
11+
---@type rustaceanvim.RARunnablesChoice | nil
1212
last_testable = nil,
1313
}
1414

@@ -54,8 +54,9 @@ end
5454
---@param choice rustaceanvim.RARunnablesChoice
5555
---@param executableArgsOverride? string[]
5656
local function override_executable_args_if_set(choice, executableArgsOverride)
57-
if type(executableArgsOverride) == 'table' and #executableArgsOverride > 0 then
58-
choice.runnables[choice.choice].args.executableArgs = executableArgsOverride
57+
local runnable = choice.runnables[choice.choice]
58+
if type(executableArgsOverride) == 'table' and #executableArgsOverride > 0 and runnable then
59+
runnable.args.executableArgs = executableArgsOverride
5960
end
6061
end
6162

lua/rustaceanvim/cargo.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ local function get_cargo_metadata(path, callback)
2828
return callback and callback(cargo_crate_dir) or cargo_crate_dir
2929
end
3030
local ok, cargo_metadata_json = pcall(vim.fn.json_decode, sc.stdout)
31-
if ok and cargo_metadata_json then
31+
if ok and type(cargo_metadata_json) == 'table' then
3232
return callback and callback(cargo_crate_dir, cargo_metadata_json) or cargo_crate_dir, cargo_metadata_json
3333
else
3434
vim.notify(
@@ -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)

0 commit comments

Comments
 (0)