mirror of
https://github.com/stevearc/aerial.nvim
synced 2024-09-16 14:34:08 +02:00
feat: add disable_max_lines option (#37)
This commit is contained in:
parent
d52784941f
commit
e2a5baf45f
7 changed files with 44 additions and 14 deletions
|
@ -213,6 +213,9 @@ vim.g.aerial = {
|
|||
-- different buffer in the way of the preferred direction
|
||||
default_direction = "prefer_right",
|
||||
|
||||
-- Disable aerial on files with this many lines
|
||||
disable_max_lines = 10000,
|
||||
|
||||
-- A list of all symbols to display. Set to false to display all symbols.
|
||||
filter_kind = {
|
||||
"Class",
|
||||
|
@ -225,7 +228,7 @@ vim.g.aerial = {
|
|||
},
|
||||
|
||||
-- Enum: split_width, full_width, last, none
|
||||
-- Determines line highlighting mode when multiple buffers are visible
|
||||
-- Determines line highlighting mode when multiple splits are visible
|
||||
highlight_mode = "split_width",
|
||||
|
||||
-- When jumping to a symbol, highlight the line for this many ms
|
||||
|
|
|
@ -7,8 +7,17 @@ M.get_backend_by_name = function(name)
|
|||
end
|
||||
|
||||
M.is_supported = function(bufnr, name)
|
||||
local max_lines = config.disable_max_lines
|
||||
if max_lines and max_lines > 0 and vim.api.nvim_buf_line_count(bufnr) > max_lines then
|
||||
return false, "File exceeds disable_max_lines size"
|
||||
end
|
||||
local backend = M.get_backend_by_name(name)
|
||||
return backend and backend.is_supported(bufnr)
|
||||
if backend then
|
||||
local supported, err = backend.is_supported(bufnr)
|
||||
return supported, err
|
||||
else
|
||||
return false, "No such backend"
|
||||
end
|
||||
end
|
||||
|
||||
local attach_callbacks = {}
|
||||
|
@ -20,11 +29,11 @@ local function get_best_backend(bufnr)
|
|||
if not bufnr or bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
|
||||
local candidates = config.backends(bufnr)
|
||||
for _, name in ipairs(candidates) do
|
||||
local backend = M.get_backend_by_name(name)
|
||||
if backend and backend.is_supported(bufnr) then
|
||||
return backend, name
|
||||
if M.is_supported(bufnr, name) then
|
||||
return M.get_backend_by_name(name), name
|
||||
end
|
||||
end
|
||||
return nil, nil
|
||||
|
@ -115,7 +124,7 @@ M.attach = function(bufnr, refresh)
|
|||
end
|
||||
|
||||
-- Backends must provide the following methods:
|
||||
-- is_supported(bufnr)
|
||||
-- is_supported(bufnr) -> bool, err
|
||||
-- fetch_symbols_sync(timeout)
|
||||
-- fetch_symbols()
|
||||
-- attach(bufnr)
|
||||
|
|
|
@ -81,7 +81,15 @@ M.is_supported = function(bufnr)
|
|||
if not bufnr or bufnr == 0 then
|
||||
bufnr = vim.api.nvim_get_current_buf()
|
||||
end
|
||||
return is_lsp_attached(bufnr)
|
||||
if not is_lsp_attached(bufnr) then
|
||||
for _, client in pairs(vim.lsp.buf_get_clients(bufnr)) do
|
||||
if client.resolved_capabilities.document_symbol then
|
||||
return false, "LSP client not attached (did you call aerial.on_attach?)"
|
||||
end
|
||||
end
|
||||
return false, "LSP client not attached"
|
||||
end
|
||||
return true, nil
|
||||
end
|
||||
|
||||
M.on_attach = function(client, bufnr, opts)
|
||||
|
|
|
@ -5,7 +5,10 @@ local util = require("aerial.util")
|
|||
local M = {}
|
||||
|
||||
M.is_supported = function(bufnr)
|
||||
return vim.tbl_contains(util.get_filetypes(bufnr), "markdown")
|
||||
if not vim.tbl_contains(util.get_filetypes(bufnr), "markdown") then
|
||||
return false, "Filetype is not markdown"
|
||||
end
|
||||
return true, nil
|
||||
end
|
||||
|
||||
M.fetch_symbols_sync = function(timeout)
|
||||
|
|
|
@ -7,14 +7,17 @@ local M = {}
|
|||
M.is_supported = function(bufnr)
|
||||
local ok, parsers = pcall(require, "nvim-treesitter.parsers")
|
||||
if not ok then
|
||||
return false
|
||||
return false, "nvim-treesitter not found"
|
||||
end
|
||||
local lang = parsers.get_buf_lang(bufnr)
|
||||
if not parsers.has_parser(lang) then
|
||||
return false
|
||||
return false, string.format("No treesitter parser for %s", lang)
|
||||
end
|
||||
local query = require("nvim-treesitter.query")
|
||||
return query.has_query_files(lang, "aerial")
|
||||
if not query.has_query_files(lang, "aerial") then
|
||||
return false, string.format("No query file for '%s'", lang)
|
||||
end
|
||||
return true, nil
|
||||
end
|
||||
|
||||
M.fetch_symbols_sync = function(timeout)
|
||||
|
|
|
@ -21,6 +21,9 @@ local default_options = {
|
|||
-- different buffer in the way of the preferred direction
|
||||
default_direction = "prefer_right",
|
||||
|
||||
-- Disable aerial on files with this many lines
|
||||
disable_max_lines = 10000,
|
||||
|
||||
-- A list of all symbols to display. Set to false to display all symbols.
|
||||
filter_kind = {
|
||||
"Class",
|
||||
|
@ -33,7 +36,7 @@ local default_options = {
|
|||
},
|
||||
|
||||
-- Enum: split_width, full_width, last, none
|
||||
-- Determines line highlighting mode when multiple buffers are visible
|
||||
-- Determines line highlighting mode when multiple splits are visible
|
||||
highlight_mode = "split_width",
|
||||
|
||||
-- When jumping to a symbol, highlight the line for this many ms
|
||||
|
|
|
@ -175,10 +175,11 @@ M.info = function()
|
|||
print("Configured backends:")
|
||||
for _, name in ipairs(config.backends(0)) do
|
||||
local line = " " .. name
|
||||
if backends.is_supported(0, name) then
|
||||
local supported, err = backends.is_supported(0, name)
|
||||
if supported then
|
||||
line = line .. " (supported)"
|
||||
else
|
||||
line = line .. " (not supported)"
|
||||
line = line .. " (not supported) [" .. err .. "]"
|
||||
end
|
||||
if backends.is_backend_attached(0, name) then
|
||||
line = line .. " (attached)"
|
||||
|
|
Loading…
Reference in a new issue