From 093909dd663ece831320feb08a76dc44dc07a6dd Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Sat, 28 Oct 2023 11:55:53 +0200 Subject: [PATCH 1/4] fix(explain-error): compatibility layer for vim.system --- lua/rustaceanvim/commands/explain_error.lua | 4 +++- lua/rustaceanvim/compat.lua | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lua/rustaceanvim/commands/explain_error.lua b/lua/rustaceanvim/commands/explain_error.lua index d1e9626f..eed513be 100644 --- a/lua/rustaceanvim/commands/explain_error.lua +++ b/lua/rustaceanvim/commands/explain_error.lua @@ -1,5 +1,7 @@ local M = {} +local compat = require('rustaceanvim.compat') + local rustc = 'rustc' function M.explain_error() @@ -64,7 +66,7 @@ function M.explain_error() vim.api.nvim_win_set_cursor(win_id, { diagnostic.lnum + 1, diagnostic.col }) -- Open folds under the cursor vim.cmd('normal! zv') - vim.system({ rustc, '--explain', diagnostic.code }, nil, vim.schedule_wrap(handler)) + compat.system({ rustc, '--explain', diagnostic.code }, nil, vim.schedule_wrap(handler)) end return M.explain_error diff --git a/lua/rustaceanvim/compat.lua b/lua/rustaceanvim/compat.lua index 23a2147c..7e37dbe7 100644 --- a/lua/rustaceanvim/compat.lua +++ b/lua/rustaceanvim/compat.lua @@ -11,4 +11,20 @@ M.get_clients = vim.lsp.get_clients or vim.lsp.get_active_clients M.uv = vim.uv or vim.loop +M.system = vim.system + -- wrapper around vim.fn.system to give it a similar API as vim.system + or function(cmd, _, on_exit) + local output = vim.fn.system(cmd) + local ok = vim.v.shell_error + ---@type vim.SystemCompleted + local systemObj = { + signal = 0, + stdout = ok and (output or '') or nil, + stderr = not ok and (output or '') or nil, + code = vim.v.shell_error, + } + on_exit(systemObj) + return systemObj + end + return M From fadb76ec886f4f15554f9b19c27138a9ce4b2620 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Sat, 28 Oct 2023 12:07:08 +0200 Subject: [PATCH 2/4] ci: add type-checking for neovim stable --- flake.nix | 83 ++++++++++++++++++++++++------------- lua/rustaceanvim/compat.lua | 8 +++- 2 files changed, 62 insertions(+), 29 deletions(-) diff --git a/flake.nix b/flake.nix index b425bf61..4d006222 100755 --- a/flake.nix +++ b/flake.nix @@ -65,38 +65,62 @@ ]; }; - type-check = pre-commit-hooks.lib.${system}.run { - src = self; - hooks = { - lua-ls.enable = true; - }; - settings = { - lua-ls = { - config = { - runtime.version = "LuaJIT"; - Lua = { - workspace = { - library = [ - "${pkgs.neovim-nightly}/share/nvim/runtime/lua" - "${pkgs.neodev-plugin}/types/nightly" - # "${pkgs.luajitPackages.busted}" - ]; - checkThirdParty = false; - ignoreDir = [ - ".git" - ".github" - ".direnv" - "result" - "nix" - "doc" - "spec" # FIXME: Add busted library - ]; + mkTypeCheck = { + rtp ? [], + disabled-diagnostics ? [], + }: + pre-commit-hooks.lib.${system}.run { + src = self; + hooks = { + lua-ls.enable = true; + }; + settings = { + lua-ls = { + config = { + runtime.version = "LuaJIT"; + Lua = { + workspace = { + library = rtp; + checkThirdParty = false; + ignoreDir = [ + ".git" + ".github" + ".direnv" + "result" + "nix" + "doc" + "spec" # FIXME: Add busted library + ]; + }; + diagnostics = { + libraryFiles = "Disable"; + disable = disabled-diagnostics; + }; }; - diagnostics. libraryFiles = "Disable"; }; }; }; }; + + type-check-stable = mkTypeCheck { + rtp = [ + "${pkgs.neovim}/share/nvim/runtime/lua" + "${pkgs.neodev-plugin}/types/stable" + # "${pkgs.luajitPackages.busted}" + ]; + disabled-diagnostics = [ + "undefined-doc-name" + "redundant-parameter" + "invisible" + ]; + }; + + type-check-nightly = mkTypeCheck { + rtp = [ + "${pkgs.neovim-nightly}/share/nvim/runtime/lua" + "${pkgs.neodev-plugin}/types/nightly" + # "${pkgs.luajitPackages.busted}" + ]; }; pre-commit-check = pre-commit-hooks.lib.${system}.run { @@ -143,7 +167,10 @@ checks = { formatting = pre-commit-check; - inherit type-check; + inherit + type-check-stable + type-check-nightly + ; inherit (pkgs) nvim-stable-tests diff --git a/lua/rustaceanvim/compat.lua b/lua/rustaceanvim/compat.lua index 7e37dbe7..4b656388 100644 --- a/lua/rustaceanvim/compat.lua +++ b/lua/rustaceanvim/compat.lua @@ -1,4 +1,4 @@ ----@diagnostic disable: deprecated +---@diagnostic disable: deprecated, duplicate-doc-field ---@mod rustaceanvim.compat Functions for backward compatibility with older Neovim versions local M = {} @@ -11,6 +11,12 @@ M.get_clients = vim.lsp.get_clients or vim.lsp.get_active_clients M.uv = vim.uv or vim.loop +--- @class vim.SystemCompleted +--- @field code integer +--- @field signal integer +--- @field stdout? string +--- @field stderr? string + M.system = vim.system -- wrapper around vim.fn.system to give it a similar API as vim.system or function(cmd, _, on_exit) From 7e0364c32bb5f55a376e98a4258fab26a463d875 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Sat, 28 Oct 2023 12:14:00 +0200 Subject: [PATCH 3/4] fix: compatibility layer for vim.list_contains --- lua/rustaceanvim/commands/crate_graph.lua | 3 ++- lua/rustaceanvim/compat.lua | 11 +++++++++++ lua/rustaceanvim/dap.lua | 11 ++++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lua/rustaceanvim/commands/crate_graph.lua b/lua/rustaceanvim/commands/crate_graph.lua index 7f02a281..de31be96 100644 --- a/lua/rustaceanvim/commands/crate_graph.lua +++ b/lua/rustaceanvim/commands/crate_graph.lua @@ -1,4 +1,5 @@ local config = require('rustaceanvim.config.internal') +local compat = require('rustaceanvim.compat') local M = {} @@ -32,7 +33,7 @@ local function handler_factory(backend, output, pipe) vim.notify('no crate graph backend specified.', vim.log.levels.ERROR) return end - if not vim.list_contains(config.tools.crate_graph.enabled_graphviz_backends, backend) then + if not compat.list_contains(config.tools.crate_graph.enabled_graphviz_backends, backend) then vim.notify('crate graph backend not recognized as valid: ' .. vim.inspect(backend), vim.log.levels.ERROR) return end diff --git a/lua/rustaceanvim/compat.lua b/lua/rustaceanvim/compat.lua index 4b656388..9118e6a0 100644 --- a/lua/rustaceanvim/compat.lua +++ b/lua/rustaceanvim/compat.lua @@ -33,4 +33,15 @@ M.system = vim.system return systemObj end +M.list_contains = vim.list_contains + or function(t, value) + vim.validate { t = { t, 't' } } + for _, v in ipairs(t) do + if v == value then + return true + end + end + return false + end + return M diff --git a/lua/rustaceanvim/dap.lua b/lua/rustaceanvim/dap.lua index dfc4e3f0..682a778e 100644 --- a/lua/rustaceanvim/dap.lua +++ b/lua/rustaceanvim/dap.lua @@ -1,4 +1,5 @@ local config = require('rustaceanvim.config.internal') +local compat = require('rustaceanvim.compat') local function scheduled_error(err) vim.schedule(function() @@ -43,12 +44,12 @@ local function get_cargo_args_from_runnables_args(runnable_args) local cargo_args = runnable_args.cargoArgs local message_json = '--message-format=json' - if not vim.list_contains(cargo_args, message_json) then + if not compat.list_contains(cargo_args, message_json) then table.insert(cargo_args, message_json) end for _, value in ipairs(runnable_args.cargoExtraArgs) do - if not vim.list_contains(cargo_args, value) then + if not compat.list_contains(cargo_args, value) then table.insert(cargo_args, value) end end @@ -91,10 +92,10 @@ function M.start(args) goto loop_end end - local is_binary = vim.list_contains(artifact.target.crate_types, 'bin') - local is_build_script = vim.list_contains(artifact.target.kind, 'custom-build') + local is_binary = compat.list_contains(artifact.target.crate_types, 'bin') + local is_build_script = compat.list_contains(artifact.target.kind, 'custom-build') local is_test = ((artifact.profile.test == true) and (artifact.executable ~= nil)) - or vim.list_contains(artifact.target.kind, 'test') + or compat.list_contains(artifact.target.kind, 'test') -- only add executable to the list if we want a binary debug and it is a binary -- or if we want a test debug and it is a test if From 14b9beaafb06885c6747033ee0453988a7fb8614 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Sat, 28 Oct 2023 12:16:16 +0200 Subject: [PATCH 4/4] docs(changelog): update --- CHANGELOG.md | 5 +++++ lua/rustaceanvim/compat.lua | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4320c76..06fe2172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.1.1] - 2023-10-28 +### Fixed +- Remove accidental use of Neovim nightly API (`dap`, `crateGraph`, `explainError`) [[#26](https://github.com/mrcjkb/rustaceanvim/issues/26)]. +- Add static type checking for Neovim stable API. + ## [3.1.0] - 2023-10-28 ### Added - `:RustLsp explainError` command, uses `rustc --explain` on error diagnostics with diff --git a/lua/rustaceanvim/compat.lua b/lua/rustaceanvim/compat.lua index 9118e6a0..abf14b3a 100644 --- a/lua/rustaceanvim/compat.lua +++ b/lua/rustaceanvim/compat.lua @@ -18,7 +18,7 @@ M.uv = vim.uv or vim.loop --- @field stderr? string M.system = vim.system - -- wrapper around vim.fn.system to give it a similar API as vim.system + -- wrapper around vim.fn.system to give it a similar API to vim.system or function(cmd, _, on_exit) local output = vim.fn.system(cmd) local ok = vim.v.shell_error