From a330fdb90911266d85503fb68361dd893344cd6a Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Tue, 31 Oct 2023 07:12:04 +0100 Subject: [PATCH] fix(compat): add missing nil checks --- CHANGELOG.md | 5 +++++ lua/rustaceanvim/compat.lua | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4645aa26..062bb136 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.3.1] - 2023-10-31 + +## Fixed +- Neovim 0.9 compatibility layer: Missing `nil` checks [[#32](https://github.com/mrcjkb/rustaceanvim/issues/32)]. + ## [3.3.0] - 2023-10-30 ### Added diff --git a/lua/rustaceanvim/compat.lua b/lua/rustaceanvim/compat.lua index 89596003..f4b45f1a 100644 --- a/lua/rustaceanvim/compat.lua +++ b/lua/rustaceanvim/compat.lua @@ -20,7 +20,10 @@ M.uv = vim.uv or vim.loop M.system = vim.system -- wrapper around vim.fn.system to give it a similar API to vim.system or function(cmd, opts, on_exit) - if opts.cwd then + ---@cast cmd string[] + ---@cast opts SystemOpts | nil + ---@cast on_exit fun(sc: vim.SystemCompleted) | nil + if opts and opts.cwd then local shell = require('rustaceanvim.shell') cmd = shell.chain_commands { 'cd ' .. opts.cwd, table.concat(cmd, ' ') } ---@cast cmd string @@ -35,7 +38,9 @@ M.system = vim.system stderr = not ok and (output or '') or nil, code = vim.v.shell_error, } - on_exit(systemObj) + if on_exit then + on_exit(systemObj) + end return systemObj end