Skip to content

Commit

Permalink
Merge pull request #104 from epheien/feat-man
Browse files Browse the repository at this point in the history
feat: add man support
  • Loading branch information
hedyhli authored Dec 27, 2024
2 parents 94e2385 + 38f9a8c commit 4f601da
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ https://github.com/hedyhli/outline.nvim/assets/50042066/f66fa661-b66a-4b48-84e8-
**Features**

- Auto-updates items and highlight for current symbol as the cursor moves
- Supports **JSX** (treesitter), **Markdown**, **Norg** (treesitter), in
- Supports **JSX** (treesitter), **Markdown**, **Norg** (treesitter), **Man**, in
addition to LSP, with other treesitter support coming soon
- Outline window opened for each tabpage
- Symbol hierarchy UI with collapsible nodes and automatic collapsing based on
Expand Down
2 changes: 1 addition & 1 deletion lua/outline/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ M.defaults = {
up_and_jump = '<C-k>',
},
providers = {
priority = { 'lsp', 'coc', 'markdown', 'norg' },
priority = { 'lsp', 'coc', 'markdown', 'norg', 'man' },
lsp = {
blacklist_clients = {},
},
Expand Down
97 changes: 97 additions & 0 deletions lua/outline/providers/man.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
-- code snippet from 'stevearc/aerial.nvim'
local str_to_kind = require('outline.symbols').str_to_kind
local config = {}

local M = {
name = 'man',
}

M.fetch_symbols_sync = function(bufnr)
bufnr = bufnr or 0
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
local items = {}
local last_header
local prev_lnum = 0
local prev_line = ""
local function finalize_header()
if last_header then
last_header.range['end'].line = prev_lnum - 1
last_header.range['end'].character = prev_line:len()
end
end
for lnum, line in ipairs(lines) do
local header = line:match("^[A-Z].+")
local padding, arg = line:match("^(%s+)(-.+)")
if header and lnum > 1 then
finalize_header()
local item = {
kind = str_to_kind["Interface"],
name = header,
level = 0,
range = {
start = { line = lnum - 1, character = 0 },
['end'] = { line = lnum - 1, character = 10000 },
},
}
item.selectionRange = item.range
if
not config.post_parse_symbol
or config.post_parse_symbol(bufnr, item, {
backend_name = "man",
lang = "man",
})
~= false
then
last_header = item
table.insert(items, item)
end
elseif arg then
local item = {
kind = str_to_kind["Interface"],
name = arg,
level = last_header and 1 or 0,
parent = last_header,
range = {
start = { line = lnum - 1, character = padding:len() },
['end'] = { line = lnum - 1, character = line:len() },
},
}
item.selectionRange = item.range
if
not config.post_parse_symbol
or config.post_parse_symbol(bufnr, item, {
backend_name = "man",
lang = "man",
})
~= false
then
if last_header then
last_header.children = last_header.children or {}
table.insert(last_header.children, item)
else
table.insert(items, item)
end
end
end
prev_lnum = lnum
prev_line = line
end
finalize_header()
return items
end

---@return boolean, table?
function M.supports_buffer(bufnr)
local ft = vim.bo[bufnr].filetype
return ft == 'man', { ft = ft, buf = bufnr }
end

---@param on_symbols fun(symbols?:outline.ProviderSymbol[], opts?:table)
---@param opts table
---@param info table?
function M.request_symbols(on_symbols, opts, info)
local symbols = M.fetch_symbols_sync(info.buf) ---@diagnostic disable-line
on_symbols(symbols, opts)
end

return M

0 comments on commit 4f601da

Please sign in to comment.