Skip to content

Commit

Permalink
feat: ship the experimental treesitter selection range (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Nov 1, 2023
1 parent 23a739c commit 8e4090b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 42 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,6 @@ require("aerial").setup({
treesitter = {
-- How long to wait (in ms) after a buffer change before updating
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 = {
Expand Down
4 changes: 0 additions & 4 deletions doc/aerial.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,6 @@ OPTIONS *aerial-option
treesitter = {
-- How long to wait (in ms) after a buffer change before updating
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 = {
Expand Down
3 changes: 1 addition & 2 deletions lua/aerial/backends/treesitter/extensions.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local config = require("aerial.config")
local helpers = require("aerial.backends.treesitter.helpers")
local M = {}

Expand Down Expand Up @@ -294,7 +293,7 @@ local function c_postprocess(bufnr, item, match)
end
end
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)
end
end
Expand Down
5 changes: 1 addition & 4 deletions lua/aerial/backends/treesitter/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ M.fetch_symbols_sync = function(bufnr)
)
return
end
local use_selection_range = config.treesitter.experimental_selection_range
-- This will track a loose hierarchy of recent node+items.
-- It is used to determine node parents for the tree structure.
local stack = {}
Expand Down Expand Up @@ -125,10 +124,8 @@ M.fetch_symbols_sync = function(bufnr)
level = level,
parent = parent_item,
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
item[k] = v
end
Expand Down
4 changes: 0 additions & 4 deletions lua/aerial/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,6 @@ local default_options = {
treesitter = {
-- How long to wait (in ms) after a buffer change before updating
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 = {
Expand Down
44 changes: 23 additions & 21 deletions tests/navigation_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ a.describe("navigation", function()
vim.api.nvim_win_set_cursor(0, { 1, 0 })
aerial.select({ index = 2 })
local cursor = vim.api.nvim_win_get_cursor(0)
assert.are.same({ 3, 0 }, cursor)
assert.are.same({ 3, 1 }, cursor)
end)

a.it("in aerial window jumps to location", function()
Expand All @@ -63,7 +63,7 @@ a.describe("navigation", function()
assert.equals("aerial", vim.bo.filetype)
aerial.select({ index = 2 })
local cursor = vim.api.nvim_win_get_cursor(0)
assert.are.same({ 3, 0 }, cursor)
assert.are.same({ 3, 1 }, cursor)
end)

a.it("in aerial window uses cursor position as index", function()
Expand All @@ -75,7 +75,7 @@ a.describe("navigation", function()
vim.api.nvim_win_set_cursor(0, { 3, 0 })
aerial.select()
local cursor = vim.api.nvim_win_get_cursor(0)
assert.are.same({ 5, 0 }, cursor)
assert.are.same({ 5, 1 }, cursor)
end)

a.it("doesn't have to jump", function()
Expand All @@ -92,7 +92,7 @@ a.describe("navigation", function()
assert.equals("aerial", vim.bo.filetype)
-- The source window cursor should be updated
local cursor = vim.api.nvim_win_get_cursor(winid)
assert.are.same({ 5, 0 }, cursor)
assert.are.same({ 5, 1 }, cursor)
end)

a.it("can open a new split when jumping", function()
Expand All @@ -111,55 +111,57 @@ a.describe("navigation", function()
-- Source window cursor should be the same
assert.are.same({ 1, 0 }, vim.api.nvim_win_get_cursor(winid))
-- 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)

a.describe("movement", function()
a.it("can go to next symbol", function()
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()
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)

a.it("can go to next N symbol", function()
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)
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)

a.it("can go to prev symbol", function()
create_md_buf(markdown_nested_content)
vim.api.nvim_win_set_cursor(0, { 3, 0 })
window.update_position(0, 0) -- Not sure why the CursorMoved autocmd doesn't fire
vim.api.nvim_win_set_cursor(0, { 3, 2 })
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
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)

a.it("can go to prev N symbol", function()
create_md_buf(markdown_nested_content)
vim.api.nvim_win_set_cursor(0, { 5, 0 })
window.update_position(0, 0) -- Not sure why the CursorMoved autocmd doesn't fire
vim.api.nvim_win_set_cursor(0, { 5, 2 })
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
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)

a.it("can go up and backwards in the tree", function()
create_md_buf(markdown_nested_content)
vim.api.nvim_win_set_cursor(0, { 5, 0 })
window.update_position(0, 0) -- Not sure why the CursorMoved autocmd doesn't fire
vim.api.nvim_win_set_cursor(0, { 5, 2 })
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
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)

a.it("can go up and forwards in the tree", function()
create_md_buf(markdown_nested_content)
vim.api.nvim_win_set_cursor(0, { 3, 0 })
window.update_position(0, 0) -- Not sure why the CursorMoved autocmd doesn't fire
vim.api.nvim_win_set_cursor(0, { 3, 2 })
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
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)
3 changes: 0 additions & 3 deletions tests/test_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ M.test_file_symbols = function(backend_name, filename, symbols_file)
config.setup({
backends = { backend_name },
filter_kind = false,
treesitter = {
experimental_selection_range = true,
},
})
vim.cmd(string.format("edit %s", filename))
local backend = backends.get(0)
Expand Down

0 comments on commit 8e4090b

Please sign in to comment.