Skip to content

Commit

Permalink
chore: add compatibility layers for neovim API deprecated in nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed May 3, 2024
1 parent 0f3e92d commit 35ac2d9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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.9] - 2024-05-04

### Changed

- Add compatibility layers for Neovim API that has been
deprecated in Neovim nightly.

## [3.1.8] - 2024-02-23

### Reverted
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</strong>
</p>
<p>🦥</p>

[![Neovim][neovim-shield]][neovim-url]
[![Lua][lua-shield]][lua-url]
[![Haskell][haskell-shield]][haskell-url]
Expand Down
16 changes: 8 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@
type-check-nightly = pre-commit-hooks.lib.${system}.run {
src = self;
hooks = {
lua-ls.enable = true;
};
settings = {
lua-ls.config = luarc-nightly;
lua-ls = {
enable = true;
settings.configuration = luarc-nightly;
};
};
};

type-check-stable = pre-commit-hooks.lib.${system}.run {
src = self;
hooks = {
lua-ls.enable = true;
};
settings = {
lua-ls.config = luarc-stable;
lua-ls = {
enable = true;
settings.configuration = luarc-stable;
};
};
};

Expand Down
5 changes: 5 additions & 0 deletions lua/haskell-tools/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ compat.system = vim.system
return systemObj
end

---@type fun(tbl:table):table
compat.tbl_flatten = vim.iter and function(tbl)
return vim.iter(tbl):flatten():totable()
end or vim.tbl_flatten

return compat
4 changes: 2 additions & 2 deletions lua/haskell-tools/hoogle/local.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

local log = require('haskell-tools.log.internal')
local deps = require('haskell-tools.deps')
local compat = require('haskell-tools.compat')

---@class LocalHoogleHandler
local HoogleLocal = {}
Expand Down Expand Up @@ -36,7 +37,7 @@ end
---@return string[] hoogle_args
local function mk_hoogle_args(search_term, opts)
local count = opts.count or 50
local args = vim.tbl_flatten { '--json', '--count=' .. count, search_term }
local args = compat.tbl_flatten { '--json', '--count=' .. count, search_term }
log.debug { 'Hoogle local args', args }
return args
end
Expand All @@ -45,7 +46,6 @@ local pickers = deps.require_telescope('telescope.pickers')
local finders = deps.require_telescope('telescope.finders')
local previewers = deps.require_telescope('telescope.previewers')
local HoogleHelpers = require('haskell-tools.hoogle.helpers')
local compat = require('haskell-tools.compat')

---@param search_term string The Hoogle search term
---@param opts LocalHoogleOpts|nil
Expand Down
4 changes: 2 additions & 2 deletions lua/haskell-tools/project/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end
---@param ... string Search patterns (can be globs)
---@return string|nil The first file that matches the globs
local function find_file(path, ...)
for _, search_term in ipairs(vim.tbl_flatten { ... }) do
for _, search_term in ipairs(compat.tbl_flatten { ... }) do
local results = vim.fn.glob(compat.joinpath(path, search_term), true, true)
if #results > 0 then
return results[1]
Expand Down Expand Up @@ -87,7 +87,7 @@ end
---@param ... string Globs to match in the root directory
---@return fun(path:string):(string|nil)
local function root_pattern(...)
local args = vim.tbl_flatten { ... }
local args = compat.tbl_flatten { ... }
local function matcher(path)
return find_file(path, unpack(args))
end
Expand Down
3 changes: 2 additions & 1 deletion lua/haskell-tools/repl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

local log = require('haskell-tools.log.internal')
local Types = require('haskell-tools.types.internal')
local compat = require('haskell-tools.compat')

---Extend a repl command for `file`.
---If `file` is `nil`, create a repl the nearest package.
Expand Down Expand Up @@ -98,7 +99,7 @@ local function mk_repl_cmd(file)
return mk_stack_repl_cmd(file)
end
if vim.fn.executable('ghci') == 1 then
local cmd = vim.tbl_flatten { 'ghci', file and { file } or {} }
local cmd = compat.tbl_flatten { 'ghci', file and { file } or {} }
log.debug { 'mk_repl_cmd', cmd }
return cmd
end
Expand Down

0 comments on commit 35ac2d9

Please sign in to comment.