Refactor symbol types

This commit is contained in:
hedy
2023-11-26 16:49:25 +08:00
parent 5764294eb7
commit 5b70292780
10 changed files with 66 additions and 68 deletions

View File

@@ -1,5 +1,3 @@
local cfg = require('outline.config')
local M = {}
local import_prefix = 'outline/providers/'
@@ -8,7 +6,7 @@ function M.find_provider()
if not M.providers then
M.providers = vim.tbl_map(function(p)
return import_prefix .. p
end, cfg.get_providers())
end, require('outline.config').get_providers())
end
for _, path in ipairs(M.providers) do
local provider = require(path)

View File

@@ -15,7 +15,6 @@ local M = {
name = 'markdown',
}
---@return boolean ft_is_markdown
function M.supports_buffer(bufnr)
return vim.api.nvim_buf_get_option(bufnr, 'ft') == 'markdown'
@@ -32,7 +31,7 @@ end
-- Parses markdown files and returns a table of SymbolInformation[] which is
-- used by the plugin to show the outline.
---@return table
---@return outline.ProviderSymbol[]
function M.handle_markdown()
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
local level_symbols = { { children = {} } }
@@ -119,7 +118,7 @@ function M.handle_markdown()
return level_symbols[1].children
end
---@param on_symbols function
---@param on_symbols fun(symbols?:outline.ProviderSymbol[], opts?:table)
---@param opts table
function M.request_symbols(on_symbols, opts)
on_symbols(M.handle_markdown(), opts)

View File

@@ -53,6 +53,8 @@ if not _G._outline_nvim_has[8] then
end
end
---@param node outline.ProviderSymbol
---@param field string
local function rec_remove_field(node, field)
node[field] = nil
if node.children then
@@ -62,6 +64,8 @@ local function rec_remove_field(node, field)
end
end
---@param callback fun(symbols?:outline.ProviderSymbol[], opts?:table)
---@param opts table
function M.request_symbols(callback, opts)
if not M.parser then
local status, parser = pcall(vim.treesitter.get_parser, 0, 'norg')

View File

@@ -15,10 +15,6 @@ function M.get_status()
return { 'client: ' .. M.client.name }
end
local function get_params()
return { textDocument = vim.lsp.util.make_text_document_params() }
end
function M.hover_info(bufnr, params, on_info)
local clients = vim.lsp.get_active_clients({ bufnr = bufnr })
local use_client
@@ -49,6 +45,7 @@ function M.hover_info(bufnr, params, on_info)
use_client.request('textDocument/hover', params, on_info, bufnr)
end
---@return boolean
function M.supports_buffer(bufnr)
local clients = vim.lsp.get_active_clients({ bufnr = bufnr })
local ret = false
@@ -69,6 +66,8 @@ function M.supports_buffer(bufnr)
return ret
end
---@param response outline.ProviderSymbol[]
---@return outline.ProviderSymbol[]
local function postprocess_symbols(response)
local symbols = lsp_utils.flatten_response(response)
@@ -81,9 +80,13 @@ local function postprocess_symbols(response)
end
end
---@param on_symbols function
---@param on_symbols fun(symbols?:outline.ProviderSymbol[], opts?:table)
---@param opts table
function M.request_symbols(on_symbols, opts)
vim.lsp.buf_request_all(0, 'textDocument/documentSymbol', get_params(), function(response)
local params = {
textDocument = vim.lsp.util.make_text_document_params(),
}
vim.lsp.buf_request_all(0, 'textDocument/documentSymbol', params, function(response)
response = postprocess_symbols(response)
on_symbols(response, opts)
end)