refactor!: drop support for Neovim 0.8 (#387)

This commit is contained in:
Steven Arcangeli 2024-07-15 11:31:20 -07:00 committed by GitHub
parent d8343d0c93
commit b309d0df6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 34 additions and 80 deletions

View file

@ -50,7 +50,6 @@ jobs:
strategy: strategy:
matrix: matrix:
include: include:
- nvim_tag: v0.8.3
- nvim_tag: v0.9.4 - nvim_tag: v0.9.4
- nvim_tag: v0.10.0 - nvim_tag: v0.10.0

View file

@ -24,12 +24,10 @@ https://user-images.githubusercontent.com/506791/122652728-18688500-d0f5-11eb-80
## Requirements ## Requirements
- Neovim 0.8+ (for older versions, use the [nvim-0.5 branch](https://github.com/stevearc/aerial.nvim/tree/nvim-0.5)) - Neovim 0.9+ (for older versions, use a [nvim-0.x branch](https://github.com/stevearc/conform.nvim/branches))
- One or more of the following: - One or more of the following:
- A working LSP setup (see [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig)) - A working LSP setup (see [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig))
- Tree-sitter parsers[^1] - Tree-sitter parsers
[^1]: With Neovim < 0.9, you need [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter).
## Installation ## Installation
@ -749,7 +747,7 @@ When writing queries, the following captures and metadata are used by Aerial:
- `@selection` - position to jump to when using Aerial for navigation, falls back to `@name` and `@symbol` - `@selection` - position to jump to when using Aerial for navigation, falls back to `@name` and `@symbol`
- `@scope` - a node naming a scope for the match, its text is used to generate a custom "Comment" linked highlight for the entry, with exception of "public" - `@scope` - a node naming a scope for the match, its text is used to generate a custom "Comment" linked highlight for the entry, with exception of "public"
A `@scope` node with text "developers" will result in its entry in the tree having an "AerialDevelopers" highlight applied to it. A `@scope` node with text "developers" will result in its entry in the tree having an "AerialDevelopers" highlight applied to it.
- `scope` - a metadata value serving the same role as `@scope` capture, overriding aforementioned capture - `scope` - a metadata value serving the same role as `@scope` capture, overriding aforementioned capture

View file

@ -20,40 +20,18 @@ M.range_from_nodes = function(start_node, end_node)
} }
end end
if vim.treesitter.language.get_lang == nil then -- Taken directly out of nvim-treesitter with minor adjustments
---@param bufnr nil|integer ---@param bufnr nil|integer
M.get_buf_lang = function(bufnr) M.get_buf_lang = function(bufnr)
return require("nvim-treesitter.parsers").get_buf_lang(bufnr) bufnr = bufnr or vim.api.nvim_get_current_buf()
end local ft = vim.bo[bufnr].filetype
else
-- Taken directly out of nvim-treesitter with minor adjustments
---@param bufnr nil|integer
M.get_buf_lang = function(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
local ft = vim.bo[bufnr].filetype
local result = vim.treesitter.language.get_lang(ft) local result = vim.treesitter.language.get_lang(ft)
if result then if result then
return result return result
else else
ft = vim.split(ft, ".", { plain = true })[1] ft = vim.split(ft, ".", { plain = true })[1]
return vim.treesitter.language.get_lang(ft) or ft return vim.treesitter.language.get_lang(ft) or ft
end
end
end
if vim.treesitter.query.get == nil then
---@param lang string
---@return vim.treesitter.Query|nil
M.load_query = function(lang)
---@diagnostic disable-next-line: deprecated
return vim.treesitter.query.get_query(lang, "aerial")
end
else
---@param lang string
---@return vim.treesitter.Query|nil
M.load_query = function(lang)
return vim.treesitter.query.get(lang, "aerial")
end end
end end
@ -62,7 +40,7 @@ end
---@note caches queries to avoid filesystem hits on neovim 0.9+ ---@note caches queries to avoid filesystem hits on neovim 0.9+
M.get_query = function(lang) M.get_query = function(lang)
if not query_cache[lang] then if not query_cache[lang] then
query_cache[lang] = { query = M.load_query(lang) } query_cache[lang] = { query = vim.treesitter.query.get(lang, "aerial") }
end end
return query_cache[lang].query return query_cache[lang].query
@ -76,14 +54,11 @@ M.has_parser = function(lang)
return installed return installed
end end
---@param bufnr integer ---@param bufnr? integer
---@return vim.treesitter.LanguageTree|nil ---@return vim.treesitter.LanguageTree|nil
M.get_parser = function(bufnr) M.get_parser = function(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf() bufnr = bufnr or vim.api.nvim_get_current_buf()
---@note nvim 0.9.1 and later don't really care for lang here, as vim itself becomes an authority on that local success, parser = pcall(vim.treesitter.get_parser, bufnr)
--- nvim 0.8.3 breaks if we are too eager, however
local lang = M.get_buf_lang(bufnr)
local success, parser = pcall(vim.treesitter.get_parser, bufnr, lang)
return success and parser or nil return success and parser or nil
end end

View file

@ -12,9 +12,6 @@ local M = {}
-- end (optional): The location of the end of this symbol (default @start) -- end (optional): The location of the end of this symbol (default @start)
M.is_supported = function(bufnr) M.is_supported = function(bufnr)
if vim.fn.has("nvim-0.9") == 0 and not pcall(require, "nvim-treesitter") then
return false, "Neovim <0.9 requires nvim-treesitter"
end
local lang = helpers.get_buf_lang(bufnr) local lang = helpers.get_buf_lang(bufnr)
if not helpers.has_parser(lang) then if not helpers.has_parser(lang) then
return false, string.format("No treesitter parser for %s", lang) return false, string.format("No treesitter parser for %s", lang)

View file

@ -54,19 +54,10 @@ M.get_highlight = function(symbol, is_icon, is_collapsed)
return string.format("Aerial%s%s", symbol.kind, is_icon and "Icon" or "") return string.format("Aerial%s%s", symbol.kind, is_icon and "Icon" or "")
end end
local get_hl_by_name ---@param name string
if vim.fn.has("nvim-0.9") == 1 then ---@return vim.api.keyset.hl_info
get_hl_by_name = function(name) local function get_hl_by_name(name)
return vim.api.nvim_get_hl(0, { name = name, link = false }) return vim.api.nvim_get_hl(0, { name = name, link = false })
end
else
get_hl_by_name = function(name)
---@diagnostic disable-next-line undefined-field
local result = vim.api.nvim_get_hl_by_name(name, true)
result.fg = result.foreground
result.bg = result.background
return result
end
end end
M.create_highlight_groups = function() M.create_highlight_groups = function()
@ -75,7 +66,7 @@ M.create_highlight_groups = function()
-- The default text highlight -- The default text highlight
vim.api.nvim_set_hl(0, "AerialNormal", { vim.api.nvim_set_hl(0, "AerialNormal", {
fg = normal_defn.fg, fg = normal_defn.fg,
ctermfg = normal_defn.ctermfg, ctermfg = normal_defn.cterm and normal_defn.cterm.ctermfg,
blend = normal_defn.blend, blend = normal_defn.blend,
default = true, default = true,
}) })
@ -85,7 +76,7 @@ M.create_highlight_groups = function()
-- Don't set the background for the float so that it blends nicely with the cursorline -- Don't set the background for the float so that it blends nicely with the cursorline
vim.api.nvim_set_hl(0, "AerialNormalFloat", { vim.api.nvim_set_hl(0, "AerialNormalFloat", {
fg = normal_float_defn.fg, fg = normal_float_defn.fg,
ctermfg = normal_float_defn.ctermfg, ctermfg = normal_float_defn.cterm and normal_float_defn.cterm.ctermfg,
blend = normal_float_defn.blend, blend = normal_float_defn.blend,
default = true, default = true,
}) })
@ -103,7 +94,7 @@ M.create_highlight_groups = function()
-- The guides when show_guide = true -- The guides when show_guide = true
vim.api.nvim_set_hl(0, "AerialGuide", { vim.api.nvim_set_hl(0, "AerialGuide", {
fg = comment_defn.fg, fg = comment_defn.fg,
ctermfg = comment_defn.ctermfg, ctermfg = comment_defn.cterm and comment_defn.cterm.ctermfg,
blend = comment_defn.blend, blend = comment_defn.blend,
default = true, default = true,
}) })

View file

@ -207,9 +207,9 @@ end
---Initialize aerial ---Initialize aerial
---@param opts? table ---@param opts? table
M.setup = function(opts) M.setup = function(opts)
if vim.fn.has("nvim-0.8") == 0 then if vim.fn.has("nvim-0.9") == 0 then
vim.notify_once( vim.notify_once(
"aerial is deprecated for Neovim <0.8. Please use the nvim-0.5 branch or upgrade Neovim", "aerial is deprecated for Neovim <0.9. Please use a nvim-0.x branch or upgrade Neovim",
vim.log.levels.ERROR vim.log.levels.ERROR
) )
return return

View file

@ -370,12 +370,12 @@
{ {
"children": [ "children": [
{ {
"col": 2, "col": 12,
"end_col": 41, "end_col": 41,
"end_lnum": 39, "end_lnum": 39,
"kind": "Struct", "kind": "Struct",
"level": 1, "level": 1,
"lnum": 39, "lnum": 38,
"name": "SomeComponent", "name": "SomeComponent",
"selection_range": { "selection_range": {
"col": 3, "col": 3,
@ -387,12 +387,12 @@
{ {
"children": [ "children": [
{ {
"col": 4, "col": 6,
"end_col": 31, "end_col": 31,
"end_lnum": 41, "end_lnum": 41,
"kind": "Struct", "kind": "Struct",
"level": 2, "level": 2,
"lnum": 41, "lnum": 40,
"name": "li", "name": "li",
"selection_range": { "selection_range": {
"col": 5, "col": 5,
@ -402,12 +402,12 @@
} }
}, },
{ {
"col": 4, "col": 31,
"end_col": 32, "end_col": 32,
"end_lnum": 42, "end_lnum": 42,
"kind": "Struct", "kind": "Struct",
"level": 2, "level": 2,
"lnum": 42, "lnum": 41,
"name": "li", "name": "li",
"selection_range": { "selection_range": {
"col": 5, "col": 5,
@ -417,12 +417,12 @@
} }
} }
], ],
"col": 2, "col": 41,
"end_col": 7, "end_col": 7,
"end_lnum": 43, "end_lnum": 43,
"kind": "Struct", "kind": "Struct",
"level": 1, "level": 1,
"lnum": 40, "lnum": 39,
"name": "ul", "name": "ul",
"selection_range": { "selection_range": {
"col": 3, "col": 3,

View file

@ -24,10 +24,6 @@ end
describe("treesitter", function() describe("treesitter", function()
for _, filename in ipairs(list_files("tests/treesitter")) do for _, filename in ipairs(list_files("tests/treesitter")) do
if filename == "usd_test.usd" and vim.fn.has("nvim-0.9.0") == 0 then
-- These queries rely on #offset! which only works in neovim 0.9.0+
goto continue
end
local filepath = "./tests/treesitter/" .. filename local filepath = "./tests/treesitter/" .. filename
local basename = vim.fn.fnamemodify(filename, ":r") local basename = vim.fn.fnamemodify(filename, ":r")
local symbols_file = "./tests/symbols/" .. basename .. ".json" local symbols_file = "./tests/symbols/" .. basename .. ".json"
@ -40,8 +36,6 @@ describe("treesitter", function()
util.test_file_symbols("markdown", filepath, "./tests/symbols/markdown_backend.json") util.test_file_symbols("markdown", filepath, "./tests/symbols/markdown_backend.json")
end) end)
end end
::continue::
end end
util.test_file_symbols("man", "./tests/man_test.txt", "./tests/symbols/man.json") util.test_file_symbols("man", "./tests/man_test.txt", "./tests/symbols/man.json")