mirror of
https://github.com/stevearc/aerial.nvim
synced 2024-09-08 02:35:44 +02:00
feat: ship the experimental treesitter selection range (#279)
This commit is contained in:
parent
23a739c0ac
commit
8e4090bf94
7 changed files with 25 additions and 42 deletions
|
@ -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 = {
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
local config = require("aerial.config")
|
||||
local helpers = require("aerial.backends.treesitter.helpers")
|
||||
local M = {}
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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 = {}
|
||||
|
@ -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
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue