Initial markdown support
Markdown doesnt have a language server, so do this manually Closes #43
This commit is contained in:
@@ -5,6 +5,7 @@ local ui = require('symbols-outline.ui')
|
||||
local writer = require('symbols-outline.writer')
|
||||
local config = require('symbols-outline.config')
|
||||
local utils = require('symbols-outline.utils.lsp_utils')
|
||||
local markdown = require('symbols-outline.markdown')
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -58,12 +59,14 @@ end
|
||||
|
||||
function M._refresh()
|
||||
if M.state.outline_buf ~= nil then
|
||||
vim.lsp.buf_request_all(0, "textDocument/documentSymbol", getParams(),
|
||||
function(response)
|
||||
local function refresh_handler(response)
|
||||
if response == nil or type(response) ~= 'table' then
|
||||
return
|
||||
end
|
||||
if not utils.is_buf_attached_to_lsp(vim.api.nvim_get_current_buf()) then
|
||||
|
||||
local current_buf = vim.api.nvim_get_current_buf()
|
||||
if (not utils.is_buf_markdown(current_buf)) and
|
||||
(not utils.is_buf_attached_to_lsp(current_buf)) then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -75,7 +78,13 @@ function M._refresh()
|
||||
|
||||
writer.parse_and_write(M.state.outline_buf,
|
||||
M.state.flattened_outline_items)
|
||||
end)
|
||||
end
|
||||
|
||||
if vim.api.nvim_buf_get_option(0, 'ft') == 'markdown' then
|
||||
refresh_handler(markdown.handle_markdown())
|
||||
end
|
||||
vim.lsp.buf_request_all(0, "textDocument/documentSymbol", getParams(),
|
||||
refresh_handler)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -96,7 +105,10 @@ function M._highlight_current_item(winnr)
|
||||
|
||||
local doesnt_have_outline_buf = not M.state.outline_buf
|
||||
|
||||
local should_exit = doesnt_have_lsp or doesnt_have_outline_buf or
|
||||
local is_not_markdown = not utils.is_buf_markdown(0)
|
||||
|
||||
local should_exit = (doesnt_have_lsp and is_not_markdown) or
|
||||
doesnt_have_outline_buf or
|
||||
is_current_buffer_the_outline
|
||||
|
||||
-- Make a special case if we have a window number
|
||||
@@ -250,15 +262,17 @@ end
|
||||
|
||||
function M.toggle_outline()
|
||||
if M.state.outline_buf == nil then
|
||||
vim.lsp.buf_request_all(0, "textDocument/documentSymbol", getParams(),
|
||||
handler)
|
||||
M.open_outline()
|
||||
else
|
||||
vim.api.nvim_win_close(M.state.outline_win, true)
|
||||
M.close_outline()
|
||||
end
|
||||
end
|
||||
|
||||
function M.open_outline()
|
||||
if M.state.outline_buf == nil then
|
||||
if vim.api.nvim_buf_get_option(0, 'ft') == 'markdown' then
|
||||
handler(markdown.handle_markdown())
|
||||
end
|
||||
vim.lsp.buf_request_all(0, "textDocument/documentSymbol", getParams(),
|
||||
handler)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user