feat: ship the experimental treesitter selection range (#279)

This commit is contained in:
Steven Arcangeli 2023-10-31 17:26:09 -07:00
parent 23a739c0ac
commit 8e4090bf94
7 changed files with 25 additions and 42 deletions

View file

@ -538,10 +538,6 @@ require("aerial").setup({
treesitter = { treesitter = {
-- How long to wait (in ms) after a buffer change before updating -- How long to wait (in ms) after a buffer change before updating
update_delay = 300, update_delay = 300,
-- Experimental feature to navigate to symbol names instead of the declaration
-- See https://github.com/stevearc/aerial.nvim/issues/279
-- If no bugs are reported for a time this will become the default
experimental_selection_range = false,
}, },
markdown = { markdown = {

View file

@ -349,10 +349,6 @@ OPTIONS *aerial-option
treesitter = { treesitter = {
-- How long to wait (in ms) after a buffer change before updating -- How long to wait (in ms) after a buffer change before updating
update_delay = 300, update_delay = 300,
-- Experimental feature to navigate to symbol names instead of the declaration
-- See https://github.com/stevearc/aerial.nvim/issues/279
-- If no bugs are reported for a time this will become the default
experimental_selection_range = false,
}, },
markdown = { markdown = {

View file

@ -1,4 +1,3 @@
local config = require("aerial.config")
local helpers = require("aerial.backends.treesitter.helpers") local helpers = require("aerial.backends.treesitter.helpers")
local M = {} local M = {}
@ -294,7 +293,7 @@ local function c_postprocess(bufnr, item, match)
end end
end end
item.name = get_node_text(root, bufnr) or "<parse error>" item.name = get_node_text(root, bufnr) or "<parse error>"
if config.treesitter.experimental_selection_range and not item.selection_range then if not item.selection_range then
item.selection_range = helpers.range_from_nodes(root, root) item.selection_range = helpers.range_from_nodes(root, root)
end end
end end

View file

@ -47,7 +47,6 @@ M.fetch_symbols_sync = function(bufnr)
) )
return return
end end
local use_selection_range = config.treesitter.experimental_selection_range
-- This will track a loose hierarchy of recent node+items. -- This will track a loose hierarchy of recent node+items.
-- It is used to determine node parents for the tree structure. -- It is used to determine node parents for the tree structure.
local stack = {} local stack = {}
@ -125,10 +124,8 @@ M.fetch_symbols_sync = function(bufnr)
level = level, level = level,
parent = parent_item, parent = parent_item,
scope = match.scope, scope = match.scope,
selection_range = selection_range,
} }
if use_selection_range then
item.selection_range = selection_range
end
for k, v in pairs(range) do for k, v in pairs(range) do
item[k] = v item[k] = v
end end

View file

@ -335,10 +335,6 @@ local default_options = {
treesitter = { treesitter = {
-- How long to wait (in ms) after a buffer change before updating -- How long to wait (in ms) after a buffer change before updating
update_delay = 300, update_delay = 300,
-- Experimental feature to navigate to symbol names instead of the declaration
-- See https://github.com/stevearc/aerial.nvim/issues/279
-- If no bugs are reported for a time this will become the default
experimental_selection_range = false,
}, },
markdown = { markdown = {

View file

@ -53,7 +53,7 @@ a.describe("navigation", function()
vim.api.nvim_win_set_cursor(0, { 1, 0 }) vim.api.nvim_win_set_cursor(0, { 1, 0 })
aerial.select({ index = 2 }) aerial.select({ index = 2 })
local cursor = vim.api.nvim_win_get_cursor(0) local cursor = vim.api.nvim_win_get_cursor(0)
assert.are.same({ 3, 0 }, cursor) assert.are.same({ 3, 1 }, cursor)
end) end)
a.it("in aerial window jumps to location", function() a.it("in aerial window jumps to location", function()
@ -63,7 +63,7 @@ a.describe("navigation", function()
assert.equals("aerial", vim.bo.filetype) assert.equals("aerial", vim.bo.filetype)
aerial.select({ index = 2 }) aerial.select({ index = 2 })
local cursor = vim.api.nvim_win_get_cursor(0) local cursor = vim.api.nvim_win_get_cursor(0)
assert.are.same({ 3, 0 }, cursor) assert.are.same({ 3, 1 }, cursor)
end) end)
a.it("in aerial window uses cursor position as index", function() a.it("in aerial window uses cursor position as index", function()
@ -75,7 +75,7 @@ a.describe("navigation", function()
vim.api.nvim_win_set_cursor(0, { 3, 0 }) vim.api.nvim_win_set_cursor(0, { 3, 0 })
aerial.select() aerial.select()
local cursor = vim.api.nvim_win_get_cursor(0) local cursor = vim.api.nvim_win_get_cursor(0)
assert.are.same({ 5, 0 }, cursor) assert.are.same({ 5, 1 }, cursor)
end) end)
a.it("doesn't have to jump", function() a.it("doesn't have to jump", function()
@ -92,7 +92,7 @@ a.describe("navigation", function()
assert.equals("aerial", vim.bo.filetype) assert.equals("aerial", vim.bo.filetype)
-- The source window cursor should be updated -- The source window cursor should be updated
local cursor = vim.api.nvim_win_get_cursor(winid) local cursor = vim.api.nvim_win_get_cursor(winid)
assert.are.same({ 5, 0 }, cursor) assert.are.same({ 5, 1 }, cursor)
end) end)
a.it("can open a new split when jumping", function() a.it("can open a new split when jumping", function()
@ -111,55 +111,57 @@ a.describe("navigation", function()
-- Source window cursor should be the same -- Source window cursor should be the same
assert.are.same({ 1, 0 }, vim.api.nvim_win_get_cursor(winid)) assert.are.same({ 1, 0 }, vim.api.nvim_win_get_cursor(winid))
-- Split window cursor should be updated -- Split window cursor should be updated
assert.are.same({ 5, 0 }, vim.api.nvim_win_get_cursor(0)) assert.are.same({ 5, 1 }, vim.api.nvim_win_get_cursor(0))
end) end)
end) end)
a.describe("movement", function() a.describe("movement", function()
a.it("can go to next symbol", function() a.it("can go to next symbol", function()
create_md_buf(markdown_nested_content) create_md_buf(markdown_nested_content)
vim.api.nvim_win_set_cursor(0, { 1, 0 }) vim.api.nvim_win_set_cursor(0, { 1, 2 })
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
aerial.next() aerial.next()
assert.are.same({ 3, 0 }, vim.api.nvim_win_get_cursor(0)) assert.are.same({ 3, 2 }, vim.api.nvim_win_get_cursor(0))
end) end)
a.it("can go to next N symbol", function() a.it("can go to next N symbol", function()
create_md_buf(markdown_nested_content) create_md_buf(markdown_nested_content)
vim.api.nvim_win_set_cursor(0, { 1, 0 }) vim.api.nvim_win_set_cursor(0, { 1, 2 })
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
aerial.next(2) aerial.next(2)
assert.are.same({ 5, 0 }, vim.api.nvim_win_get_cursor(0)) assert.are.same({ 5, 2 }, vim.api.nvim_win_get_cursor(0))
end) end)
a.it("can go to prev symbol", function() a.it("can go to prev symbol", function()
create_md_buf(markdown_nested_content) create_md_buf(markdown_nested_content)
vim.api.nvim_win_set_cursor(0, { 3, 0 }) vim.api.nvim_win_set_cursor(0, { 3, 2 })
window.update_position(0, 0) -- Not sure why the CursorMoved autocmd doesn't fire window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
aerial.prev() aerial.prev()
assert.are.same({ 1, 0 }, vim.api.nvim_win_get_cursor(0)) assert.are.same({ 1, 1 }, vim.api.nvim_win_get_cursor(0))
end) end)
a.it("can go to prev N symbol", function() a.it("can go to prev N symbol", function()
create_md_buf(markdown_nested_content) create_md_buf(markdown_nested_content)
vim.api.nvim_win_set_cursor(0, { 5, 0 }) vim.api.nvim_win_set_cursor(0, { 5, 2 })
window.update_position(0, 0) -- Not sure why the CursorMoved autocmd doesn't fire window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
aerial.prev(2) aerial.prev(2)
assert.are.same({ 1, 0 }, vim.api.nvim_win_get_cursor(0)) assert.are.same({ 1, 1 }, vim.api.nvim_win_get_cursor(0))
end) end)
a.it("can go up and backwards in the tree", function() a.it("can go up and backwards in the tree", function()
create_md_buf(markdown_nested_content) create_md_buf(markdown_nested_content)
vim.api.nvim_win_set_cursor(0, { 5, 0 }) vim.api.nvim_win_set_cursor(0, { 5, 2 })
window.update_position(0, 0) -- Not sure why the CursorMoved autocmd doesn't fire window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
aerial.prev_up() aerial.prev_up()
assert.are.same({ 1, 0 }, vim.api.nvim_win_get_cursor(0)) assert.are.same({ 1, 1 }, vim.api.nvim_win_get_cursor(0))
end) end)
a.it("can go up and forwards in the tree", function() a.it("can go up and forwards in the tree", function()
create_md_buf(markdown_nested_content) create_md_buf(markdown_nested_content)
vim.api.nvim_win_set_cursor(0, { 3, 0 }) vim.api.nvim_win_set_cursor(0, { 3, 2 })
window.update_position(0, 0) -- Not sure why the CursorMoved autocmd doesn't fire window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
aerial.next_up() aerial.next_up()
assert.are.same({ 7, 0 }, vim.api.nvim_win_get_cursor(0)) assert.are.same({ 7, 1 }, vim.api.nvim_win_get_cursor(0))
end) end)
end) end)
end) end)

View file

@ -58,9 +58,6 @@ M.test_file_symbols = function(backend_name, filename, symbols_file)
config.setup({ config.setup({
backends = { backend_name }, backends = { backend_name },
filter_kind = false, filter_kind = false,
treesitter = {
experimental_selection_range = true,
},
}) })
vim.cmd(string.format("edit %s", filename)) vim.cmd(string.format("edit %s", filename))
local backend = backends.get(0) local backend = backends.get(0)