drop support for nvim-0.5, 0.6 (BREAKING) (#1002)

* chore: drop support for nvim-0.5, 0.6 (BREAKING)

Users of these versions can still use compatibility tags
compat-nvim-0.5 and compat-nvim-0.6 respectively.

BREAKING CHANGE

* add testing for 0.9
This commit is contained in:
Shadman 2023-10-18 11:00:32 +06:00 committed by GitHub
parent c55af3b39c
commit 343e1941ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 144 deletions

View File

@ -19,14 +19,6 @@ jobs:
fail-fast: false
matrix:
include:
- flavor: nvim-0.5
runner: ubuntu-20.04
os: linux
nvim_version: v0.5.0
- flavor: nvim-0.6
runner: ubuntu-20.04
os: linux
nvim_version: v0.6.0
- flavor: nvim-0.7
runner: ubuntu-20.04
os: linux
@ -35,6 +27,10 @@ jobs:
runner: ubuntu-20.04
os: linux
nvim_version: v0.8.0
- flavor: nvim-0.9
runner: ubuntu-20.04
os: linux
nvim_version: v0.9.0
- flavor: nvim-nightly
runner: ubuntu-20.04
os: linux

View File

@ -9,7 +9,10 @@
A blazing fast and easy to configure Neovim statusline written in Lua.
`lualine.nvim` requires Neovim >= 0.5.
`lualine.nvim` requires Neovim >= 0.7.
For previous versoins of neovim please use compatability tags for example
compat-nvim-0.5
## Contributing

View File

@ -27,10 +27,7 @@ local refresh_real_curwin
-- The events on which lualine redraws itself
local default_refresh_events =
'WinEnter,BufEnter,SessionLoadPost,FileChangedShellPost,VimResized,Filetype,CursorMoved,CursorMovedI'
if vim.fn.has('nvim-0.7') == 1 then -- utilize ModeChanged event introduced in 0.7
default_refresh_events = default_refresh_events .. ',ModeChanged'
end
'WinEnter,BufEnter,SessionLoadPost,FileChangedShellPost,VimResized,Filetype,CursorMoved,CursorMovedI,ModeChanged'
-- Helper for apply_transitional_separators()
--- finds first applied highlight group after str_checked in status
---@param status string : unprocessed statusline string
@ -602,6 +599,20 @@ local function hide(opts)
end
end
--- Check neovim compatibilitu
local function verify_nvim_version()
if vim.fn.has('nvim-0.7') == 1 then return true end
modules.utils_notices.add_notice([[
### Incompatible Neovim version
Lualine supports neovim 0.7 and up. It seems you're using a older version.
Please update to newer version. Or if you have atleast neovim 0.5 you
can use older compatible versions of lualine using compat tags like
`compat-nvim-0.5`, `compat-nvim-0.6`.
]]
)
return false
end
-- lualine.setup function
--- sets new user config
--- This function doesn't load components/theme etc... They are done before
@ -616,14 +627,16 @@ local function setup(user_config)
-- When notices module is not loaded there are no notices to clear.
modules.utils_notices.clear_notices()
end
config = modules.config_module.apply_configuration(user_config)
vim.cmd([[augroup lualine | exe "autocmd!" | augroup END]])
setup_theme()
-- load components & extensions
modules.loader.load_all(config)
set_statusline()
set_tabline()
set_winbar()
if verify_nvim_version() then
config = modules.config_module.apply_configuration(user_config)
vim.cmd([[augroup lualine | exe "autocmd!" | augroup END]])
setup_theme()
-- load components & extensions
modules.loader.load_all(config)
set_statusline()
set_tabline()
set_winbar()
end
if package.loaded['lualine.utils.notices'] then
modules.utils_notices.notice_message_startup()
end

View File

@ -18,7 +18,7 @@ M.options = {
colored = true,
update_in_insert = false,
always_visible = false,
sources = { vim.fn.has('nvim-0.6') == 1 and 'nvim_diagnostic' or 'nvim_lsp', 'coc' },
sources = { 'nvim_diagnostic', 'coc' },
sections = { 'error', 'warn', 'info', 'hint' },
}

View File

@ -6,28 +6,17 @@ local M = {}
M.sources = {
nvim_lsp = function()
local error_count, warning_count, info_count, hint_count
if vim.fn.has('nvim-0.6') == 1 then
-- On nvim 0.6+ use vim.diagnostic to get lsp generated diagnostic count.
local diagnostics = vim.diagnostic.get(0)
local count = { 0, 0, 0, 0 }
for _, diagnostic in ipairs(diagnostics) do
if vim.startswith(vim.diagnostic.get_namespace(diagnostic.namespace).name, 'vim.lsp') then
count[diagnostic.severity] = count[diagnostic.severity] + 1
end
local diagnostics = vim.diagnostic.get(0)
local count = { 0, 0, 0, 0 }
for _, diagnostic in ipairs(diagnostics) do
if vim.startswith(vim.diagnostic.get_namespace(diagnostic.namespace).name, 'vim.lsp') then
count[diagnostic.severity] = count[diagnostic.severity] + 1
end
error_count = count[vim.diagnostic.severity.ERROR]
warning_count = count[vim.diagnostic.severity.WARN]
info_count = count[vim.diagnostic.severity.INFO]
hint_count = count[vim.diagnostic.severity.HINT]
else
-- On 0.5 use older vim.lsp.diagnostic module.
-- Maybe we should phase out support for 0.5 though I haven't yet found a solid reason to.
-- Eventually this will be removed when 0.5 is no longer supported.
error_count = vim.lsp.diagnostic.get_count(0, 'Error')
warning_count = vim.lsp.diagnostic.get_count(0, 'Warning')
info_count = vim.lsp.diagnostic.get_count(0, 'Information')
hint_count = vim.lsp.diagnostic.get_count(0, 'Hint')
end
error_count = count[vim.diagnostic.severity.ERROR]
warning_count = count[vim.diagnostic.severity.WARN]
info_count = count[vim.diagnostic.severity.INFO]
hint_count = count[vim.diagnostic.severity.HINT]
return error_count, warning_count, info_count, hint_count
end,
nvim_workspace_diagnostic = function()

View File

@ -103,12 +103,6 @@ local function apply_configuration(config_table)
end
end
end
if config_table.options and config_table.options.globalstatus and vim.fn.has('nvim-0.7') == 0 then
modules.utils_notices.add_notice(
'### Options.globalstatus\nSorry `globalstatus` option can only be used in neovim 0.7 or higher.\n'
)
config_table.options.globalstatus = false
end
if vim.fn.has('nvim-0.8') == 0 and (next(config_table.winbar or {}) or next(config_table.inactive_winbar or {})) then
modules.utils_notices.add_notice('### winbar\nSorry `winbar can only be used in neovim 0.8 or higher.\n')
config_table.winbar = {}

View File

@ -71,109 +71,17 @@
--- statusline:snapshot()
--- ```
local ffi = require('ffi')
local helpers = require('tests.helpers')
local stub = require('luassert.stub')
local M = {}
ffi.cdef([[
typedef unsigned char char_u;
typedef struct window_S win_T;
extern win_T *curwin;
typedef struct {
char_u *start;
int userhl;
} stl_hlrec_t;
typedef struct {
} StlClickDefinition;
typedef struct {
StlClickDefinition def;
const char *start;
} StlClickRecord;
int build_stl_str_hl(
win_T *wp,
char_u *out,
size_t outlen,
char_u *fmt,
int use_sandbox,
char_u fillchar,
int maxwidth,
stl_hlrec_t **hltab,
StlClickRecord **tabtab
);
]])
local function process_hlrec(hltab, stlbuf, eval_type)
local function default_hl()
if eval_type == 'tabline' then
return 'TabLineFill'
elseif eval_type == 'inactive' then
return 'StatusLineNC'
else
return 'StatusLine'
end
end
local len = #ffi.string(stlbuf)
local hltab_data = hltab[0]
local result = {}
if hltab_data[0].start ~= stlbuf then
table.insert(result, {
group = default_hl(),
start = 0,
})
end
local n = 0
while hltab_data[n].start ~= nil do
local group_name
if hltab_data[n].userhl == 0 then
group_name = default_hl()
elseif hltab_data[n].userhl < 0 then
group_name = vim.fn.synIDattr(-1 * hltab_data[n].userhl, 'name')
else
group_name = string.format('User%d', hltab_data[n].userhl)
end
local hl_pos = { group = group_name }
if n == 0 then
hl_pos.start = hltab_data[n].start - stlbuf
else
hl_pos.start = result[#result].start + result[#result].len
end
if hltab_data[n + 1].start ~= nil then
hl_pos.len = hltab_data[n + 1].start - hltab_data[n].start
else
hl_pos.len = (stlbuf + len) - hltab_data[n].start
end
table.insert(result, hl_pos)
n = n + 1
end
return vim.tbl_filter(function(x)
return x.len ~= 0
end, result)
end
local function gen_stl(stl_fmt, width, eval_type)
local stlbuf = ffi.new('char_u [?]', width + 100)
local fmt = ffi.cast('char_u *', stl_fmt)
local fillchar = ffi.cast('char_u', 0x20)
local hltab = ffi.new('stl_hlrec_t *[1]', ffi.new('stl_hlrec_t *'))
ffi.C.build_stl_str_hl(ffi.C.curwin, stlbuf, width + 100, fmt, 0, fillchar, width, hltab, nil)
return { str = ffi.string(stlbuf), highlights = process_hlrec(hltab, stlbuf, eval_type) }
end
local function eval_stl(stl_expr, width, eval_type)
local stl_buf, hl_list, stl_eval_res
if vim.fn.has('nvim-0.6') == 1 then
stl_eval_res = vim.api.nvim_eval_statusline(
stl_expr,
{ maxwidth = width, highlights = true, fillchar = ' ', use_tabline = (eval_type == 'tabline') }
)
else
stl_eval_res = gen_stl(stl_expr, width, eval_type)
end
stl_eval_res = vim.api.nvim_eval_statusline(
stl_expr,
{ maxwidth = width, highlights = true, fillchar = ' ', use_tabline = (eval_type == 'tabline') }
)
stl_buf, hl_list = stl_eval_res.str, stl_eval_res.highlights
local hl_map = {}