From b309d0df6b59923a2155f5a8b7ef99777b3311c9 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli <506791+stevearc@users.noreply.github.com> Date: Mon, 15 Jul 2024 11:31:20 -0700 Subject: [PATCH] refactor!: drop support for Neovim 0.8 (#387) --- .github/workflows/tests.yml | 1 - README.md | 8 ++-- lua/aerial/backends/treesitter/helpers.lua | 53 ++++++---------------- lua/aerial/backends/treesitter/init.lua | 3 -- lua/aerial/highlight.lua | 23 +++------- lua/aerial/init.lua | 4 +- tests/symbols/tsx_test.json | 16 +++---- tests/treesitter_spec.lua | 6 --- 8 files changed, 34 insertions(+), 80 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3e47bd9..6e4f9d3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -50,7 +50,6 @@ jobs: strategy: matrix: include: - - nvim_tag: v0.8.3 - nvim_tag: v0.9.4 - nvim_tag: v0.10.0 diff --git a/README.md b/README.md index 4ff438a..d456ce7 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,10 @@ https://user-images.githubusercontent.com/506791/122652728-18688500-d0f5-11eb-80 ## 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: - A working LSP setup (see [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig)) - - Tree-sitter parsers[^1] - -[^1]: With Neovim < 0.9, you need [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter). + - Tree-sitter parsers ## 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` - `@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 diff --git a/lua/aerial/backends/treesitter/helpers.lua b/lua/aerial/backends/treesitter/helpers.lua index 0aa7c9e..bacc570 100644 --- a/lua/aerial/backends/treesitter/helpers.lua +++ b/lua/aerial/backends/treesitter/helpers.lua @@ -20,40 +20,18 @@ M.range_from_nodes = function(start_node, end_node) } end -if vim.treesitter.language.get_lang == nil then - ---@param bufnr nil|integer - M.get_buf_lang = function(bufnr) - return require("nvim-treesitter.parsers").get_buf_lang(bufnr) - end -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 +-- 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) - if result then - return result - else - ft = vim.split(ft, ".", { plain = true })[1] - 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") + local result = vim.treesitter.language.get_lang(ft) + if result then + return result + else + ft = vim.split(ft, ".", { plain = true })[1] + return vim.treesitter.language.get_lang(ft) or ft end end @@ -62,7 +40,7 @@ end ---@note caches queries to avoid filesystem hits on neovim 0.9+ M.get_query = function(lang) 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 return query_cache[lang].query @@ -76,14 +54,11 @@ M.has_parser = function(lang) return installed end ----@param bufnr integer +---@param bufnr? integer ---@return vim.treesitter.LanguageTree|nil M.get_parser = function(bufnr) 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 - --- 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) + local success, parser = pcall(vim.treesitter.get_parser, bufnr) return success and parser or nil end diff --git a/lua/aerial/backends/treesitter/init.lua b/lua/aerial/backends/treesitter/init.lua index 1481d47..5639d99 100644 --- a/lua/aerial/backends/treesitter/init.lua +++ b/lua/aerial/backends/treesitter/init.lua @@ -12,9 +12,6 @@ local M = {} -- end (optional): The location of the end of this symbol (default @start) 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) if not helpers.has_parser(lang) then return false, string.format("No treesitter parser for %s", lang) diff --git a/lua/aerial/highlight.lua b/lua/aerial/highlight.lua index f036fe9..7fc5aa1 100644 --- a/lua/aerial/highlight.lua +++ b/lua/aerial/highlight.lua @@ -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 "") end -local get_hl_by_name -if vim.fn.has("nvim-0.9") == 1 then - get_hl_by_name = function(name) - 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 +---@param name string +---@return vim.api.keyset.hl_info +local function get_hl_by_name(name) + return vim.api.nvim_get_hl(0, { name = name, link = false }) end M.create_highlight_groups = function() @@ -75,7 +66,7 @@ M.create_highlight_groups = function() -- The default text highlight vim.api.nvim_set_hl(0, "AerialNormal", { fg = normal_defn.fg, - ctermfg = normal_defn.ctermfg, + ctermfg = normal_defn.cterm and normal_defn.cterm.ctermfg, blend = normal_defn.blend, 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 vim.api.nvim_set_hl(0, "AerialNormalFloat", { 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, default = true, }) @@ -103,7 +94,7 @@ M.create_highlight_groups = function() -- The guides when show_guide = true vim.api.nvim_set_hl(0, "AerialGuide", { fg = comment_defn.fg, - ctermfg = comment_defn.ctermfg, + ctermfg = comment_defn.cterm and comment_defn.cterm.ctermfg, blend = comment_defn.blend, default = true, }) diff --git a/lua/aerial/init.lua b/lua/aerial/init.lua index 39a1026..e7e4db0 100644 --- a/lua/aerial/init.lua +++ b/lua/aerial/init.lua @@ -207,9 +207,9 @@ end ---Initialize aerial ---@param opts? table 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( - "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 ) return diff --git a/tests/symbols/tsx_test.json b/tests/symbols/tsx_test.json index 4e62cd8..8c765b3 100644 --- a/tests/symbols/tsx_test.json +++ b/tests/symbols/tsx_test.json @@ -370,12 +370,12 @@ { "children": [ { - "col": 2, + "col": 12, "end_col": 41, "end_lnum": 39, "kind": "Struct", "level": 1, - "lnum": 39, + "lnum": 38, "name": "SomeComponent", "selection_range": { "col": 3, @@ -387,12 +387,12 @@ { "children": [ { - "col": 4, + "col": 6, "end_col": 31, "end_lnum": 41, "kind": "Struct", "level": 2, - "lnum": 41, + "lnum": 40, "name": "li", "selection_range": { "col": 5, @@ -402,12 +402,12 @@ } }, { - "col": 4, + "col": 31, "end_col": 32, "end_lnum": 42, "kind": "Struct", "level": 2, - "lnum": 42, + "lnum": 41, "name": "li", "selection_range": { "col": 5, @@ -417,12 +417,12 @@ } } ], - "col": 2, + "col": 41, "end_col": 7, "end_lnum": 43, "kind": "Struct", "level": 1, - "lnum": 40, + "lnum": 39, "name": "ul", "selection_range": { "col": 3, diff --git a/tests/treesitter_spec.lua b/tests/treesitter_spec.lua index 7cc6a6f..c86f291 100644 --- a/tests/treesitter_spec.lua +++ b/tests/treesitter_spec.lua @@ -24,10 +24,6 @@ end describe("treesitter", function() 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 basename = vim.fn.fnamemodify(filename, ":r") 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") end) end - - ::continue:: end util.test_file_symbols("man", "./tests/man_test.txt", "./tests/symbols/man.json")